-
-
Save anurAupa/250b84e53c72d3a9293da36343277668 to your computer and use it in GitHub Desktop.
Sample of buildspec.yml for AWS CodeBuild that builds a Docker image from code and push it to ECR to be deployed via CodePipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change the following to your desired values: | |
# __ACCOUNT_NUMBER__ | |
# __ECR_REGION__ | |
# __ECR_REPOSITORY_NAME__ | |
# __ECS_CONTAINER_NAME__ | |
version: 0.2 | |
phases: | |
install: | |
runtime-versions: | |
docker: 18 | |
pre_build: | |
commands: | |
- echo Logging in to Amazon ECR... | |
- aws --version | |
- $(aws ecr get-login --region __ECR_REGION__ --no-include-email) | |
- REPOSITORY_URI=__ACCOUNT_NUMBER__.dkr.ecr.__ECR_REGION__.amazonaws.com/__ECR_REPOSITORY_NAME__ | |
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) | |
- IMAGE_TAG=${COMMIT_HASH:=latest} | |
build: | |
commands: | |
- echo Build started on `date` | |
- echo Building the Docker image... | |
- 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... | |
- printf '[{"name”:"__ECS_CONTAINER_NAME__","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json | |
artifacts: | |
files: imagedefinitions.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment