CodePipeline 无法使用 Gemfile 中的 "git" 引用下拉私人 gem 回购协议
CodePipeline fails to pull down private gem repos with "git" references in Gemfile
我在 AWS CodeBuild 中设置了 rails 应用程序。该应用程序的源存储库位于 Github 的私有 git 存储库中,并且使用 AWS Github 连接器,该应用程序的构建过程能够成功检出该应用程序的源代码并开始构建步骤。
但是,当 bundle install
在存储库中 运行 时,构建过程失败 - 我们在 Gemfile 中有一些来自我们组织的私有 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 容器是否需要执行其他操作才能在私有存储库中提取存储库?有没有人有在 AWS CodeBuild/Codepipeline 中工作的 rails 应用程序 w/ 私有 git 回购中引用的宝石的任何示例?
回答我自己的问题以防其他人遇到这个问题 - Gemfile 中的“git@github.com...”引用强制捆绑器使用密钥对来获取 gem - 由于 CodeBuild 没有可用于这些其他存储库的有效密钥,我们遇到了那些“权限被拒绝”的问题。
有几种方法可以解决此问题 - 首先,切换到使用“https://...”引用 gem 文件中的 gem。如果你不想这样做,你可以像这样在你的构建管道中尽早添加一些东西:
git config --global url."https://github.com/".insteadOf "git@github.com:"
我在 AWS CodeBuild 中设置了 rails 应用程序。该应用程序的源存储库位于 Github 的私有 git 存储库中,并且使用 AWS Github 连接器,该应用程序的构建过程能够成功检出该应用程序的源代码并开始构建步骤。
但是,当 bundle install
在存储库中 运行 时,构建过程失败 - 我们在 Gemfile 中有一些来自我们组织的私有 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 容器是否需要执行其他操作才能在私有存储库中提取存储库?有没有人有在 AWS CodeBuild/Codepipeline 中工作的 rails 应用程序 w/ 私有 git 回购中引用的宝石的任何示例?
回答我自己的问题以防其他人遇到这个问题 - Gemfile 中的“git@github.com...”引用强制捆绑器使用密钥对来获取 gem - 由于 CodeBuild 没有可用于这些其他存储库的有效密钥,我们遇到了那些“权限被拒绝”的问题。
有几种方法可以解决此问题 - 首先,切换到使用“https://...”引用 gem 文件中的 gem。如果你不想这样做,你可以像这样在你的构建管道中尽早添加一些东西:
git config --global url."https://github.com/".insteadOf "git@github.com:"