diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..6293eb0 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,39 @@ +name: Build and Push MediaHelp Docker Image + +on: + push: + tags: + - "v*" + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - name: Checkout source + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: frontend/scripts/deploy/Dockerfile + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/mediahelp:latest + ghcr.io/${{ github.repository_owner }}/mediahelp:${{ github.ref_name }} diff --git a/frontend/scripts/deploy/Dockerfile b/frontend/scripts/deploy/Dockerfile index 86f439f..c932418 100644 --- a/frontend/scripts/deploy/Dockerfile +++ b/frontend/scripts/deploy/Dockerfile @@ -1,37 +1,35 @@ -FROM node:22-slim AS builder +FROM node:20-slim AS builder -# --max-old-space-size ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" ENV NODE_OPTIONS=--max-old-space-size=8192 ENV TZ=Asia/Shanghai -RUN npm i -g corepack - WORKDIR /app -# copy package.json and pnpm-lock.yaml to workspace +# 启用 pnpm +RUN corepack enable \ + && corepack prepare pnpm@latest --activate \ + && pnpm config set registry https://registry.npmmirror.com + +# 拷贝源码 COPY . /app # 安装依赖 -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install + +# 构建 RUN pnpm run build --filter=\!./docs RUN echo "Builder Success 🎉" FROM nginx:stable-alpine AS production -# 配置 nginx RUN echo "types { application/javascript js mjs; }" > /etc/nginx/conf.d/mjs.conf \ && rm -rf /etc/nginx/conf.d/default.conf -# 复制构建产物 COPY --from=builder /app/playground/dist /usr/share/nginx/html - -# 复制 nginx 配置 COPY --from=builder /app/scripts/deploy/nginx.conf /etc/nginx/nginx.conf EXPOSE 8080 - -# 启动 nginx CMD ["nginx", "-g", "daemon off;"]