Created
September 5, 2021 15:10
-
-
Save rxhl/3068c4856466b8520f794a78629060e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
# 0. Docker Build | |
- name: gcr.io/cloud-builders/docker | |
args: | |
- build | |
- '--no-cache' | |
- '-t' | |
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA' | |
- . | |
- '-f' | |
- Dockerfile | |
id: Build | |
# 1. Docker push to Google Artifact Registry | |
- name: gcr.io/cloud-builders/docker | |
args: | |
- push | |
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA' | |
id: Push | |
# 2. Make migrations | |
- name: gcr.io/google-appengine/exec-wrapper | |
args: | |
- '-i' | |
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA' | |
- '-s' | |
- '${PROJECT_ID}:${_DEPLOY_REGION}:${_DB_INSTANCE}' | |
- '-e' | |
- 'SETTINGS_NAME=${_SECRET_SETTINGS_NAME}' | |
- '--' | |
- 'python' | |
- 'manage.py' | |
- 'makemigrations' | |
id: Make migrations | |
# 3. Migrate | |
- name: gcr.io/google-appengine/exec-wrapper | |
args: | |
- '-i' | |
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA' | |
- '-s' | |
- '${PROJECT_ID}:${_DEPLOY_REGION}:${_DB_INSTANCE}' | |
- '-e' | |
- 'SETTINGS_NAME=${_SECRET_SETTINGS_NAME}' | |
- '--' | |
- 'python' | |
- 'manage.py' | |
- 'migrate' | |
id: Migrate | |
# 4. Collect static | |
- name: gcr.io/google-appengine/exec-wrapper | |
args: | |
- '-i' | |
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA' | |
- '-s' | |
- '${PROJECT_ID}:${_DEPLOY_REGION}:${_DB_INSTANCE}' | |
- '-e' | |
- 'SETTINGS_NAME=${_SECRET_SETTINGS_NAME}' | |
- '--' | |
- 'python' | |
- 'manage.py' | |
- 'collectstatic' | |
- '--no-input' | |
id: Collect static | |
# 5. Deploy to Cloud Run | |
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim' | |
args: | |
- run | |
- services | |
- update | |
- $_SERVICE_NAME | |
- '--platform=managed' | |
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA' | |
- >- | |
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID,$_LABELS | |
- '--region=$_DEPLOY_REGION' | |
- '--quiet' | |
id: Deploy | |
entrypoint: gcloud | |
# Store images in Google Artifact Registry | |
images: | |
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA' | |
tags: | |
- gcp-cloud-build-deploy-cloud-run | |
- gcp-cloud-build-deploy-cloud-run-managed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment