@@ -6,6 +6,7 @@ progdir=${0%/*}
66if [ " $progdir " = " $program " ]; then progdir=" ." ; fi
77if [ " $progdir " = " ." ]; then progdir=" $PWD " ; fi
88parent=$( dirname $progdir )
9+ if [ " $parent " = " ." ]; then parent=" $PWD " ; fi
910
1011# ----------------------------------------------------------------------
1112function usage() {
@@ -73,10 +74,12 @@ trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)";
7374# Option parsing
7475
7576# Options
76- shortopts=dhi:vVu:m :
77- longopts=download-data,help,ietfdb-url=,verbose,version,user=,mysqldata =,
77+ shortopts=dhi:m:r:t:vVu :
78+ longopts=download-data,help,ietfdb-url=,mysqldata=,docker-repo=,tag=, verbose,version,user=,
7879
7980# Default values
81+ TAG=$( basename $( svn info --show-item url $parent ) )
82+ REPO=" levkowetz/datatracker"
8083
8184if [ " $( uname) " = " Linux" ]; then
8285 args=$( getopt -o " $shortopts " --long " $longopts " -n ' $program' -- $SV " $@ " )
@@ -95,9 +98,11 @@ while true ; do
9598 case " $1 " in
9699 -d| --download-data) DOWNLOAD=1;; # Download and set up the database files
97100 -h| --help) usage; exit ;; # Show this help, then exit
98- -i| --ietfdb-url) URL=$2 ; shift ;; # Use an alternative database tarball URL
101+ -i| --ietfdb-url) URL=$2 ; shift ;; # Use an alternative database tarball URL
99102 -m| --mysqldir) MYSQLDIR=$2 ; shift ;; # Set the desired location for MySQL's database files
100- -u| --user) WHO=$2 ; shift ;; # Run container as someone else than $USER
103+ -r| --docker-repo) REPO=$2 ; shift ;; # Use the given docker repository, instead of the default
104+ -t| --tag) TAG=$2 ; shift ;; # Use this docker image tag, instead of the svn branch name
105+ -u| --user) WHO=$2 ; shift ;; # Run the container as the specified user
101106 -v| --verbose) VERBOSE=1;; # Be more talkative
102107 -V| --version) version; exit ;; # Show program version, then exit
103108 --) shift ; break ;;
@@ -109,9 +114,39 @@ done
109114# ----------------------------------------------------------------------
110115# The program itself
111116
112- docker ps | grep -q levkowetz/datatracker:latest && die \
117+
118+ if [ " $( uname) " != " Linux" ]; then
119+ if [ -n " $( type -p boot2docker) " ]; then
120+ machine=$( type -p boot2docker)
121+ up=up
122+ env=shellinit
123+ elif [ -n " $( type -p docker-machine) " ]; then
124+ machine=$( type -p docker-machine)
125+ up=start
126+ env=" env default"
127+ else
128+ die " Could not find boot2docker or docker-machine -- you need to set one of those before running this script."
129+ fi
130+ fi
131+
132+ if [ $( $machine status) != " running" ]; then
133+ echo " The docker VM doesn't seem to be running; will attempt to start it by doing '$$ $machine $up ':"
134+ $machine $up || die " Failed taking up the Docker VM"
135+ fi
136+
137+
138+ if [ ! -f ~ /.docker-info ]; then
139+ $machine $env 2> /dev/null | grep DOCKER_ > ~ /.docker-info
140+ fi
141+ . ~ /.docker-info
142+
143+
144+ echo " "
145+ echo " Starting a docker container for '$TAG ' ..."
146+
147+ docker ps | grep -q $REPO :$TAG && die \
113148" It seems that another docker container is already running the
114- image 'levkowetz/datatracker:latest ' -- but only one MySQL instance can bind
149+ image '$REPO : $TAG ' -- but only one MySQL instance can bind
115150to the database files at a time. Quitting."
116151
117152[ -n " $WHO " ] || WHO=$( whoami)
@@ -128,12 +163,24 @@ else
128163 [ -d " $MYSQLDIR " ] || die " Expected $MYSQLDIR to exist, but it\ndidn't. Use '$program -d' to download and unpack the database."
129164fi
130165
131- docker run -ti -p 8000:8000 -v $HOME :/home/$WHO -v $MYSQLDIR :/var/lib/mysql -e USER=$WHO -e DATADIR=${parent# $HOME / } /data levkowetz/datatracker:latest
166+ if ! docker images $REPO | grep -q $TAG ; then
167+ echo " Fetching a docker image for your docker container ..."
168+ if ! docker pull $REPO :$TAG ; then
169+ docker pull $REPO :latest || die " Failed to pull down the '$REPO :latest' docker image"
170+ id=$( docker images $REPO | grep latest | awk ' {print $3}' )
171+ echo " Tagging $REPO :latest as $REPO :$TAG for use as environment for this branch."
172+ docker tag $id $REPO :$TAG
173+ fi
174+ fi
175+
176+ docker run -ti -p 8000:8000 -v $HOME :/home/$WHO -v $MYSQLDIR :/var/lib/mysql -e USER=$WHO -e DATADIR=${parent# $HOME / } /data -e CWD=${PWD# $HOME / } $REPO :$TAG
132177
178+ echo " "
133179echo " Committing changes in the container to an image:"
134180latest=$( docker ps -lq)
135- docker commit $latest levkowetz/datatracker:latest
181+ docker commit $latest $REPO : $TAG
136182
183+ echo " "
137184echo " Cleaning up containers and images"
138185docker rm $latest
139186docker images -f dangling=true -q | xargs docker rmi -f
0 commit comments