Skip to content

Instantly share code, notes, and snippets.

@IvanWei
Created November 5, 2021 02:50
Show Gist options
  • Save IvanWei/c883b7dcb1a1b028e7c44e13ed9e97c4 to your computer and use it in GitHub Desktop.
Save IvanWei/c883b7dcb1a1b028e7c44e13ed9e97c4 to your computer and use it in GitHub Desktop.
CI/CD with Google Cloud to GCE by manual
steps:
- name: 'docker/compose:1.29.2'
args:
- build
id: build-images
- name: gcr.io/cloud-builders/docker
args:
- '-c'
- >-
docker push $$APP_CACHE_DOCKER_IMAGE:$$RELEASE_IMAGE_VERSION && docker
push $$DEPLOY_APP_DOCKER_IMAGE:$$RELEASE_IMAGE_VERSION | grep -i
"digest:" | awk -F "digest: " '{print $2}' | awk -F " " '{print $1}' >
/workspace/app-image-long-id && echo $(cat /workspace/app-image-long-id)
| grep -i "sha256:" | awk -F "sha256:" '{print $2}' | cut -c1-12 >
/workspace/app-image-short-id
id: upload-images
waitFor:
- build-images
entrypoint: bash
- name: gcr.io/cloud-builders/gcloud
args:
- '-c'
- >-
gcloud compute --project="$PROJECT_ID" instance-templates
create-with-container service-web-prod-$(date +%y%m%d-%H%M%S)-$(cat
/workspace/app-image-short-id) --machine-type=e2-small
--network=projects/nft-market-315408/global/networks/default
--network-tier=PREMIUM --metadata=google-logging-enabled=true
--maintenance-policy=MIGRATE
--service-account=347500239760-compute@developer.gserviceaccount.com
--scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append
--tags=http-server,https-server --image=cos-stable-93-16623-39-13
--image-project=cos-cloud --boot-disk-size=10GB
--boot-disk-type=pd-balanced
--boot-disk-device-name=service-web-prod-$(date +%y%m%d-%H%M%S)-$(cat
/workspace/app-image-short-id) --no-shielded-secure-boot --shielded-vtpm
--shielded-integrity-monitoring
--container-image=$$DEPLOY_APP_DOCKER_IMAGE@$(cat
/workspace/app-image-long-id) --container-restart-policy=always
--labels=container-vm=cos-stable-93-16623-39-13
id: create-vm-instance-template
waitFor:
- upload-images
entrypoint: bash
timeout: 3000s
images:
- '$_GCR_REGION/$PROJECT_ID/$_SERVICE_NAME-cache/$BRANCH_NAME:latest'
options:
substitutionOption: ALLOW_LOOSE
env:
- COMPOSE_DOCKER_CLI_BUILD=1
- DOCKER_BUILDKIT=1
- NODE_ENV=production
- >-
APP_CACHE_DOCKER_IMAGE=$_GCR_REGION/$PROJECT_ID/$_SERVICE_NAME-cache/$BRANCH_NAME
- >-
DEPLOY_APP_DOCKER_IMAGE=$_GCR_REGION/$PROJECT_ID/$_SERVICE_NAME/$BRANCH_NAME
- RELEASE_IMAGE_VERSION=latest
substitutions:
_SERVICE_NAME: service-frontend-app
_GCR_REGION: asia.gcr.io
@IvanWei
Copy link
Author

IvanWei commented Nov 5, 2021

CI/CD with Google Cloud

Continuous Deployment flow

Typescript compiler → Push container images to GCR → Create instance template → Upgrade instance groups (Not yet)

Troubleshooting

Cloud build

  • Create instance templates failure
  • options
    • machineType: default level is e2-medium , First 120 builds-minutes per day are free. Get more e free time, upgrade machine level (Machine Type).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment