Created
March 23, 2020 06:16
-
-
Save eramuk/256e3f03913d3acedb499e06229f3585 to your computer and use it in GitHub Desktop.
docker build push to ecr from github
This file contains 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
#!/bin/bash | |
set -eu -o pipefail | |
if [[ $# -ne 1 ]]; then | |
echo "invalid argument" | |
exit 1 | |
fi | |
REPO=$1 | |
repo_user=$(echo $REPO | cut -d '/' -f 1) | |
repo_name=$(echo $REPO | cut -d '/' -f 2) | |
LOCAL_REPO=${LOCAL_REPO:-${HOME}/src/${repo_name}} | |
account_id=$(aws sts get-caller-identity --query 'Account' --output text) | |
region=$(aws configure get region) | |
aws ecr get-login-password | docker login -u AWS --password-stdin https://${account_id}.dkr.ecr.${region}.amazonaws.com > /dev/null | |
repository_uri=$(aws ecr describe-repositories --repository-names $repo_name --query 'repositories[].repositoryUri' --output text) | |
git clone git@github.com:${REPO} ${LOCAL_REPO} 2>/dev/null || (cd ${LOCAL_REPO} && git pull) | |
cd ${LOCAL_REPO} | |
image_tag=$(git rev-parse --short HEAD) | |
docker build -t ${repository_uri}:${image_tag} . | |
docker push $repository_uri:${image_tag} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment