Skip to content

Instantly share code, notes, and snippets.

@jlis
Created May 15, 2018 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlis/e00465cbbf3bde3e2dc6f06ffa9fd452 to your computer and use it in GitHub Desktop.
Save jlis/e00465cbbf3bde3e2dc6f06ffa9fd452 to your computer and use it in GitHub Desktop.
AWS CodeBuild Deployment via ECS/ECR
version: 0.2
phases:
pre_build:
commands:
- aws --version
- echo Logging in to Amazon ECR...
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- if [ -z "$IMAGE_TAG" ]; then IMAGE_TAG=latest; fi
- if [ -n "$CODEBUILD_RESOLVED_SOURCE_VERSION" ]; then IMAGE_TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)"; fi
- echo Using image tag "$IMAGE_TAG"
- IMAGE_URI="$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME"
- echo Building image...
- docker build -t $IMAGE_URI:latest .
- echo Tagging image with tag "$IMAGE_TAG"...
- docker tag $IMAGE_URI:latest $IMAGE_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image to uri "$IMAGE_URI"...
- docker push $IMAGE_URI:latest
- docker push $IMAGE_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"%s","imageUri":"%s"}]' "$IMAGE_REPO_NAME" "$IMAGE_URI:$IMAGE_TAG" > images.json
artifacts:
files:
- images.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment