Created
June 30, 2014 10:27
-
-
Save nikicat/80d68c5b19a5e088bc2a to your computer and use it in GitHub Desktop.
shell script to automate Docker image rebuilding
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 -e | |
dirname=${PWD##*/} | |
if (echo $dirname | grep docker); then | |
dirname=${dirname##docker-} | |
fi | |
registry=${DOCKER_REGISTRY:=registry.tst.ape.yandex.net:5000} | |
namespace=${DOCKER_NAMESPACE:=nikicat} | |
to=$registry/$namespace/$dirname | |
from=`grep '^FROM ' Dockerfile | sed -r "s|^FROM *(.*)$|\1|"` | |
if (echo $from | grep "^yandex/"); then | |
if [ "$1" = "-l" ]; then | |
from=`echo "$from" | sed -r "s|^yandex/|$namespace/|"` | |
fi | |
from="$registry/$from" | |
fi | |
docker-build.sh $from $to | |
docker push $to |
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/sh | |
from="$1" | |
shift | |
to="$1" | |
shift | |
if [ -z "$from" ] || [ -z "$to" ]; then | |
echo "Usage: $0 <from> <to>" | |
exit 1 | |
fi | |
function restore_dockerfile() { | |
mv Dockerfile{.orig,} | |
} | |
cp Dockerfile{,.orig} | |
trap restore_dockerfile EXIT TERM INT | |
sed -ri "s|^FROM (.*)$|FROM $from|" Dockerfile | |
docker build -t $to . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment