I have a Github Action which builds a docker image then uploads it to the Container Registry.
Next I want to deploy this container to a Cloud Run service with some specific settings for the min and max instances, ensure CPU is always on, internal ingress only, etc. The documentation says these settings are set using metadata, but no example is shown. What format should this metadata take?
name: Push code to GCP
on:
push:
branches: [ main ]
jobs:
container-build-push-deploy:
name: Build Container Push to Registry Deploy to Cloud Run
runs-on: ubuntu-latest
env:
IMAGE_NAME: my-image
PROJECT_ID: my-project-123456
REGION: us-central1
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Authenticate With GCP
id: auth
uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
- name: Setup Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ env.PROJECT_ID }}
- name: Tag Release
id: increment-git-tag
run: |
bash ./scripts/git_update.sh -v patch
- name: Build Docker Image
run: docker build -t $IMAGE_NAME:latest .
- name: Configure Docker Client
run: |-
gcloud auth configure-docker --quiet
- name: Push Docker Image to Container Registry
env:
GIT_TAG: ${{ steps.increment-git-tag.outputs.git-tag }}
run: |-
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker tag $IMAGE_NAME:latest gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:latest
docker push gcr.io/$PROJECT_ID/$IMAGE_NAME:$GIT_TAG
- name: Deploy to Cloud Run
env:
GIT_TAG: ${{ steps.increment-git-tag.outputs.git-tag }}
uses: google-github-actions/deploy-cloudrun@v0
with:
service: my-service
image: 'gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ env.GIT_TAG }}'
region: ${{ env.REGION }}
secrets: |
/app/path/to/my-secret=my-secret:latest
metadata:
min-instances: 1
max-instances: 1
ingress: internal
tag: ${{ env.GIT_TAG }}
no-cpu-throttling: true
command: node
args: |
/app/path/to/main.js
arg-1
Obviously this last metadata
piece is wrong since with
is supposed to be key-value pairs of string. What is the correct format here?
2
Answers
I ended up going the pure CLI route in the interest of saving time
It would be nice to get another answer on how to use the pre-built setup-gcloud Github Action though from someone who knows.
According to the link that you share, the specs of your Cloud Run Service can be stored in a yaml file.
So I created a yaml (ex: service.yaml) file and pushed it to the
github repository
.Sample service.yaml file code with min and max instances, number of cpu and internal ingress
And here is the
Deploy to Cloud Run
steps yaml fileAdditional Info: You can use the sed command in linux to edit or replace string of a files even without opening them