| | name: Build Docker image and publish to GAR |
| |
|
| | permissions: {} |
| |
|
| | on: |
| | push: |
| | branches: |
| | - main |
| | tags: |
| | - "*" |
| |
|
| | jobs: |
| | build_and_push_to_gar: |
| | |
| | permissions: |
| | contents: "read" |
| | id-token: "write" |
| | packages: "none" |
| | name: Build and Push Docker image to GAR |
| | runs-on: ubuntu-latest |
| | environment: build |
| | env: |
| | GAR_IMAGE_BASE: ${{ vars.GAR_REPO }}/${{ github.event.repository.name }} |
| | GAR_REGISTRY: us-docker.pkg.dev |
| | steps: |
| | - name: Check out the repo |
| | uses: actions/checkout@v6 |
| | with: |
| | persist-credentials: false |
| |
|
| | - name: Authenticate to Google Cloud |
| | id: gcp-auth |
| | uses: google-github-actions/auth@v3 |
| | with: |
| | token_format: access_token |
| | workload_identity_provider: ${{ vars.GCPV2_GITHUB_WORKLOAD_IDENTITY_PROVIDER }} |
| | service_account: ${{ vars.GCP_GAR_SERVICE_ACCOUNT }} |
| |
|
| | - name: Login to Artifact Registry |
| | id: gar-login |
| | uses: docker/login-action@v3 |
| | with: |
| | registry: ${{ env.GAR_REGISTRY }} |
| | username: oauth2accesstoken |
| | password: ${{ steps.gcp-auth.outputs.access_token }} |
| |
|
| | - name: Extract metadata (tags, labels) for Docker |
| | id: meta |
| | uses: docker/metadata-action@v5 |
| | with: |
| | |
| | images: ${{ env.GAR_IMAGE_BASE }} |
| | tags: | |
| | # Generate tag based on short commit SHA |
| | type=sha,format=short,prefix= |
| | |
| | - name: Create version.json |
| | run: | |
| | # Use full sha here for version.json content |
| | echo "{\"commit\":\"$GITHUB_SHA\",\"version\":\"$GITHUB_REF_NAME\",\"source\":\"https://github.com/$GITHUB_REPOSITORY\",\"build\":\"$GITHUB_RUN_ID\"}" > version.json |
| | |
| | - name: Set up QEMU |
| | uses: docker/setup-qemu-action@v3 |
| |
|
| | - name: Set up Docker Buildx |
| | id: buildx |
| | uses: docker/setup-buildx-action@v3 |
| |
|
| | - name: Build and push Docker image to GAR |
| | id: build-and-push |
| | env: |
| | TAGS: ${{ steps.meta.outputs.tags }} |
| | uses: docker/build-push-action@v6 |
| | with: |
| | context: . |
| | |
| | push: true |
| | |
| | tags: ${{ env.TAGS }} |
| | |
| | build-args: | |
| | SENTRY_RELEASE=${{ github.sha }} |
| | NEXT_PUBLIC_SENTRY_DSN=${{ secrets.SENTRY_DSN }} |
| | |
| | secrets: | |
| | SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }} |
| | |
| | cache-from: type=gha |
| | cache-to: type=gha,mode=max |
| |
|
| | - name: Print Image URI |
| | env: |
| | TAGS: ${{ steps.meta.outputs.tags }} |
| | run: | |
| | echo "Pushed GAR image: $TAGS" |
| | |