iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 15
0
Software Development

Microservices in Action: with example in Node.js系列 第 15

Staging 環境 CI/CD

這裡我們使用的是 GCP 的 Cloud Build 服務,因為 staging 環境跟 production 環境要執行的步驟稍微有一些差異,所以我們把 config 分開寫。

步驟說明

  1. 安裝相依模組
  2. 執行整合測試
  3. 打包客製化的 image,並採用 Kaniko 的快取策略。
  4. 將 image 上傳到 GCR 服務
  5. 自動部署微服務

Kaniko 參數說明

  • build-arg

  • cache

    • 使用 kaniko 進行緩存
    • 範例:true
  • cache-dir

    • 要 cache 的資料夾位置
    • 範例:/cache
  • cache-ttl

    • 設定多久後 Cache 會過期,預設是兩週。
    • 範例:6h
  • destination

    • 你的 image 要上傳的位置
    • 範例:gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA
  • kaniko - Build Images In Kubernetes

完整的 staging-auth-ci.yaml 檔案

steps:
  - name: node:12.18.3
    id: yarn-install
    entrypoint: yarn
    args: ["install"]

  - name: node:12.18.3
    id: auth-test
    env:
      - "NEW_RELIC_NO_CONFIG_FILE=true"
      - "NEW_RELIC_ENABLED=false"
    entrypoint: npm
    args: ["run", "test"]
    dir: "packages/auth-server"

  - name: "gcr.io/kaniko-project/executor:v0.22.0"
    id: auth-build
    env: ["NODE_ENV=$_NODE_ENV"]
    args:
      - --dockerfile=docker/auth-server.Dockerfile
      - --build-arg=NODE_ENV=$_NODE_ENV
      - --destination=gcr.io/$PROJECT_ID/auth-server:ci-$_NODE_ENV-$SHORT_SHA
      - --cache=true
      - --cache-ttl=6h

  - 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=staging-cluster"

上一篇
透過 Ingress 處理外部路由
下一篇
Production 環境 CI/CD
系列文
Microservices in Action: with example in Node.js24
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言