[英]ECR image push AWS CodeBuild issue
COMMAND_EXECUTION_ERROR:执行命令时出错:$(aws ecr get-login --no-include-email --region us-east-1)。 原因:退出状态 127
下面是我的 buildspec.yml 文件
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- $(aws ecr get-login --region ***-east-*)
- REPOSITORY_URI=***********.dkr.ecr.***-east-*.amazonaws.com/repositoryname
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION)
- IMAGE_TAG=${COMMIT_HASH:=latest}
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed
- echo Pushing the Docker images...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing definitions file...
- printf '[{"name":"project-container","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > taskdefinition.json
artifacts:
files: taskdefinition.json
你的帖子有不一致的细节,是故意的吗? 如果没有,它可能会导致问题。 你的代码片段说:
$(aws ecr get-login --region ***-east-*)
也许您故意编辑了该区域(顺便说一句,这有什么意义?)但为什么它缺少--no-include-email
? 在您的帖子中,您确实提到了--no-include-email
,所以我知道您知道这一点。
与其在子shell 中运行它(例如$(my command)
),出于故障排除目的,请尝试将子shell 取出来运行,以便获得更好的输出。 在此处报告结果,以便我们对您遇到的错误进行故障排除。
aws ecr get-login --no-include-email --region us-east-1
<- 暂时试试这个
对比
$(aws ecr get-login --no-include-email --region us-east-1)
这是非常重要的。 CodeBuild 需要获得代表您访问 ECR 的权限。 这是我在这篇博客文章中找到的一个例子。 它可能需要根据您的需求进行调整。 http://beta.awsdocs.com/services/code_build/build_docker_images/
{
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:CompleteLayerUpload",
"ecr:GetAuthorizationToken",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:UploadLayerPart"
],
"Resource": "*",
"Effect": "Allow"
}
万一它帮助其他人,对于我在 CodeBuild 执行的构建脚本中所做的工作。 这些是我必须添加的 IAM 权限(在我遇到错误时一一查找)。
{
"Action": [
"ecr:GetAuthorizationToken",
"ecr:DescribeRepositories",
"ecr:CreateRepository",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:BatchCheckLayerAvailability",
"ecr:PutImage",
"ecs:UpdateService"
],
"Resource": "*",
"Effect": "Allow"
} '
我敢肯定,如果您正在做我在构建中没有做的事情,可能需要更多权限。 我正在推动 ECR 并强制服务(和相关任务)部署新映像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.