version: 0.2 phases: pre_build: commands: - echo Logging in to Amazon ECR... - aws --version - docker version - echo $AWS_REGION - aws configure list - aws --debug ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin 825765383758.dkr.ecr.$AWS_REGION.amazonaws.com build: commands: - echo Build started on `date` - echo $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $APP_ENV - echo Building the Docker image... - | docker build \ -t $CONTAINER_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION \ . \ --build-arg AWS_ACCESS_KEY_ID \ --build-arg AWS_SECRET_ACCESS_KEY \ --build-arg APP_ENV - docker tag $CONTAINER_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION 825765383758.dkr.ecr.$AWS_REGION.amazonaws.com/$CONTAINER_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION post_build: commands: - echo Pushing the Docker image to Amazon ECR... - | ( docker push 825765383758.dkr.ecr.$AWS_REGION.amazonaws.com/$CONTAINER_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION || true & wait ) - echo Writing image tag... - echo $CODEBUILD_RESOLVED_SOURCE_VERSION > image-tag.txt # - cp appspec.yml appspec.yml artifacts: files: - image-tag.txt - docker-compose.yaml - appspec.yml - deploy.sh discard-paths: yes