-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
37 lines (37 loc) · 2.48 KB
/
cloudbuild.yaml
File metadata and controls
37 lines (37 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Reference: https://cloud.google.com/build/docs/deploying-builds/deploy-cloud-run
# File format: https://cloud.google.com/build/docs/build-config-file-schema
# Use this instead of directly selecting Dockerfile option in the build trigger, as we need to use this file to instruct on how to deploy as well.
steps:
# Build the container image
- id: tardsquad-discord-bot-build
name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'us.gcr.io/tardsquad-discord-bot/tardsquad-discord-bot', '.']
# Push the container image to Container Registry
- id: tardsquad-discord-bot-push
name: 'gcr.io/cloud-builders/docker'
args: ['push', 'us.gcr.io/tardsquad-discord-bot/tardsquad-discord-bot']
# Deploy container image to Cloud Run
#- id: tardsquad-discord-bot-deploy
#name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
#entrypoint: gcloud
#args: ['run', 'deploy', 'tardsquad-discord-bot', '--image', 'us.gcr.io/tardsquad-discord-bot/tardsquad-discord-bot', '--region', 'us-central1']
# Deploy container image to Compute Engine
# Requires that the Clould Build service account has Compute Engine permissions, which can be set in iAM but easiest at
# https://console.cloud.google.com/cloud-build/settings/service-account?project=tardsquad-discord-bot
# Ref: https://cloud.google.com/compute/docs/containers/deploying-containers#updating_a_container_on_a_vm_instance
- id: tardsquad-discord-bot-deploy
name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args: ['compute', 'instances', 'update-container', '--project=tardsquad-discord-bot', '--zone=us-central1-a', '--container-image', 'us.gcr.io/tardsquad-discord-bot/tardsquad-discord-bot:latest', 'tardbot-vm']
# Delete storage bucket
# Container Registry automatically creates a Cloud Storage Bucket that is multi-regional. However the free tier for Cloud Storage only has regional included.
# Possible workaround is to use a custom build trigger: https://stackoverflow.com/a/60983361/265508
# Another hack: delete undelaying Bucket after deployment: https://stackoverflow.com/a/70821159/265508
# Con: can't reboot the Compute Engine VM, as the image is now gone. Instead have to trigger a rebuild from Trigger UI.
# Note: the command succeeds and prints deleted files, but they are still visible in the bucket UI...
- id: tardsquad-discord-bot-bucket-delete
name: 'gcr.io/cloud-builders/gsutil'
entrypoint: gsutil
args: ['-m', 'rm', '-r', 'gs://us.artifacts.tardsquad-discord-bot.appspot.com']
images:
- us.gcr.io/tardsquad-discord-bot/tardsquad-discord-bot