Codebuild docker build stage failing

Viewed 35

My question is similar to this post where the Docker build stage is failing in Codebuild. However, the buildspec.yml file is a bit different since I'm including additional credentials. Here is my buildspec file:

version: 0.2


phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws --version
      - aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin XXXXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com
      - REPOSITORY_URI=XXXXXXXXXXXX.dkr.ecr.us-west-2.amazonaws.com/wp-api
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_TAG=build-$(echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}')
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...
      - docker build -t app:latest --secret id=awscredentials,src=$HOME/.aws/credentials .
      - docker tag app:latest REPOSITORY_URI:latest
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker images...
      - docker push $REPOSITORY_URI:latest

The error I get is:

[Container] 2022/07/11 18:37:24 Command did not exit successfully docker build -t app:latest --secret id=awscredentials,src=$HOME/.aws/credentials . exit status 1
[Container] 2022/07/11 18:37:24 Phase complete: BUILD State: FAILED
[Container] 2022/07/11 18:37:24 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -t app:latest --secret id=awscredentials,src=$HOME/.aws/credentials .. Reason: exit status 1
[Container] 2022/07/11 18:37:24 Entering phase POST_BUILD
[Container] 2022/07/11 18:37:24 Running command echo Build completed on `date`
Build completed on Mon Jul 11 18:37:24 UTC 2022

Am I missing something? Note that a more basic buildfile runs fine in the same project environment (one that does not have extra credentials or anything).

0 Answers
Related