0

I am using Github Actions to push an image into GCP Artifact Registry and later deploy to Cloud Run

All the process goes fine, except the automatic deploying to Cloud Run.

Below is the link for the example that guided me

https://github.com/codeedu/live-imersao-fullcycle10-nestjs-tests/blob/main/.github/workflows/ci_cd.yml

The error is as below:

Deploying...
failed
Deployment failed
ERROR: (gcloud.run.deploy) spec.template.spec.containers[0].image: Must provide an image URL to deploy

I appreciate any help to accomplish this task

Below is the workflow file:

name: CI and CD

on:
  workflow_dispatch:
  push:
    branches: [main, develop]

env:
  REGISTRY: gcr.io
  IMAGE_NAME: ${{ secrets.GCP_PROJECT_NAME }}/${{ secrets.CLOUD_RUN_SERVICE }}
  REGION: us-central1
  # REGISTRY_GIT: ghcr.io
  # IMAGE_NAME_GIT: ${{ github.repository }}

jobs:
  test-code:
    runs-on: ubuntu-20.04

    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js 16.x
      uses: actions/setup-node@v3
      with:
        node-version: 16.x
    - run: npm ci
    - run: npm run test
  
  build-image:
    needs: test-code
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-20.04
    outputs:
      tags: ${{ steps.meta.outputs.tags }}
    concurrency: build-image-process
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      # Workaround: https://github.com/docker/build-push-action/issues/461
      - name: Setup Docker buildx
        uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
      
      # Login against a Docker registry except on PR
      # https://github.com/docker/login-action
      - name: Log into registry ${{ env.REGISTRY }}
        if: github.event_name != 'pull_request'
        uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
        with:
          registry: ${{ env.REGISTRY }}
          username: _json_key
          #username: ${{ github.actor }}
          password: ${{ secrets.GCP_SERVICE_ACCOUNT }}
          #password: ${{ secrets.GITHUB_TOKEN }}

      # Extract metadata (tags, labels) for Docker
      # https://github.com/docker/metadata-action
      - name: Extract Docker metadata
        id: meta
        uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
      
      # Build and push Docker image with Buildx (don't push on PR)
      # https://github.com/docker/build-push-action
      - name: Build and push Docker image
        id: build-and-push
        uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
        if: ${{ github.event_name != 'pull_request' }}
        with:
          context: .
          file: ./Dockerfile.prod
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
        
      - name: Outputs tags
        run: echo "${{ steps.meta.outputs.tags }}"

  deploy-image:
    needs: build-image
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-20.04

    steps:

      - name: Checkout repository
        uses: actions/checkout@v3
    
      - id: 'auth'
        uses: 'google-github-actions/auth@v0'
        with:
          credentials_json: '${{ secrets.GCP_SERVICE_ACCOUNT }}'
    
      - name: 'Deploy to Cloud Run'
        uses: 'google-github-actions/deploy-cloudrun@v0'
        with:
          service: ${{ secrets.CLOUD_RUN_SERVICE }}
          image: ${{ needs.build-image.outputs.tags }}
          region: ${{ env.REGION }}
Aliton Oliveira
  • 1,224
  • 1
  • 15
  • 26
  • Are you still facing issue? If so can you share the document or tutorial you followed to deploy automatically? – Roopa M Dec 07 '22 at 14:17
  • My solution was to hard code the image name. After some executions, the command `steps.meta.outputs.tags` started showing the correct image name. – Aliton Oliveira Dec 07 '22 at 14:28
  • Can you share your solution as answer so that it will help others also? – Roopa M Dec 07 '22 at 14:30
  • I am still waiting for a proper answer. I just did a workaround to make it work. Image name hard coded `image: "gcr.io/projectName/cloudRunName:main"` – Aliton Oliveira Dec 07 '22 at 14:35
  • The command `needs.build-image.outputs.tags` is still empty and that's why I hard coded the image name. – Aliton Oliveira Dec 07 '22 at 14:48

0 Answers0