【问题标题】:Secret in Cloud Build to Cloud run stepCloud Build 到 Cloud 运行步骤中的秘密
【发布时间】:2022-01-22 19:59:47
【问题描述】:

我正在尝试使用 Cloud Build 和 Cloud Run 为我的应用设置 CICD。 我的 cloudbuild.yaml 看起来像这样:

 steps:
 # Build the container image
 - name: 'gcr.io/cloud-builders/docker'
   args: ['build', '-t', 'gcr.io/project/dsapp-staging:$COMMIT_SHA', '.']
   timeout: '1200s'
 # Push the container image to Container Registry
 - name: 'gcr.io/cloud-builders/docker'
   args: ['push', 'gcr.io/project/dsapp-staging:$COMMIT_SHA']
   timeout: '1200s'
 # Deploy container image to Cloud Run
 - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
   entrypoint: gcloud
   args:
   - 'run'
   - 'deploy'
   - 'dsapp-staging'
   - '--image'
   - 'gcr.io/project/dsapp-staging:$COMMIT_SHA'
   - '--region'
   - 'europe-west1'
   - "--set-env-vars=FIREBASE_AUTH=$$FIREBASE_AUTH"
   timeout: '1200s'
   secretEnv: ['FIREBASE_AUTH']
 timeout: '1200s'

 availableSecrets:
  secretManager:
  - versionName: projects/projectid/secrets/FIREBASE_AUTH/versions/1
    env: 'FIREBASE_AUTH'

 images:
 - 'gcr.io/project/dsapp-staging:$COMMIT_SHA'

我的问题在于“FIREBASE_AUTH”秘密变量,我收到一条错误消息,提示我无法使用替换。 如何将我从秘密中获取的 env var 传递给我的 gcloud 命令?

【问题讨论】:

    标签: google-cloud-run google-cloud-build


    【解决方案1】:

    您不能在 Cloud Build 中使用类似的密钥。我不知道技术原因,但我可以给你解决方法:你必须在你的步骤中使用 shell 模式。就这样写吧

     - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
       entrypoint: bash
       args:
       - '-c'
       - "gcloud run deploy dsapp-staging --image gcr.io/project/dsapp-taging:$COMMIT_SHA --region europe-west1 --set-env-vars=FIREBASE_AUTH=$$FIREBASE_AUTH"
       timeout: '1200s'
       secretEnv: ['FIREBASE_AUTH']
    
    

    现在它可以工作了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-21
      • 1970-01-01
      • 2019-05-23
      • 1970-01-01
      • 2020-08-23
      • 2021-11-20
      • 1970-01-01
      • 2021-05-14
      相关资源
      最近更新 更多