Skip to content

Instantly share code, notes, and snippets.

@jmervine
Last active July 19, 2018 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmervine/b1835fa3bfcea9eaa9bf2521291f0615 to your computer and use it in GitHub Desktop.
Save jmervine/b1835fa3bfcea9eaa9bf2521291f0615 to your computer and use it in GitHub Desktop.
# Simply ensure repo and return url
aws ecr create-repository --repository-name $1 2>/dev/null || true
echo "$(aws ecr describe-repositories --repository-name $1 | jq '.repositories[0].repositoryUri')"
# .bashrc
# usage: exec helper -- emulates `set -x`
# $ __x "command"
function __x {
echo "+ $1"
$1
}
# usage: for first run
# $ ecr_init hello-world:latest
function ecr_init {
local image=$1
local repo=$(echo "${image}" | awk -F':' '{ print $1 }')
local tag=$(echo "${image}" | awk -F':' '{ print $2 }')
local repo_url=$(aws ecr create-repository --repository-name ${repo} | jq '.repository.repositoryUri')
# not sure if it's a good idea to include login here, but am for now, feel free to comment this out and run manually
eval $(aws ecr get-login --no-include-email)
__x "docker tag ${image} ${repo_url}:${tag}"
__x "docker push ${repo_url}:${tag}"
}
# usage: for updates
# $ ecr_push hello-world:latest
function ecr_push {
local image=$1
local tag=$(echo "${image}" | awk -F':' '{ print $2 }')
local repo_url=$(aws ecr describe-repositories | jq '.repositories[] | select('.repositoryName' == "$image") | .repositoryUri')
# not sure if it's a good idea to include login here, but am for now, feel free to comment this out and run manually
eval $(aws ecr get-login --no-include-email)
__x "docker tag ${image} ${repo_url}:${tag}"
__x "docker push ${repo_url}:${tag}"
}
# another, simpler way
# usage: for updates
# $ ecr_push hello-world:latest
function ecr {
local image=$1
local tag=$(echo "${image}" | awk -F':' '{ print $2 }')
aws ecr create-repository --repository-name ${image} 2>/dev/null || true
local repo_url=$(aws ecr describe-repositories --repository-name ${image} | jq '.repositories[0].repositoryUri')
# not sure if it's a good idea to include login here, but am for now, feel free to comment this out and run manually
eval $(aws ecr get-login --no-include-email)
__x "docker tag ${image} ${repo_url}:${tag}"
__x "docker push ${repo_url}:${tag}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment