From 289a8ea74e589456cb041abbc80848a3bef0a329 Mon Sep 17 00:00:00 2001 From: Erik Osterman Date: Thu, 17 Jan 2019 20:57:56 -0800 Subject: [PATCH] Add buildspec (#17) --- README.md | 34 ++++++++++++++++++++++++++++++++++ README.yaml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/README.md b/README.md index 7ab516a..f134e81 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,40 @@ module "ecs_release_pipeline" { Complete usage can be seen in the [terraform-aws-ecs-web-app](https://github.com/cloudposse/terraform-aws-ecs-web-app/blob/master/main.tf) module. +## Example Buildspec + +Here's an example `buildspec.yaml`. Stick this in the root of your project repository. + +```yaml +version: 0.2 +phases: + pre_build: + commands: + - echo Logging in to Amazon ECR... + - aws --version + - eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) + - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME + - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) + build: + commands: + - echo Build started on `date` + - echo Building the Docker image... + - REPO_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME + - docker pull $REPO_URI:latest || true + - docker build --cache-from $REPO_URI:latest --tag $REPO_URI:latest --tag $REPO_URI:$IMAGE_TAG . + post_build: + commands: + - echo Build completed on `date` + - echo Pushing the Docker images... + - REPO_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME + - docker push $REPO_URI:latest + - docker push $REPO_URI:$IMAGE_TAG + - echo Writing image definitions file... + - printf '[{"name":"%s","imageUri":"%s"}]' "$CONTAINER_NAME" "$REPO_URI:$IMAGE_TAG" | tee imagedefinitions.json +artifacts: + files: imagedefinitions.json +``` + ## Makefile Targets diff --git a/README.yaml b/README.yaml index b48cb1c..333ac8c 100644 --- a/README.yaml +++ b/README.yaml @@ -106,6 +106,40 @@ usage: |- # Example usage examples: |- Complete usage can be seen in the [terraform-aws-ecs-web-app](https://github.com/cloudposse/terraform-aws-ecs-web-app/blob/master/main.tf) module. + + ## Example Buildspec + + Here's an example `buildspec.yaml`. Stick this in the root of your project repository. + + ```yaml + version: 0.2 + phases: + pre_build: + commands: + - echo Logging in to Amazon ECR... + - aws --version + - eval $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) + - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME + - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) + build: + commands: + - echo Build started on `date` + - echo Building the Docker image... + - REPO_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME + - docker pull $REPO_URI:latest || true + - docker build --cache-from $REPO_URI:latest --tag $REPO_URI:latest --tag $REPO_URI:$IMAGE_TAG . + post_build: + commands: + - echo Build completed on `date` + - echo Pushing the Docker images... + - REPO_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$IMAGE_REPO_NAME + - docker push $REPO_URI:latest + - docker push $REPO_URI:$IMAGE_TAG + - echo Writing image definitions file... + - printf '[{"name":"%s","imageUri":"%s"}]' "$CONTAINER_NAME" "$REPO_URI:$IMAGE_TAG" | tee imagedefinitions.json + artifacts: + files: imagedefinitions.json + ``` # How to get started quickly #quickstart: |-