我们有两份报告
在回购1> package.json内部有一个依赖项
"dependencies": {
"repo-2": "git+https://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo-2/"
}然后,在"repo-1“的CodeBuild内部,我们有以下构建规范
version: 0.2
phases:
install:
runtime-versions:
nodejs: 10
commands:
- mkdir -p ./deploy
build:
commands:
- echo "Server copy START $(date)"
- cp -r ./index.js ./deploy/index.js
- cp -r ./package.json ./deploy/package.json
- cp -r ./buildspec.yml ./deploy/buildspec.yml
- echo "Server copy END $(date)"
- echo "Server npm install START $(date)"
- cd ./deploy && npm install --production
- echo "Server npm install END $(date)"
post_build:
commands:
artifacts:
files:
- '**/*'
base-directory: 'deploy'CodeBuild抛出的错误如下
npm ERR! fatal: unable to access 'https://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo-2/': The requested URL returned error: 403 基本上,问题是:我是否可以使用CodeCommit回购作为npm的依赖项,那么正确的方法是什么?
试#1
我试图添加这个(和类似的变体),但是没有成功,https://medium.com/@ngchiwang/aws-npm-install-private-codecommit-module-8512c3203c37
#Try 2
我还试图将依赖项URL更改为
"repo-2": "git://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo-2"但是获取以下错误
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fatal: unable to connect to git-codecommit.us-east-1.amazonaws.com:
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: git-codecommit.us-east-1.amazonaws.com[0: 52.94.233.146]: errno=Connection refused发布于 2019-09-24 13:27:10
我今天遇到了同样的问题,并通过在git-credential-helper构建规范文件的env部分启用了。
示例:
version: 0.2
env:
git-credential-helper: yes
phases:
install:
runtime-versions:
nodejs: 10
commands:
- npm install
build:
commands:
- npm run build这与策略中的CodeCommit特权(您已经说过)结合在一起,导致使用来自CodeCommit的私有npm包构建。
发布于 2019-11-28 03:55:45
I上周也有类似的问题,所以我将分享为Amazon推荐的解决方案。
更好的方法是在buildspec文件的env部分中将“git-凭证-助手”设置为“git-凭证-助手”,然后可以使用https访问存储库。同样,请参考下面的BuildSpec示例。
================Buildspec Snippet=================
版本: 0.2
env:
git-credential-helper: yes
phases:
pre_build:
commands:
- /usr/bin/git ls-remote -h -t https://git-codecommit.us-east-1.amazonaws.com/v1/repos/repo-2/================Buildspec Snippet=================
此外,请确保您提供了访问CodeCommit存储库所需的CodeBuild IAM角色权限。我提供了下面的IAM策略示例,您可以参考它提供权限,具体取决于您的用例:
===========IAM策略example=============
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"codecommit:GetRepository",
"codecommit:GitPull",
"codecommit:GetFolder"
],
"Resource": "arn:aws:codecommit:us-east-1:<put repo Name or *>"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": "codecommit:ListRepositories",
"Resource": "*"
}
]
}===========IAM策略example=============
请检查上述方法是否有助于实现用例.
请注意,上面的buildspec片段只是解释如何访问CodeCommit回购的一个例子,它需要根据您的需求进行修改。例如,您可以在package.json中描述存储库的依赖性,如下所示,我假设您已经在通过代码构建中的buildspec文件运行npm。
"dependencies": {
"my-npm": "git+https://git-codecommit.us-east-1.amazonaws.com/v1/repos/<repo name>"
},发布于 2019-08-29 12:01:35
尝试使用以下命令将您的私有AWS CodeCommit回购作为您的npm模块:
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
git config --global url."ssh://".insteadOf https://
npm install --save git+https://<your_repo_url>#master如果您想使用npm依赖项,请查看以下类似问题的答案:npm install private github repositories by dependency in package.json
https://stackoverflow.com/questions/57709367
复制相似问题