Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save addicola/05f1177920d449d703a42bc009612ee4 to your computer and use it in GitHub Desktop.

Select an option

Save addicola/05f1177920d449d703a42bc009612ee4 to your computer and use it in GitHub Desktop.

Revisions

  1. @tvalletta tvalletta created this gist Feb 17, 2017.
    24 changes: 24 additions & 0 deletions aws-codebuild-cross-account-image-push.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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