【问题标题】:How to allow App Engine to authenticate and download private Go modules如何允许 App Engine 验证和下载私有 Go 模块
【发布时间】:2019-09-06 16:31:53
【问题描述】:

我的项目使用托管在私有 GitHub 存储库中的 Go 模块。

这些都列在我的 go.mod 文件中,在公共文件中。

在我的本地计算机上,通过在项目的本地 git 配置文件中使用正确的 SSH 密钥或 API 令牌对私有存储库进行身份验证没有问题。该项目在这里编译得很好。

在部署 (gcloud app deploy) 和云中的构建阶段期间,git 配置和 .netrc 文件均未考虑在内,因此我的项目编译失败并出现私有模块的身份验证错误。

解决这个问题的最佳方法是什么?我想避免一种解决方法,即在部署的文件中包含私有模块的源代码,而是想办法让远程运行或 git 使用我可以提供的凭据。

【问题讨论】:

  • 我建议您将 mirror the github 回购到云回购,然后在您的 App Engine 部署中引用云回购

标签: google-app-engine go


【解决方案1】:

您可以尝试直接从构建中部署它。根据Accessing private GitHub repositories,您可以在其中一个构建步骤中使用密钥和域设置 git。

之后,您可以按照Quickstart for automating App Engine deployments with Cloud Build 中的建议,指定一个步骤来运行gcloud app deploy 命令。

执行此操作所需的 cloudbuild.yaml 示例如下:

# Decrypt the file containing the key
steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args:
  - kms
  - decrypt
  - --ciphertext-file=id_rsa.enc
  - --plaintext-file=/root/.ssh/id_rsa
  - --location=global
  - --keyring=my-keyring
  - --key=github-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 github.com
    IdentityFile /root/.ssh/id_rsa
    EOF
    mv known_hosts /root/.ssh/known_hosts
  volumes:
  - name: 'ssh'
    path: /root/.ssh

# Deploy app
- name: "gcr.io/cloud-builders/gcloud"
  args: ["app", "deploy"]
timeout: "16000s"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-05
    • 1970-01-01
    • 2016-10-13
    • 2016-07-12
    • 2019-04-30
    • 2020-05-11
    • 2021-08-17
    • 1970-01-01
    相关资源
    最近更新 更多