Created
March 12, 2014 11:19
-
-
Save bakins/9504964 to your computer and use it in GitHub Desktop.
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 | |
VERSION="" | |
NAME="" | |
DIR="" | |
while getopts "v:n" opt; do | |
case $opt in | |
v) | |
VERSION=$OPTARG | |
;; | |
n) | |
NAME=$OPTARG | |
;; | |
d) | |
DIR=$OPTARG | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit | |
;; | |
esac | |
done | |
shift $(( OPTIND - 1 )) | |
DIR=$1 | |
if [ -z "$DIR" ]; then | |
echo "dir is required" >&2 | |
exit -2 | |
fi | |
cd $DIR | |
if [ ! -f Dockerfile ]; then | |
echo "no Dockerfile" >&2 | |
exit -3 | |
fi | |
if [ -z "$VERSION" ]; then | |
VERSION=$(grep -E "^#\s*VERSION:" Dockerfile | cut -d ':' -f 2 | tr -d ' ') | |
if [ -z "$VERSION" ]; then | |
echo "version is required" >&2 | |
exit -2 | |
fi | |
fi | |
if [ -z "$NAME" ]; then | |
NAME=$(grep -E "^#\s*NAME:" Dockerfile | cut -d ':' -f 2 | tr -d ' ') | |
if [ -z "$NAME" ]; then | |
NAME=$(basename $DIR) | |
fi | |
fi | |
docker build --rm -t $NAME:$VERSION $DIR | |
docker inspect $NAME:$VERSION > $NAME-$VERSION.json | |
# this is a hack as you can only export containers, not images | |
# save does not do what you would expect it to do | |
ID=$(docker run -d $NAME:$VERSION "sleep 1") | |
sleep 3 | |
docker export $ID | gzip -9 > $NAME-$VERSION.tar.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment