@@ -121,24 +121,20 @@ done
121121# ----------------------------------------------------------------------
122122# The program itself
123123
124- if [ " $( uname) " != " Linux" ]; then
125- if [ " $( uname) " = " Darwin" ]; then
126- APP=" /Applications/Docker.app"
127- CMD=" open -a"
128- else
129- die " This script does not have support for your architecture ($( uname) ); sorry :-("
130- fi
131- if [ -n " $( type -p docker-machine) " ]; then
132- machine=$( type -p docker-machine)
133- else
134- die " Could not find boot2docker or docker-machine -- you need to set one of those before running this script."
135- fi
124+ [ -f /proc/1/cgroups ] && grep ' docker' /proc/1/cgroups && die " It looks like you're inside docker already ..."
125+
126+ if [ " $( uname) " = " Darwin" ]; then
127+ APP=" /Applications/Docker.app"
128+ CMD=" open -a"
129+ elif [ " $( uname) " = " Linux" ]; then
130+ echo " Running on Linux."
136131else
137- die " Didn't expect to run this script on Linux -- are you inside docker? "
132+ die " This script does not have support for your architecture ( $( uname ) ); sorry :-( "
138133fi
139134
140-
141- if [ -e " $APP " ]; then
135+ if [ " $( uname) " = " Linux" ]; then
136+ echo " Not trying to start a virtual docker machine on Linux"
137+ elif [ -e " $APP " ]; then
142138 info=$( docker info 2>&1 || true)
143139 if ! docker info 1> /dev/null 2>&1 ; then
144140 echo -e " The docker VM doesn't seem to be running; docker info gave:\n $info "
@@ -183,57 +179,60 @@ else
183179 fi
184180fi
185181
186- echo " "
187- echo " Starting a docker container for '$TAG '."
188-
189- docker ps | grep -q $REPO :$TAG && die \
190- " It seems that another docker container is already running the
191- image '$REPO :$TAG '. Continuing here can cause various problems,
192- such as changes from within the container being saved from different
193- containers to the same image, overwriting earlier changes, and
194- multiple containers trying to use the same database files. Better
195- to bail out here. Quitting."
196-
197- if [ -n " $DOWNLOAD " ]; then
198- (
199- cd $( dirname $MYSQLDIR )
200- wget -N $DBURL && tar xjf ietf_utf8.bin.tar.bz2 && chmod -R go+rwX mysql
201- )
202- [ -d " $MYSQLDIR " ] || die " The download seems to have failed; still no $MYSQLDIR . Giving up."
182+
183+ image=$( docker ps | grep " $REPO :$TAG " | awk ' { print $1 }' )
184+ if [ " $image " ]; then
185+ if [ " $* " ]; then
186+ echo " Running 'cd ~/${parent# $HOME / } ; $* '"
187+ docker exec -u $WHO $image bash -c " cd ~/${parent# $HOME / } ; $* "
188+ else
189+ docker exec -u $WHO -ti $image bash
190+ fi
203191else
204- [ -d " $MYSQLDIR " ] || die " Expected $MYSQLDIR to exist, but it\ndidn't. Use '$program -d' to download and unpack the database."
205- fi
192+ echo " "
193+ echo " Starting a docker container for '$TAG '."
194+
195+ if [ -n " $DOWNLOAD " ]; then
196+ (
197+ cd $( dirname $MYSQLDIR )
198+ wget -N $DBURL && tar xjf ietf_utf8.bin.tar.bz2 && chmod -R go+rwX mysql
199+ )
200+ [ -d " $MYSQLDIR " ] || die " The download seems to have failed; still no $MYSQLDIR . Giving up."
201+ else
202+ [ -d " $MYSQLDIR " ] || die " Expected $MYSQLDIR to exist, but it\ndidn't. Use '$program -d' to download and unpack the database."
203+ fi
206204
207- if ! docker images $REPO | grep -q $TAG ; then
208- echo " Fetching docker image '$REPO :$TAG '"
209- if ! docker pull $REPO :$TAG ; then
210- docker pull $REPO :latest || die " Failed to pull down the '$REPO :latest' docker image"
211- id=$( docker images $REPO | grep latest | awk ' {print $3}' )
212- echo " Tagging $REPO :latest as $REPO :$TAG for use as environment for this branch."
213- docker tag $id $REPO :$TAG
205+ if ! docker images $REPO | grep -q $TAG ; then
206+ echo " Fetching docker image '$REPO :$TAG '"
207+ if ! docker pull $REPO :$TAG ; then
208+ docker pull $REPO :latest || die " Failed to pull down the '$REPO :latest' docker image"
209+ id=$( docker images $REPO | grep latest | awk ' {print $3}' )
210+ echo " Tagging $REPO :latest as $REPO :$TAG for use as environment for this branch."
211+ docker tag $id $REPO :$TAG
212+ fi
214213 fi
215- fi
216214
217- echo -e " \nThe web interface for 'runserver' should appear on $URL \n"
218- if [ -z " $MYSQLDIR " ]; then
219- docker run -ti -p $PORT :8000 -v $HOME :/home/$WHO \
220- -e USER=$WHO -e DATADIR=${parent# $HOME / } /data -e CWD=${PWD# $HOME / } \
221- -e TAG=$TAG -e FILEDIR=${FILEDIR# $HOME } \
222- $REPO :$TAG " $@ "
223- else
224- docker run -ti -p $PORT :8000 -v $HOME :/home/$WHO -v $MYSQLDIR :/var/lib/mysql\
225- -e USER=$WHO -e DATADIR=${parent# $HOME / } /data -e CWD=${PWD# $HOME / } \
226- -e TAG=$TAG -e FILEDIR=${FILEDIR# $HOME } \
227- $REPO :$TAG " $@ "
228- fi
215+ echo -e " \nThe web interface for 'runserver' should appear on $URL \n"
216+ if [ -z " $MYSQLDIR " ]; then
217+ docker run -ti -p $PORT :8000 -v $HOME :/home/$WHO \
218+ -e USER=$WHO -e DATADIR=${parent# $HOME / } /data -e CWD=${PWD# $HOME / } \
219+ -e TAG=$TAG -e FILEDIR=${FILEDIR# $HOME } \
220+ $REPO :$TAG " $@ "
221+ else
222+ docker run -ti -p $PORT :8000 -v $HOME :/home/$WHO -v $MYSQLDIR :/var/lib/mysql\
223+ -e USER=$WHO -e DATADIR=${parent# $HOME / } /data -e CWD=${PWD# $HOME / } \
224+ -e TAG=$TAG -e FILEDIR=${FILEDIR# $HOME } \
225+ $REPO :$TAG " $@ "
226+ fi
229227
230- echo " "
231- echo " Committing changes in the container to an image:"
232- latest=$( docker ps -lq)
233- docker commit $latest $REPO :$TAG
228+ echo " "
229+ echo " Committing changes in the container to an image:"
230+ latest=$( docker ps -lq)
231+ docker commit $latest $REPO :$TAG
234232
235- echo " "
236- echo " Cleaning up containers and images"
237- docker rm $latest
238- docker images -f dangling=true -q | xargs docker rmi -f
233+ echo " "
234+ echo " Cleaning up containers and images"
235+ docker rm $latest
236+ docker images -f dangling=true -q | xargs docker rmi -f
239237
238+ fi
0 commit comments