From 64dddf6ef9f098734ad0299a4da0235acb9ce6d4 Mon Sep 17 00:00:00 2001 From: Vivien Date: Thu, 19 Oct 2023 11:18:06 +0200 Subject: [PATCH] ci: backend docker image is tagged with git tag for production --- .github/workflows/build_and_deploy.yaml | 44 +++++++++++++++---------- .github/workflows/check.yaml | 2 +- .github/workflows/main_push.yaml | 1 + .github/workflows/tags_push.yaml | 1 + 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build_and_deploy.yaml b/.github/workflows/build_and_deploy.yaml index 097e193f7..c09e6f11e 100644 --- a/.github/workflows/build_and_deploy.yaml +++ b/.github/workflows/build_and_deploy.yaml @@ -7,6 +7,10 @@ on: type: string description: 'Github environment to use' required: true + version: + type: string + description: 'version to deploy' + required: true secrets: GCP_SA_KEY: required: true @@ -20,11 +24,30 @@ jobs: actions: read environment: ${{ inputs.environment }} env: - TAG: europe-west1-docker.pkg.dev/marble-infra/marble/marble-frontend:latest + IMAGE: europe-west1-docker.pkg.dev/marble-infra/marble/marble-frontend:${{ inputs.version }} SERVICE_ACCOUNT: marble-frontend-cloud-run@${{ vars.GCP_PROJECT_ID }}.iam.gserviceaccount.com steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + # source: https://github.com/docker/login-action#google-artifact-registry-gar + - name: Login to Google Artifact Registry + uses: docker/login-action@v3 + with: + registry: europe-west1-docker.pkg.dev + username: _json_key + password: ${{ secrets.GCP_SA_KEY }} + + # source: https://github.com/docker/build-push-action + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + target: app-builder + tags: ${{ env.IMAGE }} - name: Auth uses: 'google-github-actions/auth@v1' @@ -36,24 +59,9 @@ jobs: with: install_components: beta - - name: Configure Docker - run: | - gcloud auth configure-docker europe-west1-docker.pkg.dev - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build and push - uses: docker/build-push-action@v4 - with: - context: . - push: true - target: app-builder - tags: ${{ env.TAG }} - - name: Deploy server run: | gcloud run deploy marble-frontend \ --quiet \ --region="europe-west1" \ - --image="${{ env.TAG }}" + --image="${{ env.IMAGE }}" diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 171c692f6..49cbda07a 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -10,7 +10,7 @@ jobs: contents: read actions: read steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: pnpm/action-setup@v2 with: version: 8 diff --git a/.github/workflows/main_push.yaml b/.github/workflows/main_push.yaml index de9c74210..087c43b29 100644 --- a/.github/workflows/main_push.yaml +++ b/.github/workflows/main_push.yaml @@ -24,5 +24,6 @@ jobs: uses: ./.github/workflows/build_and_deploy.yaml with: environment: 'staging' + version: latest secrets: GCP_SA_KEY: ${{ secrets.GCP_SA_KEY_STAGING }} diff --git a/.github/workflows/tags_push.yaml b/.github/workflows/tags_push.yaml index 247964b91..2182e3598 100644 --- a/.github/workflows/tags_push.yaml +++ b/.github/workflows/tags_push.yaml @@ -24,5 +24,6 @@ jobs: uses: ./.github/workflows/build_and_deploy.yaml with: environment: 'production' + version: ${{ github.ref_name }} secrets: GCP_SA_KEY: ${{ secrets.GCP_SA_KEY_PRODUCTION }}