From 36c8f9e40cc2b3918b0c6c3e839d2949f5cdac2c Mon Sep 17 00:00:00 2001 From: "benjamin.747" Date: Wed, 11 Feb 2026 14:57:26 +0800 Subject: [PATCH] feat: add gcp image push process --- .github/workflows/deploy-api.yml | 34 +++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-api.yml b/.github/workflows/deploy-api.yml index 317c4a2..0b2efa3 100644 --- a/.github/workflows/deploy-api.yml +++ b/.github/workflows/deploy-api.yml @@ -7,6 +7,8 @@ env: REGISTRY_ALIAS: m8q5m4u3 REPOSITORY: mega IMAGE_TAG_BASE: campsite-0.1.0-pre-release + GCP_PROJECT_ID: infra-20250121-20260121-0235 + GCP_REPOSITORY: mega RUBY_VERSION: 3.3.4 NODE_VERSION: 18.16.1 BUNDLER_VERSION: 2.3.14 @@ -20,7 +22,6 @@ concurrency: cancel-in-progress: true jobs: - # Build amd64 image in CI and push to ECR Public build-push-amd64: runs-on: ubuntu-latest timeout-minutes: 30 @@ -30,6 +31,9 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + # ========================= + # AWS (ECR Public) + # ========================= - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -43,21 +47,41 @@ jobs: with: registry-type: public - - name: Build & push amd64 image + # ========================= + # GCP (Artifact Registry) + # ========================= + - name: Auth to GCP + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_SA_KEY }} + + - name: Configure docker for GCP + run: | + gcloud auth configure-docker us-central1-docker.pkg.dev + + # ========================= + # Build & Push + # ========================= + - name: Build & push amd64 image (AWS + GCP) env: - REGISTRY: ${{ steps.login-ecr-public.outputs.registry }} + AWS_REGISTRY: ${{ steps.login-ecr-public.outputs.registry }} + GCP_IMAGE_BASE: us-central1-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GCP_REPOSITORY }}/${{ env.REPOSITORY }} run: | set -euo pipefail - IMAGE_BASE="$REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}" + + AWS_IMAGE_BASE="$AWS_REGISTRY/${{ env.REGISTRY_ALIAS }}/${{ env.REPOSITORY }}" + IMAGE_TAG="${{ env.IMAGE_TAG_BASE }}-amd64" + docker buildx build \ --platform linux/amd64 \ --provenance=false \ --sbom=false \ - -t "$IMAGE_BASE:${{ env.IMAGE_TAG_BASE }}-amd64" \ --build-arg RUBY_VERSION=${{ env.RUBY_VERSION }} \ --build-arg NODE_VERSION=${{ env.NODE_VERSION }} \ --build-arg BUNDLER_VERSION=${{ env.BUNDLER_VERSION }} \ -f ./api/Dockerfile \ + -t "$AWS_IMAGE_BASE:$IMAGE_TAG" \ + -t "$GCP_IMAGE_BASE:$IMAGE_TAG" \ --push ./api # Merge locally-built arm64 image (pushed separately) with CI-built amd64