Skip to content

Instantly share code, notes, and snippets.

@tvalletta
Created February 17, 2017 15:14
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save tvalletta/451e7a289a53f1e52ca52de6bc35d6b2 to your computer and use it in GitHub Desktop.
Save tvalletta/451e7a289a53f1e52ca52de6bc35d6b2 to your computer and use it in GitHub Desktop.
AWS CodeBuild buildspec.yml example for building a docker image and pushing it to a AWS ECS docker repo in another AWS account
version: 0.1
# REQUIRED ENVIRONMENT VARIABLES
# AWS_KEY - AWS Access Key ID
# AWS_SEC - AWS Secret Access Key
# AWS_REG - AWS Default Region (e.g. us-west-2)
# AWS_OUT - AWS Output Format (e.g. json)
# AWS_PROF - AWS Profile name (e.g. central-account)
# IMAGE_REPO_NAME - Name of the image repo (e.g. my-app)
# IMAGE_TAG - Tag for the image (e.g. latest)
# AWS_ACCOUNT_ID - Remote AWS account id (e.g. 555555555555)
phases:
pre_build:
commands:
- printf "${AWS_KEY}\n${AWS_SEC}\n${AWS_REG}\n${AWS_OUT}\n" | aws configure --profile ${AWS_PROF}
- $(aws ecr get-login --profile ${AWS_PROF})
build:
commands:
- docker build -t $IMAGE_REPO_NAME .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REG.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
post_build:
commands:
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REG.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
@skarnecki
Copy link

can update this gist? you should use aws iam role instead of passing api keys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment