Skip to content

Commit ff89873

Browse files
committed
Added support for Docker for Mac, which uses hypervisor virtualisation. The older VirtualBox based docker-machine should still work.
- Legacy-Id: 12389
1 parent b00824a commit ff89873

1 file changed

Lines changed: 49 additions & 20 deletions

File tree

docker/run

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ FILEDIR=$parent/../data/
8383
PORT=8000
8484
REPO="ietf/datatracker-environment"
8585
TAG=$(basename $(svn info $parent | grep ^URL | awk '{print $2}'))
86-
URL=https://www.ietf.org/lib/dt/sprint/ietf_utf8.bin.tar.bz2
86+
DBURL=https://www.ietf.org/lib/dt/sprint/ietf_utf8.bin.tar.bz2
8787
WHO=$(whoami)
8888

8989
if [ "$(uname)" = "Linux" ]; then
@@ -104,7 +104,7 @@ while true ; do
104104
-d| --download-data) DOWNLOAD=1;; # Download and set up the database files
105105
-h| --help) usage; exit;; # Show this help, then exit
106106
-f| --filedir) FILEDIR=$2; shift;; # Set the desired location of drafts, charters etc.
107-
-i| --ietfdb-url) URL=$2; shift;; # Use an alternative database tarball URL
107+
-i| --ietfdb-url) DBURL=$2; shift;; # Use an alternative database tarball URL
108108
-m| --mysqldir) MYSQLDIR=$2; shift;; # Set the desired location of MySQL's database files
109109
-p| --port) PORT=$2; shift;; # Bind the container's port 8000 to external port PORT
110110
-r| --docker-repo) REPO=$2; shift;; # Use the given docker repository, instead of the default
@@ -122,6 +122,12 @@ done
122122
# The program itself
123123

124124
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
125131
if [ -n "$(type -p docker-machine)" ]; then
126132
machine=$(type -p docker-machine)
127133
else
@@ -132,29 +138,51 @@ else
132138
fi
133139

134140

135-
if [ $($machine status default | tr "A-Z" "a-z" ) != "running" ]; then
136-
echo "The docker VM doesn't seem to be running; will attempt to start it by doing '\$ $machine start':"
137-
$machine start || die "Failed taking up the Docker VM"
138-
fi
141+
if [ -e "$APP" ]; then
142+
info=$(docker info 2>&1 || true)
143+
if ! docker info 1> /dev/null 2>&1; then
144+
echo -e "The docker VM doesn't seem to be running; docker info gave:\n $info"
145+
echo "Will attempt to start docker by doing '\$ $CMD $APP':"
146+
$CMD $APP
147+
declare -i count
148+
printf "Waiting for docker engine .."
149+
while true; do
150+
printf "."
151+
sleep 2
152+
if docker info >/dev/null 2>&1; then break; fi
153+
count=$(( $count + 1))
154+
if [ $count -gt 10 ]; then
155+
die "No contact with docker engine; bailing out."
156+
fi
157+
done
158+
fi
159+
URL="http://localhost:$PORT/"
160+
else
161+
if [ $($machine status default | tr "A-Z" "a-z" ) != "running" ]; then
162+
echo "The docker VM doesn't seem to be running; will attempt to start it by doing '\$ $machine start':"
163+
$machine start || die "Failed taking up the Docker VM"
164+
fi
139165

140-
if [ -f "$machine" ]; then
141-
if [ $($machine status default | tr "A-Z" "a-z") = "running" ]; then
142-
tmpfile=$(mktemp docker.run.XXXXXXXX)
143-
if $machine env 2>/dev/null | grep DOCKER_ > $tmpfile; then
144-
mv $tmpfile ~/.docker-info
145-
elif printenv | grep DOCKER_ > $tmpfile; then
146-
mv $tmpfile ~/.docker-info
166+
if [ -f "$machine" ]; then
167+
if [ $($machine status default | tr "A-Z" "a-z") = "running" ]; then
168+
tmpfile=$(mktemp docker.run.XXXXXXXX)
169+
if $machine env 2>/dev/null | grep DOCKER_ > $tmpfile; then
170+
mv $tmpfile ~/.docker-info
171+
elif printenv | grep DOCKER_ > $tmpfile; then
172+
mv $tmpfile ~/.docker-info
173+
else
174+
rm $tmpfile
175+
die "Failed setting the appropriate DOCKER_* environment variables."
176+
fi
177+
. ~/.docker-info
147178
else
148-
rm $tmpfile
149-
die "Failed setting the appropriate DOCKER_* environment variables."
179+
rm -f ~/.docker-info
150180
fi
151-
. ~/.docker-info
152-
else
153-
rm -f ~/.docker-info
181+
ip=$($machine ip)
182+
URL="http://$ip:$PORT/"
154183
fi
155184
fi
156185

157-
158186
echo ""
159187
echo "Starting a docker container for '$TAG'."
160188

@@ -169,7 +197,7 @@ to bail out here. Quitting."
169197
if [ -n "$DOWNLOAD" ]; then
170198
(
171199
cd $(dirname $MYSQLDIR)
172-
wget -N $URL && tar xjf ietf_utf8.bin.tar.bz2 && chmod -R go+rwX mysql
200+
wget -N $DBURL && tar xjf ietf_utf8.bin.tar.bz2 && chmod -R go+rwX mysql
173201
)
174202
[ -d "$MYSQLDIR" ] || die "The download seems to have failed; still no $MYSQLDIR. Giving up."
175203
else
@@ -186,6 +214,7 @@ if ! docker images $REPO | grep -q $TAG; then
186214
fi
187215
fi
188216

217+
echo -e "\nThe web interface for 'runserver' should appear on $URL\n"
189218
if [ -z "$MYSQLDIR" ]; then
190219
docker run -ti -p $PORT:8000 -v $HOME:/home/$WHO \
191220
-e USER=$WHO -e DATADIR=${parent#$HOME/}/data -e CWD=${PWD#$HOME/} \

0 commit comments

Comments
 (0)