Using Google Container Registry, Docker Buildx, and GitHub Actions
Created on .
Read in 1 minute.
Today, I was trying to integrate the docker/build-push-action with Google Container Registry (GCR). I was able to get the build working, but I was unable to push the image to GCR due to authentication issues. The solution involved the following.
- Using the google-github-actions/auth action to authenticate with Google Cloud.
- Calling
gcloud auth configure-docker --quiet gcr.io
to configure the Docker CLI to use the Google Cloud credentials.
The workflow looks like this.
- name: Setup auth
id: "auth"
uses: "google-github-actions/[email protected]"
with:
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
service_account: "[email protected]${{ secrets.GOOGLE_CLOUD_PROJECT }}.iam.gserviceaccount.com"
- name: Setup docker
uses: docker/setup-buildx-[email protected]
- name: Authenticate docker
run: |
gcloud auth configure-docker --quiet gcr.io
- name: Build and push
uses: docker/build-push-[email protected]
with:
context: .
push: true
tags: ${{ env.IMAGE }}
cache-from: type=gha
cache-to: type=gha,mode=max
I was unable to get the cache working with GCR. Iβm not sure if itβs a bug or if Iβm doing something wrong.
IAM Role
I also created a custom role based upon Storage Legacy Bucket Writer
to add to the [email protected]
service account.
This includes the following permissions.
storage.buckets.get
storage.multipartUploads.abort
storage.multipartUploads.create
storage.multipartUploads.list
storage.multipartUploads.listParts
storage.objects.create
storage.objects.delete
storage.objects.list
And it works! π
Next
Strongly Typed Yup Schema in TypeScript
Previous
Environment Variables in GitHub Docker build-push-action
Related
- Environment Variables in GitHub Docker build-push-action
- Caching Playwright Binaries in GitHub Actions
- GitHub Workflow to Sync Branches
- Automatically Approving and Merging Dependabot Pull Requests
- Unwatch All Repositories in a GitHub Organization
- Microservice Usage Logging with Openresty and Google BigQuery
- WMS Layer on Google Maps
- Google Maps React Wrapper
- Automatically Archiving Dependabot and Semantic Release Emails