在私人的package.json git仓库谷歌App Engine的部署(Google App E

2019-10-29 16:16发布

我在我的package.json依赖私人到位桶回购

{
   "my-dependency": "git+ssh://git@bitbucket.org/something/my-dependency.git"
}

我跟着中给出的说明[1]和[2]和创建的我与公里加密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不访问步骤#定义的SSH密钥0和#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] 链接库私人在packages.json在应用程序部署到gcloud

Answer 1:

每当有一个Host Key verification failed的错误,这是最有可能与您known_hosts文件,这意味着主机密钥bitbucket.org是不是在你的known_hosts文件等客户端没有办法验证它。 尝试运行ssh-keyscan -t rsa bitbucket.org > known_hosts ,然后cat known_hosts ,看看bitbucket.org主机密钥是存在的。

如果答案是否定的,输出是空的,它可能是一个网络问题与过程的干扰。 按照这个公认的答案线程来解决它。

如果答案是肯定的,完美的,只有一个步骤中缺少,那就是配置SSH密钥插入到位桶。 进入bitbucket.org下“到位桶设置”,然后单击其中的一个选项“SSH密钥”。 添加一个键(标注为你决定何种名称),并粘贴您从运行猫的〜/ .ssh / id_rsa.pub成关键部分得到的输出。

从本质上讲,在一个线程你联系我克隆到私人目录中相同的文件夹我的应用程序的根。 这样一来,在我的package.json可以简单地加入这一行dependencies: {“circular-structure-stringify”: “./circular-structure-stringify”}这将让我require()它像任何NPM包。

我知道我应该已经把GitHub的链接打开但尽管如此,我的工作,我会在评论部分很快被张贴另一个例子。 同时,让我知道结果。



Answer 2:

因此很明显,这是不可能提供的SSH密钥gcloud app deploy的一步。 因此,使用

{
   "my-dependency": "git+ssh://git@bitbucket.org/something/my-dependency.git"
}

不管用!

解决方法(如@JKleinne在链接的线程中提到)是克隆回购,从本地文件夹安装:

{
  "my-dependency": "lib/my-dependency"
}

我写了一个小bash脚本来检查,如果回购可以访问和克隆/如果可以拉:

GIT_PROJECT=$1
GIT_REPO=$2
NAME=${GIT_REPO}
REMOTE="git@bitbucket.org:${GIT_PROJECT}/${GIT_REPO}.git"

if [[ ! -d ./lib ]]
then
    mkdir -p ./lib
fi

## Test if git repo is accessible
if ! git ls-remote --exit-code -h ${REMOTE}; then
    echo "Unable to access git repo, skipping"
    exit 0
fi

## Clone or pull
if [[ ! -d ./lib/${NAME} ]]
then
    git clone ${REMOTE} ./lib/${NAME}
else
    git -C ./lib/${NAME} pull
fi

然后,我在安装前脚本使用它:

"preinstall": "./get-internal-package.sh something my-dependency",


文章来源: Google App Engine deployment with private git repo in package.json