【发布时间】:2020-11-26 05:57:20
【问题描述】:
我正在尝试在 Cloud Build 步骤中使用 exec-wrapper 来运行 Cloud SQL 代理并运行节点脚本来执行自定义数据库迁移。这是我的云构建配置的样子:
steps:
- name: gcr.io/cloud-builders/docker
args: ['build', '-t', 'gcr.io/$PROJECT_ID/api-stg', '.']
- name: gcr.io/cloud-builders/docker
args: ['push', 'gcr.io/$PROJECT_ID/api-stg']
- name: gcr.io/cloud-builders/gcloud
args: ['app', 'deploy', 'app-stg.yaml', '--image-url=gcr.io/$PROJECT_ID/api-stg']
- name: "gcr.io/google-appengine/exec-wrapper"
args: ["-i", "gcr.io/$PROJECT_ID/api-stg",
"-s", "$PROJECT_ID:us-central1:<Cloud SQL Instance Name>",
"--", "scripts/management/custom_migration"]
images: ['gcr.io/$PROJECT_ID/api-stg']
timeout: 1200s # 20 minutes
在我的custom_migration.js 文件中,我有如下内容:
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const bucket = storage.bucket(BUCKET_NAME);
const file = await bucket.file(key);
const result = await new Promise(resolve => file.download((err, data) => {...}));
...
这会导致google-auth-library 出现以下错误:
Error: The file at /root/.google/credentials does not exist, or it is not a file.
Error: ENOENT: no such file or directory, lstat '/root/.google'
当部署在新版本中时,我的 App Engine 柔性环境能够运行此代码,但 Cloud Build 步骤中的相同代码未正确获得凭据。如何允许 exec-wrapper 使用我的 App Engine 柔性环境的默认凭据?
【问题讨论】:
-
这里为什么需要一个 exec-wrapper?
-
@guillaumeblaquiere 我需要一个 exec-wrapper 以便通过 Cloud SQL 代理连接到我的 Cloud SQL 实例。看来这就是 exec 包装器的目的
-
好的,您需要一个 Cloud SQL 连接和 nodeJS 环境来运行您的迁移脚本,对吗?如果我有正确答案,我还会向您解释 exec-wrapper 和 Cloud Build 元数据服务器的问题。
-
@guillaumeblaquiere 是的,没错!
-
脚本
scripts/management/custom_migration在你的容器gcr.io/$PROJECT_ID/api-stg中还是在外面?
标签: node.js docker google-cloud-platform google-cloud-storage google-cloud-build