Build and Upload App Image #55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Upload App Image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Environment to deploy to' | |
| required: true | |
| default: 'stage' | |
| type: choice | |
| options: | |
| - stage | |
| - prod | |
| apps: | |
| description: 'List of apps to build and deploy (as JSON array)' | |
| required: true | |
| default: '["eva","eva-hp"]' | |
| type: string | |
| force_build: | |
| description: 'Force build image from scratch (ignores environment-based logic)' | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| build-and-push: | |
| name: Build & Push ${{ matrix.app }} | |
| if: ${{ github.event.inputs.environment == 'stage' || (github.event.inputs.environment == 'prod' && github.event.inputs.force_build == 'true') }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| app: ${{ fromJSON(github.event.inputs.apps) }} | |
| fail-fast: false | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY_JSON }} | |
| - name: Setup gcloud | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Setup Docker Auth | |
| run: | | |
| gcloud auth configure-docker us-central1-docker.pkg.dev --quiet | |
| - name: Get short Git SHA | |
| id: vars | |
| run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| - name: Build and Push Image | |
| run: | | |
| image_name=${{ matrix.app }} | |
| image_tag="${image_name%.Dockerfile}" | |
| tag="ghcr.io/${{ github.repository }}:${image_tag}" | |
| echo "Building $image_name.Dockerfile as $tag..." | |
| docker buildx build \ | |
| --file ${{ matrix.app }}.Dockerfile \ | |
| --tag us-central1-docker.pkg.dev/mrgn-shared/shared-artifact-registry/${{ matrix.app }}:${{ github.event.inputs.environment }} \ | |
| --tag us-central1-docker.pkg.dev/mrgn-shared/shared-artifact-registry/${{ matrix.app }}:${{ steps.vars.outputs.sha_short }} \ | |
| --platform linux/amd64 \ | |
| --cache-from type=registry,ref=us-central1-docker.pkg.dev/mrgn-shared/shared-artifact-registry/${{ matrix.app }}:build-cache \ | |
| --cache-to type=registry,ref=us-central1-docker.pkg.dev/mrgn-shared/shared-artifact-registry/${{ matrix.app }}:build-cache,mode=max \ | |
| --push \ | |
| . | |
| tag-to-prod: | |
| name: Tag Images to Prod | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| app: ${{ fromJSON(github.event.inputs.apps) }} | |
| fail-fast: false | |
| if: ${{ github.event.inputs.environment == 'prod' && github.event.inputs.force_build != 'true' }} | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: google-github-actions/auth@v2 | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY_JSON }} | |
| - name: Setup gcloud | |
| uses: google-github-actions/setup-gcloud@v2 | |
| - name: Setup Docker Auth | |
| run: | | |
| gcloud auth configure-docker us-central1-docker.pkg.dev --quiet | |
| - name: Tag Images to Prod | |
| run: | | |
| echo "Tagging ${{ matrix.app }} from stage to prod..." | |
| gcloud container images add-tag \ | |
| us-central1-docker.pkg.dev/mrgn-shared/shared-artifact-registry/${{ matrix.app }}:stage \ | |
| us-central1-docker.pkg.dev/mrgn-shared/shared-artifact-registry/${{ matrix.app }}:prod \ | |
| --quiet |