Im trying out Github actions to automate my docker build and push to GCP Artifact Registry. But my Github actions got an error "No such image" on docker tag command.
**Below is the yaml file for Github Actions : **
name: Build and Push Docker Image to Google Cloud Platform
on:
push:
branches: [ main ]
jobs:
build-push-gcr:
name: Build and Push to GCP
runs-on: ubuntu-latest
env:
IMAGE_NAME: <my-image-name>
PROJECT_ID: <my-project-id>
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: google-github-actions/setup-gcloud@v0
with:
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }}
project_id: ${{ env.PROJECT_ID }}
export_default_credentials: true
- name: Build Docker Image
run: docker buildx build --platform linux/amd64 -t carro-backend-api:latest .
- name: Configure Docker Client
run: |-
gcloud auth configure-docker --quiet
gcloud auth configure-docker us-central1-docker.pkg.dev --quiet
- name: Push Docker Image to Container Registry (GCR)
run: |-
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
- name: Push Docker Image to Artifact Registry
run: |-
docker tag $IMAGE_NAME:latest us-central1-docker.pkg.dev/$PROJECT_ID/$IMAGE_NAME/$IMAGE_NAME:latest
docker push us-central1-docker.pkg.dev/$PROJECT_ID/$IMAGE_NAME/$IMAGE_NAME:latest
This is the error showing in the Github action. [Error screenshot at Github Actions]: https://i.sstatic.net/kqx4n.png
I had found some thread saying its the "buildx" issue, and I tried the solution provided. But its still the same. Do I miss out something?
Where is the build located after the build run successfully on Github Actions?
My first time trying out Github Actions to automate things, so not so sure if I missed out something.
There's no need to retag the image, especially when you are inconsistent with the values. Instead output the build directly to your desired image name:
run: docker buildx build --platform linux/amd64 -t "gcr.io/$PROJECT_ID/$IMAGE_NAME:latest" -t "us-central1-docker.pkg.dev/$PROJECT_ID/$IMAGE_NAME/$IMAGE_NAME:latest" --push .
Perform your registry auth before this step and you can delete the tag and push steps.