From 1eb7c71ff93a857d30c7cb675096ec22b14173da Mon Sep 17 00:00:00 2001 From: oiov Date: Sun, 25 May 2025 17:01:06 +0800 Subject: [PATCH] test --- .dockerignore | 7 ++ .github/workflows/docker-build-push.yml | 95 ++++++++++++------------- Dockerfile | 20 ++---- docker-compose.yml | 15 ++-- 4 files changed, 62 insertions(+), 75 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b7a3dec --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +# .dockerignore +# node_modules +# npm-debug.log +# README.md +# .env* +# .next +# .git \ No newline at end of file diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml index 2aaf63f..0c176e7 100644 --- a/.github/workflows/docker-build-push.yml +++ b/.github/workflows/docker-build-push.yml @@ -1,69 +1,64 @@ -name: Build and Push Docker Image +name: Build and Push Docker Image to GHCR on: push: branches: - - '**' - workflow_dispatch: - inputs: - version: - description: '镜像版本号' - required: false - default: 'latest' - environment: - description: '部署环境' - required: false - default: 'production' - type: choice - options: - - production - - staging - - development + - main + tags: + - 'v*.*.*' + pull_request: + branches: + - main + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }}/wrdo jobs: - build: + build-and-push: runs-on: ubuntu-latest - + permissions: + contents: read + packages: write + steps: - - name: Checkout code - uses: actions/checkout@v3 - - # 设置 QEMU 以支持多平台构建 - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - # 设置 Docker Buildx + # 检出代码 + - name: Checkout repository + uses: actions/checkout@v4 + + # 设置 Docker Buildx(支持多平台构建) - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 + + # 登录到 GitHub Container Registry + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 with: - driver-opts: | - image=moby/buildkit:master - network=host - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Extract metadata + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # 提取 Docker 镜像元数据(标签、版本等) + - name: Extract Docker metadata id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: - images: oiovwr/wrdo + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=raw,value=${{ github.event.inputs.version || 'latest' }} - type=raw,value=latest - - - name: Build and push - uses: docker/build-push-action@v4 + type=sha,format=short + type=ref,event=branch,prefix= + type=ref,event=tag + + # 构建并推送 Docker 镜像 + - name: Build and push Docker image + uses: docker/build-push-action@v6 with: context: . - push: true - platforms: linux/amd64,linux/arm64 + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} # 仅在 push 时推送 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha,scope=${{ github.workflow }}-${{ github.ref }} - cache-to: type=gha,mode=max,scope=${{ github.workflow }}-${{ github.ref }} build-args: | ENVIRONMENT=${{ github.event.inputs.environment || 'production' }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 96da4eb..b74085c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:22-alpine AS base +FROM node:20-alpine AS base FROM base AS deps RUN apk add --no-cache libc6-compat @@ -19,21 +19,9 @@ WORKDIR /app RUN npm install -g pnpm -# ARG NEXT_PUBLIC_APP_URL="http://localhost:3000" -# ARG RESEND_API_KEY="re_" -# ARG DATABASE_URL="" -# ARG NEXT_PUBLIC_OPEN_SIGNUP="1" -# ARG GITHUB_TOKEN="" -# ARG AUTH_SECRET="" -# ARG GOOGLE_CLIENT_ID="" -# ARG GOOGLE_CLIENT_SECRET="" -# ARG GITHUB_ID="" -# ARG GITHUB_SECRET="" -# ARG LinuxDo_CLIENT_ID="" -# ARG LinuxDo_CLIENT_SECRET="" -# ARG NEXT_PUBLIC_EMAIL_R2_DOMAIN="" -# ARG NEXT_PUBLIC_GOOGLE_ID="" -# ARG SCREENSHOTONE_BASE_URL="" +ARG NEXT_PUBLIC_APP_URL="http://localhost:3000" +ARG RESEND_API_KEY="" +ARG DATABASE_URL="" COPY --from=deps /app/node_modules ./node_modules COPY . . diff --git a/docker-compose.yml b/docker-compose.yml index 3b34ceb..3d69561 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,11 @@ -version: "3.8" - services: app: - build: - context: . - dockerfile: Dockerfile - args: - RESEND_API_KEY: ${RESEND_API_KEY} - # image: ghcr.io/oiov/wr.do/wrdo:${TAG:-latest} + # build: + # context: . + # dockerfile: Dockerfile + # args: + # RESEND_API_KEY: ${RESEND_API_KEY} + image: ghcr.io/oiov/wr.do/wrdo:${TAG:-latest} container_name: wrdo ports: - "3000:3000" @@ -36,7 +34,6 @@ services: networks: - wrdo-network restart: unless-stopped - # command: ["bash", "-c", "pnpm db:push && node server.js"] # If you want to use local database, uncomment the following line # postgres: