Skip to content

Instantly share code, notes, and snippets.

@smiller171
Created March 18, 2018 19:42
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 smiller171/67da108927fa08719ce9960a87abe73c to your computer and use it in GitHub Desktop.
Save smiller171/67da108927fa08719ce9960a87abe73c to your computer and use it in GitHub Desktop.
Dockerhub fork commit hook
#!/bin/bash
list=$(curl -s https://hub.docker.com/v2/repositories/library/node/tags/?page_size=500 | jq -r '.results|.[]|.name' | grep -v onbuild | grep -v latest |
sort)
branch=$(git rev-parse --abbrev-ref HEAD)
create_branch() {
tag=$1
branch=$2
if git rev-parse --verify ${tag} > /dev/null
then
echo "branch ${tag} exists"
else
git checkout "${branch}" > /dev/null
git checkout -B ${tag}
sed -i "" "s/FROM node/FROM node:${tag}/g" Dockerfile
git commit --no-verify -am 'update tag'
fi
}
export -f create_branch
echo $list | xargs -P 1 -n 1 -I {} bash -c 'create_branch "$@"' _ {} "${branch}"
git checkout "${branch}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment