From 2acc58168db785de95de54ed9f18735f44dde4ae Mon Sep 17 00:00:00 2001 From: Eric Maydeck <126706864+emaydeck-mozilla@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:54:59 -0600 Subject: [PATCH] fix: fixed workflow_dispatch runs for docker.yml GHA workflow (#752) This includes fixes for the GHA workflow that builds and pushes images to GAR. --- .github/workflows/build-and-push-image.yml | 18 +++++++++++------- .github/workflows/docker.yml | 18 +++++++++--------- Dockerfile | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-and-push-image.yml b/.github/workflows/build-and-push-image.yml index 96e61249..39fe3a91 100644 --- a/.github/workflows/build-and-push-image.yml +++ b/.github/workflows/build-and-push-image.yml @@ -1,4 +1,4 @@ -name: Build and push image to GAR +name: Reusable build-and-push workflow run-name: Build and push image "${{ inputs.image }}:${{ inputs.tag }}" to GAR @@ -11,16 +11,20 @@ on: crate: required: true type: string + # `gar_location`, `gar_repository`, and `gcp_project_id` have all been + # set as optional because default value has been supplied. As this + # workflow is only callable by other workflows, GitHub Actions will throw + # an error if we set "required: true" regardless of any defaults defined. gar_location: - required: true + required: false type: string default: us gar_repository: - required: true + required: false type: string default: autopush-prod gcp_project_id: - required: true + required: false type: string default: moz-fx-autopush-prod image: @@ -57,6 +61,7 @@ jobs: "${GITHUB_SERVER_URL}" \ "${GITHUB_REPOSITORY}" \ "${GITHUB_RUN_ID}" > version.json + - uses: docker/setup-buildx-action@v3 - id: gcp-auth uses: google-github-actions/auth@v2 with: @@ -73,9 +78,8 @@ jobs: with: context: . file: Dockerfile - tags: - - ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE }}:latest - - ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE }}:${{ env.TAG }} + # This is using both "latest" and app version tags. + tags: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE }}:latest,${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/${{ env.GAR_REPOSITORY }}/${{ env.IMAGE }}:${{ env.TAG }} push: true cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 383a1af3..460feb5c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -12,11 +12,11 @@ jobs: determine-tag: name: Determine tag to build if: | - github.event_name == "workflow_dispatch" || - (github.event_name == "check_run" && \ - github.event.check_run.name == "build-test-deploy" && \ - github.event.check_run.conclusion == "success" && \ - github.ref_type == "tag") + github.event_name == 'workflow_dispatch' || + (github.event_name == 'check_run' && + github.event.check_run.name == 'build-test-deploy' && + github.event.check_run.conclusion == 'success' && + github.ref_type == 'tag') runs-on: ubuntu-latest permissions: {} outputs: @@ -38,7 +38,7 @@ jobs: autoconnect: name: "Autoconnect: Build and push to GAR" - needs: [tag] + needs: [determine-tag] permissions: contents: read id-token: write @@ -48,11 +48,11 @@ jobs: binary: autoconnect crate: autoconnect image: autoconnect - tag: ${{ needs.tag.outputs.TAG }} + tag: ${{ needs.determine-tag.outputs.TAG }} autoendpoint: name: "Autoendpoint: Build and push to GAR" - needs: [tag] + needs: [determine-tag] permissions: contents: read id-token: write @@ -62,4 +62,4 @@ jobs: binary: autoendpoint crate: autoendpoint image: autoendpoint - tag: ${{ needs.tag.outputs.TAG }} + tag: ${{ needs.determine-tag.outputs.TAG }} diff --git a/Dockerfile b/Dockerfile index ab2d396c..55264aa5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # NOTE: Ensure builder's Rust version matches CI's in .circleci/config.yml # RUST_VER -FROM rust:1.80-bookworm as builder +FROM rust:1.80-bookworm AS builder ARG CRATE ADD . /app