Amazon web services AWS ECS代码管道生成错误存储库\u URI

Amazon web services AWS ECS代码管道生成错误存储库\u URI,amazon-web-services,amazon-ecs,aws-codepipeline,Amazon Web Services,Amazon Ecs,Aws Codepipeline,我们想用ECR上已有的图像尝试代码管道 因此,我们遵循文档中的步骤 我们的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

我们想用ECR上已有的图像尝试代码管道

因此,我们遵循文档中的步骤

我们的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 
我们想知道我们是否遗漏了什么,我们从这里开始遵循以下步骤:


有什么建议吗?

有两种可能:-

一个是您没有在为ec2实例创建的角色中添加ecr和ecs,或者您使用的是elastic beanstalk。首先核实

否则,请研究第二种可能性:- 在阶段中使用以下命令:-

阶段: 安装: 命令: -nohup/usr/local/bin/dockerd——主机=unix:///var/run/docker.sock --主人=tcp://127.0.0.1:2375 --存储驱动程序=overlay2& -超时15 sh-c“直到docker信息;执行回显;睡眠1;完成”

有关更多详细信息,请使用此链接

查找错误

无法连接到位于的Docker守护程序unix:///var/run/docker.sock. 是 docker守护进程正在运行吗

我发现这很有帮助:

特别是第5.d点

  • 按照直接运行代码构建中的步骤创建构建项目、运行构建并查看构建信息

    如果使用控制台创建项目:

    a。对于操作系统,选择Ubuntu

    b。对于运行时,选择标准

    c。对于图像,选择aws/codebuild/standard:4.0

    d。由于使用此生成项目生成Docker映像,请选择Privileged


  • 我遇到了和您一样的问题,我通过以下方式解决了这个问题:尝试使用代码构建,然后使用IAM角色
    AmazonEC2ContainerRegistryFullAccess
    角色,现在单击该代码生成的“编辑”,选择“环境”,然后单击
    允许AWS CodeBuild修改此服务角色,以便可用于此构建项目
    。现在再试一次


    干杯

    您是否选择了aws/codebuild/docker:17.09.0作为您在codebuild项目中的版本?似乎docker不可用,所以我猜这就是您错过的。@BrettGreen实际上aws更改了该部分,它不再显示docker,这就是为什么在buildspec.yml上我们需要放置docker:18,这似乎是错误:(实际上,这里有一个复选框,上面写着“如果您想构建Docker映像或希望构建获得提升的权限,请启用此标志”。可能比手动安装dockerKnow效果更好,但我遇到了问题,我的文件buildspec.yml,printf'[{“name”:“Stepper:3”,“imageUri”:“%s”}]“$REPOSITORY\u URI:$IMAGE\u TAG>imagedefinitions.json。但是当代码管道运行时,它显示:AWS ECS容器Stepper:3不存在imagedefinitions.json文件中的“名称”需要与任务定义中的容器名称完全匹配……我假设在某个时候您正在更新ECS服务或其他内容,并猜测它的任务定义初始化容器\u定义[0]。名称与Stepper:3不匹配…请确保它与目标服务匹配。