Tweaks to the docker setup to make it work nicely to run different docker containers for different SVN branches.
- Legacy-Id: 10466
This commit is contained in:
parent
07eb5d9b21
commit
a5435449cd
|
@ -52,7 +52,7 @@ RUN apt-get update && apt-get install -qy \
|
|||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set up root password
|
||||
RUN echo "root:codesprint" | chpasswd
|
||||
RUN echo "root:root" | chpasswd
|
||||
|
||||
# MySQL
|
||||
VOLUME /var/lib/mysql
|
||||
|
@ -69,10 +69,13 @@ RUN wget -q -P /usr/local/bin/ https://tools.ietf.org/tools/idnits/idnits && chm
|
|||
ENV DDIR="/usr/local/share/datatracker"
|
||||
RUN mkdir -p $DDIR
|
||||
WORKDIR $DDIR
|
||||
|
||||
COPY requirements.txt ./
|
||||
COPY settings_local.py ./
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
COPY settings_local.py ./
|
||||
COPY setprompt ./
|
||||
|
||||
COPY docker-init.sh /docker-init.sh
|
||||
ENTRYPOINT ["/docker-init.sh"]
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@ if [ ! "$USER" ]; then
|
|||
echo "Environment variable USER is not set -- will set USER='django'."
|
||||
USER="django"
|
||||
fi
|
||||
if [ ! "$TAG" ]; then
|
||||
echo "Environment variable TAG is not set -- will set TAG='datatracker'."
|
||||
TAG="datatracker"
|
||||
fi
|
||||
|
||||
echo "Checking if MySQL base data exists ..."
|
||||
if [ ! -d $MYSQLDIR/mysql ]; then
|
||||
|
@ -53,27 +57,30 @@ if ! id -u "$USER" &> /dev/null; then
|
|||
useradd -s /bin/bash -G staff $USER
|
||||
fi
|
||||
|
||||
VIRTDIR="/opt/home/$USER/$TAG"
|
||||
if [ ! -d /opt/home/$USER ]; then
|
||||
echo "Setting up python virtualenv at /opt/home/$USER ..."
|
||||
mkdir -p /opt/home/$USER
|
||||
chown $USER /opt/home/$USER
|
||||
mkdir /opt/home/$USER/datatracker
|
||||
virtualenv --system-site-packages /opt/home/$USER/datatracker
|
||||
mkdir $VIRTDIR
|
||||
virtualenv --system-site-packages $VIRTDIR
|
||||
fi
|
||||
|
||||
echo "Activating a virtual python environment ..."
|
||||
cat /opt/home/$USER/datatracker/bin/activate >> /etc/bash.bashrc
|
||||
. /opt/home/$USER/datatracker/bin/activate
|
||||
cat $VIRTDIR/bin/activate >> /etc/bash.bashrc
|
||||
cat /usr/local/share/datatracker/setprompt >> /etc/bash.bashrc
|
||||
. $VIRTDIR/bin/activate
|
||||
|
||||
|
||||
if ! python -c "import django"; then
|
||||
echo "Installing requirements ..."
|
||||
pip install -r /usr/local/share/datatracker/requirements.txt
|
||||
fi
|
||||
|
||||
if [ ! -f /opt/home/$USER/datatracker/lib/site-python/settings_local.py ]; then
|
||||
if [ ! -f $VIRTDIR/lib/site-python/settings_local.py ]; then
|
||||
echo "Setting up a default settings_local.py ..."
|
||||
mkdir -p /opt/home/$USER/datatracker/lib/site-python/
|
||||
cp /usr/local/share/datatracker/settings_local.py /opt/home/$USER/datatracker/lib/site-python/
|
||||
mkdir -p $VIRTDIR/lib/site-python/
|
||||
cp /usr/local/share/datatracker/settings_local.py $VIRTDIR/lib/site-python/
|
||||
fi
|
||||
|
||||
chown -R $USER /opt/home/$USER
|
||||
|
|
16
docker/run
16
docker/run
|
@ -74,12 +74,13 @@ trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)";
|
|||
# Option parsing
|
||||
|
||||
# Options
|
||||
shortopts=dhi:m:r:t:vVu:
|
||||
longopts=download-data,help,ietfdb-url=,mysqldata=,docker-repo=,tag=,verbose,version,user=,
|
||||
shortopts=dhi:m:Mr:t:vVu:
|
||||
longopts=download-data,help,ietfdb-url=,mysqldata=,no-mysqldir,docker-repo=,tag=,verbose,version,user=,
|
||||
|
||||
# Default values
|
||||
TAG=$(basename $(svn info --show-item url $parent))
|
||||
TAG=$(basename $(svn info $parent | grep ^URL | awk '{print $2}'))
|
||||
REPO="levkowetz/datatracker"
|
||||
NOMYMAP=""
|
||||
|
||||
if [ "$(uname)" = "Linux" ]; then
|
||||
args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@")
|
||||
|
@ -100,6 +101,7 @@ while true ; do
|
|||
-h| --help) usage; exit;; # Show this help, then exit
|
||||
-i| --ietfdb-url) URL=$2; shift;; # Use an alternative database tarball URL
|
||||
-m| --mysqldir) MYSQLDIR=$2; shift;; # Set the desired location for MySQL's database files
|
||||
-M| --no-mysqldir) NOMYMAP=1;; # Don't map the mysql dir to an external dir
|
||||
-r| --docker-repo) REPO=$2; shift;; # Use the given docker repository, instead of the default
|
||||
-t| --tag) TAG=$2; shift;; # Use this docker image tag, instead of the svn branch name
|
||||
-u| --user) WHO=$2; shift;; # Run the container as the specified user
|
||||
|
@ -142,7 +144,7 @@ fi
|
|||
|
||||
|
||||
echo ""
|
||||
echo "Starting a docker container for '$TAG' ..."
|
||||
echo "Starting a docker container for '$TAG'."
|
||||
|
||||
docker ps | grep -q $REPO:$TAG && die \
|
||||
"It seems that another docker container is already running the
|
||||
|
@ -173,7 +175,11 @@ if ! docker images $REPO | grep -q $TAG; then
|
|||
fi
|
||||
fi
|
||||
|
||||
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
|
||||
if [ -n "$NOMYMAP" ]; then
|
||||
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
|
||||
else
|
||||
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
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Committing changes in the container to an image:"
|
||||
|
|
Loading…
Reference in a new issue