Step1: 打包客製化的 image
docker build -f docker/auth-server.Dockerfile --build-arg NODE_ENV=$_NODE_ENV -t gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA .
Step2: 將 image 上傳到 GCR 服務
docker push gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA .
Step3: 自動部署微服務
export CLOUDSDK_COMPUTE_ZONE=asia-east1-a
export CLOUDSDK_CONTAINER_CLUSTER=prod-cluster
kubectl set image deployment auth-deployment auth-server=gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA
steps:
- name: "gcr.io/cloud-builders/docker"
id: auth-build
env: ["NODE_ENV=$_NODE_ENV"]
args:
- "build"
- "-f"
- "docker/auth-server.Dockerfile"
- "--build-arg"
- "NODE_ENV=$_NODE_ENV"
- "-t"
- "gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA"
- "."
- name: "gcr.io/cloud-builders/docker"
id: auth-push
args:
- "push"
- "gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA"
- name: "gcr.io/cloud-builders/kubectl"
args:
- set
- image
- deployment
- auth-deployment
- auth-server=gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA
env:
- "CLOUDSDK_COMPUTE_ZONE=asia-east1-a"
- "CLOUDSDK_CONTAINER_CLUSTER=prod-cluster"