aws-codebuild-docker-images
aws-codebuild-docker-images copied to clipboard
CodeBuild push to ECR doesn't work
Original issue: https://github.com/aws/aws-cli/issues/7231 by @AMB-Informacio
Describe the bug
It's the same behaviour as the described in:
https://github.com/aws/aws-cli/issues/7102
A buildspec.yml file describes to build a docker image and to push it to ECR but the Docker push don't work, retrying to do that and finally fails.
There was answered as a problem with the artifacts and the image-definitions.json file. But that's happening because the previous step "docker push" fails unexpectedly, and that is the real problem.
Expected Behavior
Docker image pushed to ECR
Current Behavior
For any reason docker push is retrying and then an EOF appears.
[Container] 2022/08/30 06:32:01 Running command docker push $REPOSITORY_URI:latest
--
723 | The push refers to repository [XXXXXXXXXX.dkr.ecr.eu-west-1.amazonaws.com/gitoccupacy-backend-service]
724 | 6a37c076ad0a: Preparing
725 | 838351f683ff: Preparing
726 | f00576e66739: Preparing
727 | 845237c43dbf: Preparing
[...]
1069 | 845237c43dbf: Retrying in 1 second
1070 | 94a688c21a1d: Retrying in 1 second
1071 | EOF
1072 |
1073 | [Container] 2022/08/30 06:32:51 Command did not exit successfully docker push $REPOSITORY_URI:latest exit status 1
1074 | [Container] 2022/08/30 06:32:51 Phase complete: POST_BUILD State: FAILED
Reproduction Steps
Commit or retry to build project with this buildspec.yml file:
version: 0.2
env:
secrets-manager:
DOCKERHUB_LOGIN: "dockerhub:login"
DOCKERHUB_PASSWORD: "dockerhub:password"
batch:
fast-fail: false
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- REPOSITORY_DOMAIN_NAME=$(echo $AWS_ACCOUNT_ID'.dkr.ecr.'$AWS_DEFAULT_REGION'.amazonaws.com')
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $REPOSITORY_DOMAIN_NAME
- REPOSITORY_URI=$(echo $REPOSITORY_DOMAIN_NAME'/'$IMAGE_REPO_NAME)
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=latest}
- echo Logging in to DockerHub
- docker login --username $DOCKERHUB_LOGIN --password $DOCKERHUB_PASSWORD
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build --target release --file './backend-service/Dockerfile' -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":"backend","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json
Possible Solution
No response
Additional Information/Context
No response
CLI version used
code build version: 0.2
Environment details (OS name and version, etc.)
code build version: 0.2
Thanks @tim-finnigan !
did anyone find the fix?