Forked from tvalletta/aws-codebuild-cross-account-image-push.yml
Created
June 27, 2017 15:13
-
-
Save pjaol/ba9673d9f96e7759c721b1472cd4734d 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
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment