version: 0.2 env: secrets-manager: DOCKERHUB_USERNAME: hub.docker.com:username DOCKERHUB_PASS: hub.docker.com:password phases: pre_build: commands: - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME - echo Logging in to Docker HUB to avoid rate limit - echo "$DOCKERHUB_PASS" | docker login --username $DOCKERHUB_USERNAME --password-stdin - echo Logging in to Amazon ECR - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com build: commands: - echo Build started on `date` - echo Building the Docker image - docker build -f docker/api/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 latest, $IMAGE_TAG - docker push $REPOSITORY_URI:latest - docker push $REPOSITORY_URI:$IMAGE_TAG - sed -i 's//'$AWS_ACCOUNT_ID'/g' deployments/api/taskdef.json - sed -i 's//'$AWS_ACCOUNT_ID'\.dkr\.ecr\.'$AWS_DEFAULT_REGION'\.amazonaws.com\/'$IMAGE_REPO_NAME'\:'$IMAGE_TAG'/g' deployments/api/taskdef.json artifacts: files: - imageDetail.json - deployments/api/appspec.yml - deployments/api/taskdef.json