Skip to content

Commit a543544

Browse files
committed
Tweaks to the docker setup to make it work nicely to run different docker containers for different SVN branches.
- Legacy-Id: 10466
1 parent 07eb5d9 commit a543544

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

docker/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ RUN apt-get update && apt-get install -qy \
5252
&& rm -rf /var/lib/apt/lists/*
5353

5454
# Set up root password
55-
RUN echo "root:codesprint" | chpasswd
55+
RUN echo "root:root" | chpasswd
5656

5757
# MySQL
5858
VOLUME /var/lib/mysql
@@ -69,10 +69,13 @@ RUN wget -q -P /usr/local/bin/ https://tools.ietf.org/tools/idnits/idnits && chm
6969
ENV DDIR="/usr/local/share/datatracker"
7070
RUN mkdir -p $DDIR
7171
WORKDIR $DDIR
72+
7273
COPY requirements.txt ./
73-
COPY settings_local.py ./
7474
RUN pip install -r requirements.txt
7575

76+
COPY settings_local.py ./
77+
COPY setprompt ./
78+
7679
COPY docker-init.sh /docker-init.sh
7780
ENTRYPOINT ["/docker-init.sh"]
7881

docker/docker-init.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ if [ ! "$USER" ]; then
66
echo "Environment variable USER is not set -- will set USER='django'."
77
USER="django"
88
fi
9+
if [ ! "$TAG" ]; then
10+
echo "Environment variable TAG is not set -- will set TAG='datatracker'."
11+
TAG="datatracker"
12+
fi
913

1014
echo "Checking if MySQL base data exists ..."
1115
if [ ! -d $MYSQLDIR/mysql ]; then
@@ -53,27 +57,30 @@ if ! id -u "$USER" &> /dev/null; then
5357
useradd -s /bin/bash -G staff $USER
5458
fi
5559

60+
VIRTDIR="/opt/home/$USER/$TAG"
5661
if [ ! -d /opt/home/$USER ]; then
5762
echo "Setting up python virtualenv at /opt/home/$USER ..."
5863
mkdir -p /opt/home/$USER
5964
chown $USER /opt/home/$USER
60-
mkdir /opt/home/$USER/datatracker
61-
virtualenv --system-site-packages /opt/home/$USER/datatracker
65+
mkdir $VIRTDIR
66+
virtualenv --system-site-packages $VIRTDIR
6267
fi
6368

6469
echo "Activating a virtual python environment ..."
65-
cat /opt/home/$USER/datatracker/bin/activate >> /etc/bash.bashrc
66-
. /opt/home/$USER/datatracker/bin/activate
70+
cat $VIRTDIR/bin/activate >> /etc/bash.bashrc
71+
cat /usr/local/share/datatracker/setprompt >> /etc/bash.bashrc
72+
. $VIRTDIR/bin/activate
73+
6774

6875
if ! python -c "import django"; then
6976
echo "Installing requirements ..."
7077
pip install -r /usr/local/share/datatracker/requirements.txt
7178
fi
7279

73-
if [ ! -f /opt/home/$USER/datatracker/lib/site-python/settings_local.py ]; then
80+
if [ ! -f $VIRTDIR/lib/site-python/settings_local.py ]; then
7481
echo "Setting up a default settings_local.py ..."
75-
mkdir -p /opt/home/$USER/datatracker/lib/site-python/
76-
cp /usr/local/share/datatracker/settings_local.py /opt/home/$USER/datatracker/lib/site-python/
82+
mkdir -p $VIRTDIR/lib/site-python/
83+
cp /usr/local/share/datatracker/settings_local.py $VIRTDIR/lib/site-python/
7784
fi
7885

7986
chown -R $USER /opt/home/$USER

docker/run

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)";
7474
# Option parsing
7575

7676
# Options
77-
shortopts=dhi:m:r:t:vVu:
78-
longopts=download-data,help,ietfdb-url=,mysqldata=,docker-repo=,tag=,verbose,version,user=,
77+
shortopts=dhi:m:Mr:t:vVu:
78+
longopts=download-data,help,ietfdb-url=,mysqldata=,no-mysqldir,docker-repo=,tag=,verbose,version,user=,
7979

8080
# Default values
81-
TAG=$(basename $(svn info --show-item url $parent))
81+
TAG=$(basename $(svn info $parent | grep ^URL | awk '{print $2}'))
8282
REPO="levkowetz/datatracker"
83+
NOMYMAP=""
8384

8485
if [ "$(uname)" = "Linux" ]; then
8586
args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@")
@@ -100,6 +101,7 @@ while true ; do
100101
-h| --help) usage; exit;; # Show this help, then exit
101102
-i| --ietfdb-url) URL=$2; shift;; # Use an alternative database tarball URL
102103
-m| --mysqldir) MYSQLDIR=$2; shift;; # Set the desired location for MySQL's database files
104+
-M| --no-mysqldir) NOMYMAP=1;; # Don't map the mysql dir to an external dir
103105
-r| --docker-repo) REPO=$2; shift;; # Use the given docker repository, instead of the default
104106
-t| --tag) TAG=$2; shift;; # Use this docker image tag, instead of the svn branch name
105107
-u| --user) WHO=$2; shift;; # Run the container as the specified user
@@ -142,7 +144,7 @@ fi
142144

143145

144146
echo ""
145-
echo "Starting a docker container for '$TAG' ..."
147+
echo "Starting a docker container for '$TAG'."
146148

147149
docker ps | grep -q $REPO:$TAG && die \
148150
"It seems that another docker container is already running the
@@ -173,7 +175,11 @@ if ! docker images $REPO | grep -q $TAG; then
173175
fi
174176
fi
175177

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
178+
if [ -n "$NOMYMAP" ]; then
179+
docker run -ti -p 8000:8000 -v $HOME:/home/$WHO -e USER=$WHO -e DATADIR=${parent#$HOME/}/data -e CWD=${PWD#$HOME/} -e TAG=$TAG $REPO:$TAG
180+
else
181+
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/} -e TAG=$TAG $REPO:$TAG
182+
fi
177183

178184
echo ""
179185
echo "Committing changes in the container to an image:"

0 commit comments

Comments
 (0)