From fff455312e4e9b6d0674ec89428bf77dc4b6d5d2 Mon Sep 17 00:00:00 2001 From: oiov Date: Sun, 25 May 2025 15:15:45 +0800 Subject: [PATCH] chore --- .github/workflows/docker-build-push.yml | 96 +++++++++++++------------ Dockerfile | 4 +- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/.github/workflows/docker-build-push.yml b/.github/workflows/docker-build-push.yml index 0c176e7..d739bc0 100644 --- a/.github/workflows/docker-build-push.yml +++ b/.github/workflows/docker-build-push.yml @@ -1,64 +1,66 @@ -name: Build and Push Docker Image to GHCR +name: Build and Push Docker Image on: - push: - branches: - - main - tags: - - 'v*.*.*' - pull_request: - branches: - - main - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }}/wrdo + workflow_dispatch: + inputs: + version: + description: '镜像版本号' + required: false + default: 'latest' + environment: + description: '部署环境' + required: false + default: 'production' + type: choice + options: + - production + - staging + - development jobs: - build-and-push: + build: runs-on: ubuntu-latest - permissions: - contents: read - packages: write - + steps: - # 检出代码 - - name: Checkout repository - uses: actions/checkout@v4 - - # 设置 Docker Buildx(支持多平台构建) + - name: Checkout code + uses: actions/checkout@v3 + + # 设置 QEMU 以支持多平台构建 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + # 设置 Docker Buildx - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - # 登录到 GitHub Container Registry - - name: Log in to GitHub Container Registry - uses: docker/login-action@v3 + uses: docker/setup-buildx-action@v2 with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - # 提取 Docker 镜像元数据(标签、版本等) - - name: Extract Docker metadata + 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 id: meta - uses: docker/metadata-action@v5 + uses: docker/metadata-action@v4 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: oiovwr/wrdo tags: | - 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 + type=raw,value=${{ github.event.inputs.version || 'latest' }} + type=raw,value=latest + + - name: Build and push + uses: docker/build-push-action@v4 with: context: . - file: ./Dockerfile - push: ${{ github.event_name != 'pull_request' }} # 仅在 push 时推送 + push: true + platforms: linux/amd64,linux/arm64 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 7fc9123..c310f0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,8 +20,8 @@ WORKDIR /app RUN npm install -g pnpm # ARG NEXT_PUBLIC_APP_URL="http://localhost:3000" -ARG RESEND_API_KEY="re_" -ARG DATABASE_URL="" +# ARG RESEND_API_KEY="re_" +# ARG DATABASE_URL="" # ARG NEXT_PUBLIC_OPEN_SIGNUP="1" # ARG GITHUB_TOKEN="" # ARG AUTH_SECRET=""