【发布时间】:2020-01-29 20:50:36
【问题描述】:
我的 package.json 中有一个私有 Bitbucket 存储库的依赖项
{
"my-dependency": "git+ssh://git@bitbucket.org/something/my-dependency.git"
}
我按照 [1] 和 [2] 中的说明创建了一个使用 kms 加密的 SSH 密钥。
我创建了一个自定义cloudbuild.yaml,如下所示:
# Decrypt the file containing the key
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args:
- kms
- decrypt
- --ciphertext-file=bitbucket_rsa.enc
- --plaintext-file=/root/.ssh/id_rsa
- --location=global
- --keyring=default
- --key=bitbucket-key
volumes:
- name: 'ssh'
path: /root/.ssh
# Set up git with key and domain
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
chmod 600 /root/.ssh/id_rsa
cat <<EOF >/root/.ssh/config
Hostname bitbucket.org
IdentityFile /root/.ssh/id_rsa
EOF
mv known_hosts /root/.ssh/known_hosts
volumes:
- name: 'ssh'
path: /root/.ssh
# Install
- name: 'gcr.io/cloud-builders/yarn'
args: ['install']
volumes:
- name: 'ssh'
path: /root/.ssh
# Build
- name: "gcr.io/cloud-builders/yarn"
args: ["build"]
volumes:
- name: 'ssh'
path: /root/.ssh
# Deploy
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy", "my-service.yaml"]
volumes:
- name: 'ssh'
path: /root/.ssh
当我通过gcloud builds submit --config=cloudbuild.yaml 运行它时,步骤 #0 到 #3 运行良好,但步骤 #4 失败,因为 app deploy 触发另一个 yarn install,它无法访问步骤 #0 中定义的 SSH 密钥和#1:
Step #4: INFO rm_node_modules took 0 seconds
Step #4: INFO starting: yarn_install
Step #4: INFO yarn_install yarn install
Step #4: INFO `yarn_install` stdout:
Step #4: yarn install v1.9.4
Step #4: [1/5] Validating package.json...
Step #4: [2/5] Resolving packages...
Step #4: [3/5] Fetching packages...
Step #4: info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Step #4:
Step #4: INFO `yarn_install` had stderr output:
Step #4: error Command failed.
Step #4: Exit code: 128
Step #4: Command: git
Step #4: Arguments: ls-remote --tags --heads ssh://git@bitbucket.org/something/my-dependency.git
Step #4: Directory: /workspace
Step #4: Output:
Step #4: Host key verification failed.
Step #4: fatal: Could not read from remote repository.
Step #4:
Step #4: Please make sure you have the correct access rights
Step #4: and the repository exists.
Step #4:
Step #4: ERROR error: `yarn_install` returned code: 1
Step #4: INFO yarn_install took 11 seconds
Step #4: INFO build process for FTL image took 11 seconds
Step #4: INFO full build took 11 seconds
Step #4: ERROR `yarn_install` had stderr output:
Step #4: error Command failed.
感谢您的帮助!
参考资料:
[1]https://cloud.google.com/cloud-build/docs/access-private-github-repos
[2]Link private repository in packages.json in app deployed to gcloud
【问题讨论】:
-
忘了提到在
.gcloudignore中添加!node_modules/,从而将所有模块发送到应用程序部署产生INVALID_ARGUMENT: This deployment has too many files. New versions are limited to 10000 files for this app
标签: node.js google-app-engine npm google-cloud-platform google-cloud-build