登录
首页 >  Golang >  Go问答

如何允许 App Engine 验证并下载私有 Go 模块

来源:stackoverflow

时间:2024-04-11 09:27:32 145浏览 收藏

大家好,我们又见面了啊~本文《如何允许 App Engine 验证并下载私有 Go 模块》的内容中将会涉及到等等。如果你正在学习Golang相关知识,欢迎关注我,以后会给大家带来更多Golang相关文章,希望我们能一起进步!下面就开始本文的正式内容~

问题内容

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

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

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

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

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


解决方案


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

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

执行此操作所需的 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 </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"

本篇关于《如何允许 App Engine 验证并下载私有 Go 模块》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>