GitHub
github.com › marketplace › actions › push-to-gcr-github-action
Push to GCR GitHub Action - GitHub Marketplace
name: Push to GCR GitHub Action on: [push] jobs: build-and-push-to-gcr: runs-on: ubuntu-latest permissions: contents: 'read' id-token: 'write' steps: - uses: actions/checkout@v5 - name: Authenticate to Google Cloud id: auth uses: google-github-actions/auth@v2 with: workload_identity_provider: projects/123123123/locations/global/workloadIdentityPools/the-workload-pool/providers/the-provider service_account: artifact-registry-writer@<PROJECT_ID>.iam.gserviceaccount.com - uses: RafikFarhad/push-to-gcr-github-action@v5 with: # gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }} # can be base64 encoded or plain text || not needed if you use google-github-actions/auth registry: gcr.io project_id: my-awesome-project image_name: backend image_tag: latest,v1 dockerfile: ./docker/Dockerfile.prod context: ./docker
Videos
Acaird
acaird.github.io › computers › 2020 › 02 › 11 › github-google-container-cloud-run
Using Github Actions to Build and Push Images to Google Container Registry
February 11, 2020 - My code is in Github and I wanted to be able to build images and push them to GCR automatically so that I could later deploy them to Google Cloud Run. There is some starting configuration at https://github.com/actions/starter-workflows/blob/master/ci/google.yml that is pretty good, but it includes ...
GitHub
github.com › RafikFarhad › push-to-gcr-github-action › releases
Releases · RafikFarhad/push-to-gcr-github-action
An action that build docker image and push to Google Cloud Registry and Google Artifact Registry. - RafikFarhad/push-to-gcr-github-action
Author RafikFarhad
GitHub
github.com › RafikFarhad › push-to-gcr-github-action
GitHub - RafikFarhad/push-to-gcr-github-action: An action that build docker image and push to Google Cloud Registry and Google Artifact Registry.
name: Push to GCR GitHub Action on: [push] jobs: build-and-push-to-gcr: runs-on: ubuntu-latest permissions: contents: 'read' id-token: 'write' steps: - uses: actions/checkout@v5 - name: Authenticate to Google Cloud id: auth uses: google-github-actions/auth@v2 with: workload_identity_provider: projects/123123123/locations/global/workloadIdentityPools/the-workload-pool/providers/the-provider service_account: artifact-registry-writer@<PROJECT_ID>.iam.gserviceaccount.com - uses: RafikFarhad/push-to-gcr-github-action@v5 with: # gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }} # can be base64 encoded or plain text || not needed if you use google-github-actions/auth registry: gcr.io project_id: my-awesome-project image_name: backend image_tag: latest,v1 dockerfile: ./docker/Dockerfile.prod context: ./docker
Starred by 74 users
Forked by 42 users
Languages Shell 81.1% | Dockerfile 16.5% | C 2.4% | Shell 81.1% | Dockerfile 16.5% | C 2.4%
GitHub
github.com › RafikFarhad › push-to-gcr-github-action › blob › master › action.yaml
push-to-gcr-github-action/action.yaml at master · RafikFarhad/push-to-gcr-github-action
An action that build docker image and push to Google Cloud Registry and Google Artifact Registry. - push-to-gcr-github-action/action.yaml at master · RafikFarhad/push-to-gcr-github-action
Author RafikFarhad
Reddit
reddit.com › r/golang › using github actions to build an image and push to multiple repositories?
r/golang on Reddit: Using GitHub Actions to build an image and push to multiple repositories?
May 22, 2024 -
I'm attempting to push an image that's built and stored in GitHub Registory to Google Artifact Registry.
The GitHub Actions file contains:
docker build . --tag ghcr.io/myaccount/golang-docker:latest docker push ghcr.io/myaccount/golang-docker:latest
This obviously builds and pushes it to ghcr.
I want to add an additional step to also push to AR so I've properly setup all the auth stuff in AR and the variables in the actions files:
env: IMAGE_NAME: 'golang-docker' PROJECT_ID: 'project-blablabla' AR_REPO_LOCATION: 'us-west1' AR_URL: 'us-west1-docker.pkg.dev/project-blablabla/my-ar-repo' SERVICE_ACCOUNT: 'github-actions-service-account@project-blablabla.iam.gserviceaccount.com' WORKLOAD_IDENTITY_PROVIDER: 'projects/123456789/locations/global/workloadIdentityPools/my-app-dev-pool/providers/github-actions-provider'
Then I add
- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v2'
with:
token_format: 'access_token'
project_id: ${{ env.PROJECT_ID }}
service_account: ${{ env.SERVICE_ACCOUNT }}
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
- name: Docker Auth
id: docker-auth
uses: 'docker/login-action@v1'
with:
username: 'oauth2accesstoken'
password: '${{ steps.auth.outputs.access_token }}'
registry: '${{ env.AR_REPO_LOCATION }}-docker.pkg.dev'
- name: Push to AR
run: |-
docker push "${{ env.AR_URL }}/${{ env.IMAGE_NAME }}:latest"But it errors out at the last step with:
An image does not exist locally with the tag: us-west1-docker.pkg.dev/project-blablabla/my-ar-repo/golang-docker The push refers to repository [us-west1-docker.pkg.dev/platform-blablabla/my-ar-repo/golang-docker]
I'm guessing it has to do with tagging of the image at the build step, but Im' not well versed in docker so I'm not sure what I'm missing. Basically, I'm trying to avoid building the image twice. I want to build it once and then push to one or more registries.
Any ideas?
Top answer 1 of 3
1
This works for us jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Authenticate to Google Cloud uses: google-github-actions/auth@v2 with: credentials_json: ${{ secrets.GCP_SA_KEY }} - name: Set up Cloud SDK uses: google-github-actions/setup-gcloud@v2 - name: Authorize Docker for GCR run: gcloud auth configure-docker - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build and push uses: docker/build-push-action@v5 with: push: true tags: | gcr.io/my_project/my_app:latest gcr.io/my_project/my_app:${{ env.GITHUB_TAG }} file: path/to/dockerfile/Dockerfile We use it for google container registry, not artifcact registry, but I think, it should work for your case
2 of 3
1
I'm using docker/metadata-action@v5 to generate tags as well as multiple registry targets: https://github.com/toolhippie/jq/blob/master/.github/workflows/docker.yml
GitHub
github.com › wipash › action-gcr-push
GitHub - wipash/action-gcr-push: Build, tag, and push container to Google Cloud Registry
name: Build and push to GCR on: push: branches: - master jobs: build_push_gcr: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v1 - name: Build and push to GCR uses: wipash/action-gcr-push@master env: GCLOUD_AUTH_KEY: ${{secrets.GCLOUD_AUTH_KEY}} with: image: cmsback version_tag: 1.0.2 environment: production project: central-management-system
Author wipash
YouTube
youtube.com › watch
Build a Docker Image and Publish It to GCP GCR & Artifact Registry using Github Actions - YouTube
👨💼📈 Mentorship/On-the-Job Support/Consulting - https://calendly.com/antonputra/youtube or me@antonputra.com▬▬▬▬▬ Experience & Location 💼 ▬▬▬▬▬► I’m a S...
Published October 21, 2021
Ianwhitestone
ianwhitestone.work › docker-builds-gcr-github-actions
Continuous docker builds with Github Actions – Ian Whitestone
December 11, 2020 - Here’s an example workflow that builds & pushes a Docker image to GCR on every commit to master: # .github/workflows/docker-gcp.yml name: Docker-GCP on: push: branches: - master jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup gcloud uses: GoogleCloudPlatform/github-actions/setup-gcloud@master with: version: '290.0.1' service_account_key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }} project_id: ${{ secrets.GCP_PROJECT_ID }} - name: Configure docker for GCP run: gcloud auth configure-docker - name: Build docker image run: docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/<YOUR_IMAGE_NAME>:latest .
GitHub
github.com › hpdobrica › push-to-gcr-github-action
GitHub - hpdobrica/push-to-gcr-github-action: An action that build docker image and push to Google Cloud Registry.
name: Push to GCR Github Action on: [push] jobs: build-and-push-to-gcr: runs-on: ubuntu-latest steps: - uses: RafikFarhad/push-to-gcr-github-action@v1 with: gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }} registry: gcr.io project_name: my-awesome-project image_name: server-end
Author hpdobrica
Stack Overflow
stackoverflow.com › questions › 75219715 › docker-push-in-github-actions-to-gcr-creates-multiple-images
containers - Docker push in (GitHub actions) to GCR creates multiple images - Stack Overflow
- name: build and push to local registry uses: docker/[email protected] with: context: ${{ inputs.context }} file: ${{ inputs.context }}/${{ inputs.dockerfile }} no-cache: ${{ inputs.no_cache }} build-args: ${{ inputs.build_args }} push: true tags: ${{ env.LOCAL_IMAGE }} outputs: type=image,oci-mediatypes=false · I then use buildx to copy the image to a GCR registry
GitHub
github.com › marketplace › actions › push-docker-image-to-gcr
Push Docker Image to GCR · Actions · GitHub Marketplace · GitHub
Path to the context directory (containing the Dockerfile). ... Name of dockerfile. ... Google Cloud Project ID. Google Cloud Service Key (JSON). uses: Industrial/push-docker-gcr with: docker_image_name: api docker_image_tag: latest docker_context: ./services/api gcr_host: gcr.io gcr_project_id: ${{ secrets.GCLOUD_PROJECT_ID }} gcr_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }}
GitHub
github.com › worklifebeyond › push-to-gcr
GitHub - worklifebeyond/push-to-gcr: Github workflow action to push a docker image to Google Cloud Registry
Add service-account.json to Github secret as GCLOUD_CREDENTIALS ... on: push jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - name: Build the Docker image run: | echo $GCLOUD_CREDENTIALS > keyfile.json cat keyfile.json | docker login -u _json_key --password-stdin https://gcr.io docker build .
Author worklifebeyond