version: 0.2 phases: install: runtime-versions: docker: 18 python: 3.7 ruby: 2.6 pre_build: commands: - echo Logging in to Amazon ECR... - aws --version - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) - REPOSITORY_URI=$(aws ecr describe-repositories --repository-name modernization-workshop --query=repositories[0].repositoryUri --output=text) - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) - IMAGE_TAG=${COMMIT_HASH:=latest} - PWD=$(pwd) - echo Setting CodeCommit Credentials - git config --global credential.helper '!aws codecommit credential-helper $@' - git config --global credential.UseHttpPath true - git init - git remote add origin https://git-codecommit.us-west-2.amazonaws.com/v1/repos/modernization-workshop - git fetch - git checkout -f "$CODEBUILD_RESOLVED_SOURCE_VERSION" - git submodule init - git submodule update --recursive build: commands: - echo Build started on `date` - echo Building the Docker image... - cd app - 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... - echo Source DIR ${CODEBUILD_SRC_DIR} - printf '[{"name":"modernization-workshop","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > ${CODEBUILD_SRC_DIR}/imagedefinitions.json artifacts: files: imagedefinitions.json