Skip to content

Instantly share code, notes, and snippets.

@nikicat
Created June 30, 2014 10:27
Show Gist options
  • Save nikicat/80d68c5b19a5e088bc2a to your computer and use it in GitHub Desktop.
Save nikicat/80d68c5b19a5e088bc2a to your computer and use it in GitHub Desktop.
shell script to automate Docker image rebuilding
#!/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
#!/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