ruby-on-rails - CodePipeline 无法使用 Gemfile 中的 "git"引用拉下私有(private) gem 存储库

标签 ruby-on-rails aws-codepipeline aws-code-deploy

我在 AWS CodeBuild 中设置了一个 Rails 应用程序。该应用程序的源存储库位于 Github 中的私有(private) git 存储库中,并且借助 AWS Github 连接器,该应用程序的构建过程能够成功 check out 该应用程序的源代码并开始构建步骤。

构建过程失败,但是,当 bundle install 在存储库中运行时 - 我们在 Gemfile 中有许多来 self 们组织的私有(private) gem,包含在 gem“somegem”中, git: git@github.com:... 模式。 CodeBuild 应该 能够拉下这些存储库 - 它们都已在 AWS Github 连接器中启用,并且主应用程序的存储库已成功拉下。 bundle install 运行时我们看到的是:

[Container] 2021/02/25 18:08:42 Moving to directory /codebuild/output/src384/src/s3/00
[Container] 2021/02/25 18:08:42 Registering with agent
[Container] 2021/02/25 18:08:42 Phases found in YAML: 2
[Container] 2021/02/25 18:08:42  INSTALL: 3 commands
[Container] 2021/02/25 18:08:42  BUILD: 4 commands
[Container] 2021/02/25 18:08:42 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2021/02/25 18:08:42 Phase context status code:  Message: 
[Container] 2021/02/25 18:08:42 Entering phase INSTALL
[Container] 2021/02/25 18:08:42 Running command bundle config set path vendor/bundle

[Container] 2021/02/25 18:08:44 Running command bundle config set clean 'true'

[Container] 2021/02/25 18:08:44 Running command bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/.......
Fetching git@github.com:OrganizationName/ApplicationName.git
Warning: Permanently added the RSA host key for IP address '140.82.114.3' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Retrying `git clone 'git@github.com:OrganizationName/ApplicationName.git' "/codebuild/output/src384/src/s3/00/vendor/bundle/ruby/2.7.0/cache/bundler/git/ApplicationName-8bd8465f89c17a9b95589e33678f605c1f1e45c5" --bare --no-hardlinks --quiet` due to error (2/4): Bundler::Source::Git::GitCommandError Git error: command `git clone 'git@github.com:OrganizationName/ApplicationName.git' "/codebuild/output/src384/src/s3/00/vendor/bundle/ruby/2.7.0/cache/bundler/git/ApplicationName-8bd8465f89c17a9b95589e33678f605c1f1e45c5" --bare --no-hardlinks --quiet` in directory /codebuild/output/src384/src/s3/00 has failed.
Permission denied (publickey).
fatal: Could not read from remote repository.

此时,整个构建步骤失败。 CodeBuild 容器是否需要执行其他操作才能在私有(private)存储库中提取存储库?有没有人有在 AWS CodeBuild/Codepipeline 中工作的带有 gems 的 Rails 应用程序示例?

最佳答案

回答我自己的问题以防其他人遇到这个问题 - Gemfile 中的“git@github.com ...”引用强制 bundler 使用 key 对来获取 gem - 因为 CodeBuild 没有有效的用于这些其他 repo 的 key ,我们会遇到那些“权限被拒绝”的问题。

有几种方法可以解决这个问题 - 首先,是切换到使用“https://...”对 gemfile 中的 gem 的引用。如果您不想这样做,您可以像这样在构建管道的早期添加一些东西:

    git config --global url."https://github.com/".insteadOf "git@github.com:"

关于ruby-on-rails - CodePipeline 无法使用 Gemfile 中的 "git"引用拉下私有(private) gem 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66374433/

相关文章:

amazon-web-services - 如何在 CodeDeploy 中设置和获取环境变量

ruby-on-rails - UUID 和整数字段的多态关联

typescript - AWS CDK 部署在 CodePipeline/CodeBuild 中

lambda - AWS CodePipeline : pass Lambda function output to CloudFormation

amazon-web-services - 如何为合并的 GitHub 拉取请求触发 CodePipeline?

amazon-web-services - AWS : Code deploy installation failed

html - 如何转义我的 application.html.erb 文件

ruby-on-rails - Rails 模块作用域

mysql - 连接表格和 map 显示

linux - 如何在通过 AWS CodeDeploy 从 Git (Bitbucket) 部署后保留符号链接(symbolic link)