Skip to content

Instantly share code, notes, and snippets.

@KyleTryon
Created June 12, 2019 14:29
Show Gist options
  • Save KyleTryon/2c448412f8d7e53723f3f8977aff4e3f to your computer and use it in GitHub Desktop.
Save KyleTryon/2c448412f8d7e53723f3f8977aff4e3f to your computer and use it in GitHub Desktop.
# Orb 'circleci/aws-ecr@6.0.0' resolved to 'circleci/aws-ecr@6.0.0'
version: 2
jobs:
aws-ecr/build-and-push-image:
machine: true
steps:
- run:
command: echo TAG=$(echo $CIRCLE_BRANCH$CIRCLE_TAG | sed 's@/@-@') >> $BASH_ENV
- run:
command: echo ACCOUNT_URL="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
>> $BASH_ENV
- checkout
- run:
name: Install AWS CLI
command: |
export PIP=$(which pip pip3 | head -1)
if [[ -n $PIP ]]; then
if which sudo > /dev/null; then
sudo $PIP install awscli --upgrade
else
# This installs the AWS CLI to ~/.local/bin. Make sure that ~/.local/bin is in your $PATH.
$PIP install aws --upgrade --user
fi
elif [[ $(which unzip curl | wc -l) -eq 2 ]]; then
cd
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
if which sudo > /dev/null; then
sudo ~/awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
else
# This installs the AWS CLI to the default location (~/.local/lib/aws) and create a symbolic link (symlink) at ~/bin/aws. Make sure that ~/bin is in your $PATH.
awscli-bundle/install -b ~/bin/aws
fi
rm -rf awscli-bundle*
cd -
else
echo "Unable to install AWS CLI. Please install pip."
exit 1
fi
- run:
name: Configure AWS Access Key ID
command: |
aws configure set aws_access_key_id \
$AWS_ACCESS_KEY_ID \
--profile default
- run:
name: Configure AWS Secret Access Key
command: |
aws configure set aws_secret_access_key \
$AWS_SECRET_ACCESS_KEY \
--profile default
- run:
name: Configure AWS default region
command: |
aws configure set region $AWS_DEFAULT_REGION \
--profile default
- run:
command: |
# aws ecr get-login returns a login command w/ a temp token
LOGIN_COMMAND=$(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
# save it to an env var & use that env var to login
$LOGIN_COMMAND
name: Log into Amazon ECR
- run:
command: |
docker build \
\
-f Dockerfile \
-t $ACCOUNT_URL/ECR_REPOSITORY:TAG \
.
name: Build docker image
- run:
command: docker push $ACCOUNT_URL/ECR_REPOSITORY:TAG
name: Push image to Amazon ECR
workflows:
version: 2
build-and-deploy:
jobs:
- aws-ecr/build-and-push-image:
filters:
tags:
only: /.*/
context: org-global
# Original config.yml file:
# version: 2.1
# orbs:
# aws-ecr: circleci/aws-ecr@6.0.0
# # aws-ecs: circleci/aws-ecs@0.0.8
# workflows:
# version: 2
# build-and-deploy:
# jobs:
# - aws-ecr/build-and-push-image:
# context: org-global
# filters:
# tags:
# only: /.*/
# account-url: ACCOUNT_URL
# repo: ECR_REPOSITORY
# region: AWS_DEFAULT_REGION
# tag: TAG
# pre-steps:
# - run:
# command: echo TAG=$(echo $CIRCLE_BRANCH$CIRCLE_TAG | sed 's@/@-@') >> $BASH_ENV
# - run:
# command: echo ACCOUNT_URL=\"${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com\" >> $BASH_ENV
# # - aws-ecs/deploy-service-update:
# # requires:
# # - aws-ecr/build_and_push_image
# # cluster-name: \"conceptho\"
# # container-image-name-updates: \"container=${ECR_REPOSITORY}-service,tag=${TAG}\"
# # family: \"${ECR_REPOSITORY}-qa\"
# # before: |
# # echo TAG=$(echo $CIRCLE_BRANCH$CIRCLE_TAG | sed 's@/@-@') >> $BASH_ENV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment