我们想用ECR上已有的图像来尝试CodePipeline。
因此,我们遵循文档中的步骤。
我们有这样的buildspec.yml:
phases:
install:
runtime-versions:
nodejs: 10
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- $(aws ecr get-login --no-include-email --region us-east-1)
- REPOSITORY_URI=OUR_URL_FROM_ECR
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
- echo $REPOSITORY_URI
- echo $COMMIT_HASH
- echo $IMAGE_TAG
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 on `date`
- echo Pushing the Docker images...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"Petr","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json
我们创建了一个新的管道流,但当我们推动一些更改时,我们会得到以下日志:
[Container] 2019/11/07 23:30:49 Waiting for agent ping
[Container] 2019/11/07 23:30:51 Waiting for DOWNLOAD_SOURCE
[Container] 2019/11/07 23:30:52 Phase is DOWNLOAD_SOURCE
[Container] 2019/11/07 23:30:52 CODEBUILD_SRC_DIR=/codebuild/output/src386464501/src
[Container] 2019/11/07 23:30:52 YAML location is /codebuild/output/src386464501/src/buildspec.yml
[Container] 2019/11/07 23:30:52 No commands found for phase name: INSTALL
[Container] 2019/11/07 23:30:52 Processing environment variables
[Container] 2019/11/07 23:30:52 Moving to directory /codebuild/output/src386464501/src
[Container] 2019/11/07 23:30:52 Registering with agent
[Container] 2019/11/07 23:30:52 Phases found in YAML: 4
[Container] 2019/11/07 23:30:52 POST_BUILD: 6 commands
[Container] 2019/11/07 23:30:52 INSTALL: 0 commands
[Container] 2019/11/07 23:30:52 PRE_BUILD: 9 commands
[Container] 2019/11/07 23:30:52 BUILD: 4 commands
[Container] 2019/11/07 23:30:52 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2019/11/07 23:30:52 Phase context status code: Message:
[Container] 2019/11/07 23:30:52 Entering phase INSTALL
[Container] 2019/11/07 23:30:52 Running command echo "Installing Node.js version 10 ..."
Installing Node.js version 10 ...
[Container] 2019/11/07 23:30:52 Running command n 10.16.3
installed : v10.16.3 (with npm 6.9.0)
[Container] 2019/11/07 23:31:02 Phase complete: INSTALL State: SUCCEEDED
[Container] 2019/11/07 23:31:02 Phase context status code: Message:
[Container] 2019/11/07 23:31:02 Entering phase PRE_BUILD
[Container] 2019/11/07 23:31:02 Running command echo Logging in to Amazon ECR...
Logging in to Amazon ECR...
[Container] 2019/11/07 23:31:02 Running command aws --version
aws-cli/1.16.242 Python/3.6.8 Linux/4.14.143-91.122.amzn1.x86_64 exec-env/AWS_ECS_EC2 botocore/1.12.232
[Container] 2019/11/07 23:31:07 Running command $(aws ecr get-login --no-include-email --region us-east-1)
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[Container] 2019/11/07 23:31:10 Running command REPOSITORY_URI=***********
[Container] 2019/11/07 23:31:10 Running command COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
[Container] 2019/11/07 23:31:10 Running command IMAGE_TAG=${COMMIT_HASH:=latest}
[Container] 2019/11/07 23:31:10 Running command echo $REPOSITORY_URI
***********
[Container] 2019/11/07 23:31:10 Running command echo $COMMIT_HASH
88f8cfc
[Container] 2019/11/07 23:31:10 Running command echo $IMAGE_TAG
88f8cfc
[Container] 2019/11/07 23:31:10 Phase complete: PRE_BUILD State: SUCCEEDED
[Container] 2019/11/07 23:31:10 Phase context status code: Message:
[Container] 2019/11/07 23:31:10 Entering phase BUILD
[Container] 2019/11/07 23:31:10 Running command echo Build started on `date`
Build started on Thu Nov 7 23:31:10 UTC 2019
[Container] 2019/11/07 23:31:10 Running command echo Building the Docker image...
Building the Docker image...
[Container] 2019/11/07 23:31:10 Running command docker build -t $REPOSITORY_URI:latest .
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[Container] 2019/11/07 23:31:10 Command did not exit successfully docker build -t $REPOSITORY_URI:latest . exit status 1
[Container] 2019/11/07 23:31:10 Phase complete: BUILD State: FAILED
[Container] 2019/11/07 23:31:10 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -t $REPOSITORY_URI:latest .. Reason: exit status 1
[Container] 2019/11/07 23:31:10 Entering phase POST_BUILD
[Container] 2019/11/07 23:31:10 Running command echo Build completed on `date`
Build completed on Thu Nov 7 23:31:10 UTC 2019
[Container] 2019/11/07 23:31:10 Running command echo Pushing the Docker images...
Pushing the Docker images...
[Container] 2019/11/07 23:31:10 Running command docker push $REPOSITORY_URI:latest
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[Container] 2019/11/07 23:31:10 Command did not exit successfully docker push $REPOSITORY_URI:latest exit status 1
[Container] 2019/11/07 23:31:10 Phase complete: POST_BUILD State: FAILED
[Container] 2019/11/07 23:31:10 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker push $REPOSITORY_URI:latest. Reason: exit status 1
[Container] 2019/11/07 23:31:10 Expanding base directory path: .
[Container] 2019/11/07 23:31:10 Assembling file list
[Container] 2019/11/07 23:31:10 Expanding .
[Container] 2019/11/07 23:31:10 Expanding file paths for base directory .
[Container] 2019/11/07 23:31:10 Assembling file list
[Container] 2019/11/07 23:31:10 Expanding imagedefinitions.json
[Container] 2019/11/07 23:31:10 Skipping invalid file path imagedefinitions.json
[Container] 2019/11/07 23:31:10 Phase complete: UPLOAD_ARTIFACTS State: FAILED
[Container] 2019/11/07 23:31:10 Phase context status code: CLIENT_ERROR Message: no matching artifact paths found
我们想知道我们是否错过了什么,我们从这里开始遵循一些步骤:
https://aws.amazon.com/es/blogs/devops/build-a-continuous-delivery-pipeline-for-your-container-images-with-amazon-ecr-as-source/
有什么建议吗?
我遇到了类似的错误。修复方法是,此构建项目需要构建Docker映像,因此将Privilege Mode设置为true。
特权模式授予构建项目的Docker容器访问权限。
有两种可能性:-
一个是你没有在你为ec2实例创建的角色中添加ecr和ecs,或者如果你使用的是弹性豆茎。首先验证
否则,请研究第二种可能性:-在您的阶段使用以下命令:-
阶段:安装:命令:-nohup/usr/local/bin/dockerd—主机=unix:///var/run/docker.sock--主机=tcp://127.0.0.1:2375--存储驱动程序=overlay2&-timeout 15 sh-c"直到docker信息;执行回声。;睡眠1;完成">
有关详细信息,请使用此链接https://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker-custom-image.html#sample-docker自定义图像文件
https://docs.aws.amazon.com/codebuild/latest/userguide/troubleshooting.html#troubleshooting-无法连接到docker守护程序
对于错误
无法连接到位于的Docker守护进程unix:///var/run/docker.sock.是docker守护进程正在运行?
我发现这很有帮助:https://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html
特别是第5.d.点
-
直接按照Run CodeBuild中的步骤创建生成项目、运行生成并查看生成信息。
如果你使用控制台来创建你的项目:
a。对于操作系统,请选择Ubuntu。
b。选择"标准"作为"运行时"。
c。对于"图像",请选择aws/codebuild/standard:4.0。
d。因为您使用此构建项目来构建Docker映像,所以请选择Privileged。
我遇到了和你一样的问题,我解决这个问题的方法是:尝试转到CodeBuild,然后转到它的IAM角色。AmazonEC2ContainerRegistryFullAccess
角色,现在单击该代码构建的"编辑"并选择"环境",然后单击Allow AWS CodeBuild to modify this service role so it can be used with this building project
。现在再试一次。
干杯
我知道这是旧的,但如果你在代码构建中已经有了权限,请注意,正如AWS的一名工作人员所说,每侧都需要两个权限。您基本上需要获得ERC/Codebuild的权限。
请参阅本期