Ulises
Ulises

Reputation: 416

AWS ECS CodePipeline build error REPOSITORY_URI

we wanna try CodePipeline with a image that we already have on ECR.

So we follow the steps on the documentation.

We have buildspec.yml like this:

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

We created a new pipeline flow, but when we push some changes we get this log:

[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 

We wanna know if we are missing something, we follow some steps from here:

https://aws.amazon.com/es/blogs/devops/build-a-continuous-delivery-pipeline-for-your-container-images-with-amazon-ecr-as-source/

Any advice?

Upvotes: 0

Views: 8258

Answers (5)

Joshua Ochia
Joshua Ochia

Reputation: 131

I know this is old but if you already have a permission in your Codebuild please note that both permission on each side are needed as one of AWS staff said. You basically need permission to both ERC/Codebuild.

Please refer to this issue

Upvotes: 0

Harsh Upparwal
Harsh Upparwal

Reputation: 33

I ran into similar error. The fix is, this build project needs to build a Docker image therefore set Privilege Mode to true.

Privileged mode grants a build project's Docker container access.

Upvotes: 2

Sajjan Mishra
Sajjan Mishra

Reputation: 85

I have had the same problem as you and the way I fixed it was by following: try going to CodeBuild and then to its IAM Role. AmazonEC2ContainerRegistryFullAccess role and now click on 'Edit' for that code build and select 'Environment' and click on Allow AWS CodeBuild to modify this service role so it can be used with this building project. Now try again.

Cheers

Upvotes: 0

bravogolfgolf
bravogolfgolf

Reputation: 377

For error

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I found this helpful: https://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html

Specifically point 5.d.

  1. Follow the steps in Run CodeBuild directly to create a build project, run the build, and view build information.

    If you use the console to create your project:

    a. For Operating system, choose Ubuntu.

    b. For Runtime, choose Standard.

    c. For Image, choose aws/codebuild/standard:4.0.

    d. Because you use this build project to build a Docker image, select Privileged.

Upvotes: 0

AVDHUT NALAWADE
AVDHUT NALAWADE

Reputation: 1

There will be two possibilities:-

one is that you didn't add ecr and ecs in your roles which you created for ec2 instance or if you are using elastic beanstalk. first verify that

otherwise look into this second possibility:- Use following commands in your phases:-

phases: install: commands: - nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2& - timeout 15 sh -c "until docker info; do echo .; sleep 1; done"

for more details use this link https://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker-custom-image.html#sample-docker-custom-image-files

https://docs.aws.amazon.com/codebuild/latest/userguide/troubleshooting.html#troubleshooting-cannot-connect-to-docker-daemon

Upvotes: 0

Related Questions