Updated Dockerfile and the default settings_local for the docker image. Added docker-init.sh which is used in the docker image, and docker/run which is a wrapper which runs the docker image with suitable settings.
- Legacy-Id: 10436
This commit is contained in:
parent
a17b3c62f5
commit
c2432107a3
|
@ -21,23 +21,37 @@
|
|||
FROM debian:wheezy
|
||||
MAINTAINER Henrik Levkowetz <henrik@levkowetz.com>
|
||||
|
||||
# Default django runserver port
|
||||
EXPOSE 8000
|
||||
|
||||
# Use backports
|
||||
RUN echo "deb http://http.debian.net/debian wheezy-backports main contrib non-free" >> /etc/apt/sources.list
|
||||
|
||||
# Run apt-get noninteractive
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Some basic packages we'll need
|
||||
RUN apt-get update && apt-get install -qy apt-utils wget less python procps ca-certificates awk
|
||||
# Install needed packages
|
||||
RUN apt-get update && apt-get install -qy \
|
||||
apt-utils \
|
||||
ca-certificates \
|
||||
gawk \
|
||||
less \
|
||||
libmysqlclient-dev \
|
||||
libsvn1/wheezy-backports \
|
||||
libxml2-dev \
|
||||
libxslt-dev \
|
||||
mysql-server \
|
||||
procps \
|
||||
pv \
|
||||
python \
|
||||
python-dev \
|
||||
subversion/wheezy-backports \
|
||||
wget \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# MySQL
|
||||
RUN apt-get update && apt-get install -qy mysql-server
|
||||
|
||||
# Subversion
|
||||
RUN apt-get update && apt-get install -qy subversion/wheezy-backports libsvn1/wheezy-backports
|
||||
|
||||
# Some packages needed to compile requirements
|
||||
RUN apt-get update && apt-get install -qy libmysqlclient-dev python-dev libxml2-dev libxslt-dev
|
||||
VOLUME /var/lib/mysql
|
||||
|
||||
# Pip
|
||||
ENV PYTHONWARNINGS="ignore:a true SSLContext object"
|
||||
|
@ -52,7 +66,7 @@ RUN wget -q -P /usr/local/bin/ https://tools.ietf.org/tools/idnits/idnits
|
|||
RUN chmod +x /usr/local/bin/idnits
|
||||
|
||||
# A default user
|
||||
RUN useradd -ms /bin/bash django
|
||||
RUN useradd -m -s /bin/bash -u 500 django
|
||||
USER django
|
||||
WORKDIR /home/django
|
||||
|
||||
|
@ -68,4 +82,10 @@ RUN . bin/activate; pip install -r requirements.txt
|
|||
COPY settings_local.py ./settings_local.py
|
||||
RUN . bin/activate; ietf/manage.py test --settings=settings_sqlitetest
|
||||
|
||||
WORKDIR /home
|
||||
USER root
|
||||
WORKDIR /
|
||||
|
||||
COPY docker-init.sh /docker-init.sh
|
||||
ENTRYPOINT ["/docker-init.sh"]
|
||||
|
||||
CMD /bin/bash
|
||||
|
|
93
docker/docker-init.sh
Executable file
93
docker/docker-init.sh
Executable file
|
@ -0,0 +1,93 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Gathering info ..."
|
||||
MYSQLDIR="$(mysqld --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"
|
||||
|
||||
echo "Checking if MySQL base data exists ..."
|
||||
if [ ! -d $MYSQLDIR/mysql ]; then
|
||||
echo "Re-installing MySQL ..."
|
||||
apt-get update && apt-get install --reinstall mysql-server
|
||||
fi
|
||||
|
||||
|
||||
echo "Checking if MySQL is running ..."
|
||||
if ! /etc/init.d/mysql status; then
|
||||
echo "Starting mysql ..."
|
||||
/etc/init.d/mysql start
|
||||
fi
|
||||
|
||||
echo "Checking if the IETF database exists at $MYSQLDIR ..."
|
||||
if [ ! -d $MYSQLDIR/ietf_utf8 ]; then
|
||||
ls -l $MYSQLDIR
|
||||
|
||||
echo "Creating database ..."
|
||||
mysqladmin -u root --default-character-set=utf8 create ietf_utf8
|
||||
|
||||
echo "Setting up permissions ..."
|
||||
mysql -u root ietf_utf8 <<< "GRANT ALL PRIVILEGES ON ietf_utf8.* TO django@localhost IDENTIFIED BY 'RkTkDPFnKpko'; FLUSH PRIVILEGES;"
|
||||
|
||||
echo "Fetching database ..."
|
||||
DUMPDIR=/home/$USER/$DATADIR
|
||||
wget -N -P $DUMPDIR http://www.ietf.org/lib/dt/sprint/ietf_utf8.sql.gz
|
||||
|
||||
echo "Loading database ..."
|
||||
gunzip < $DUMPDIR/ietf_utf8.sql.gz \
|
||||
| pv --progress --bytes --rate --eta --cursor --size $(gzip --list --quiet $DUMPDIR/ietf_utf8.sql.gz | awk '{ print $2 }') \
|
||||
| sed -e 's/ENGINE=MyISAM/ENGINE=InnoDB/' \
|
||||
| mysql --user=django --password=RkTkDPFnKpko -s -f ietf_utf8 \
|
||||
&& rm /tmp/ietf_utf8.sql.gz
|
||||
|
||||
fi
|
||||
|
||||
if ! id -u "$USER" &> /dev/null; then
|
||||
echo "Creating user '$USER' ..."
|
||||
useradd -ms /bin/bash $USER
|
||||
fi
|
||||
|
||||
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 /opt/home/$USER/datatracker
|
||||
fi
|
||||
|
||||
echo "Activating virtual python environment"
|
||||
cat /opt/home/$USER/datatracker/bin/activate >> /etc/bash.bashrc
|
||||
. /opt/home/$USER/datatracker/bin/activate
|
||||
|
||||
|
||||
if [ ! -d /opt/home/$USER/datatracker/lib/python2.7/site-packages/django ]; then
|
||||
echo "Installing requirements (based on trunk)"
|
||||
pip install -r /home/django/src/trunk/requirements.txt
|
||||
fi
|
||||
|
||||
if [ ! -f /opt/home/$USER/datatracker/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 /home/django/src/trunk/settings_local.py /opt/home/$USER/datatracker/lib/site-python/
|
||||
fi
|
||||
|
||||
echo "Done."
|
||||
|
||||
FLAG1=/opt/home/$USER/.docker-init-flag-1
|
||||
if [ ! -f $FLAG1 ]; then
|
||||
touch $FLAG1
|
||||
cat <<-EOT
|
||||
|
||||
******************************************************************************
|
||||
|
||||
You should now cd to your svn working directory and update the datatracker
|
||||
prerequisites according to the requirements given in 'requirements.txt':
|
||||
|
||||
$ pip install -r requirements.txt
|
||||
|
||||
Happy coding!
|
||||
|
||||
******************************************************************************
|
||||
EOT
|
||||
fi
|
||||
|
||||
chown -R $USER /opt/home/$USER
|
||||
cd /home/$USER
|
||||
su $USER
|
134
docker/run
Executable file
134
docker/run
Executable file
|
@ -0,0 +1,134 @@
|
|||
#!/bin/bash
|
||||
|
||||
version=0.10
|
||||
program=${0##*/}
|
||||
progdir=${0%/*}
|
||||
if [ "$progdir" = "$program" ]; then progdir="."; fi
|
||||
if [ "$progdir" = "." ]; then progdir="$PWD"; fi
|
||||
parent=$(dirname $progdir)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
function usage() {
|
||||
cat <<EOF
|
||||
NAME
|
||||
$program - Run a docker datatracker container with suitable settings
|
||||
|
||||
SYNOPSIS
|
||||
$program [OPTIONS] ARGS
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
This is a wrapper which runs docker with suitable arguments on a
|
||||
debian-based docker image which has been set up with the dependencies
|
||||
needed to easily run the IETF datatracker in development mode. By
|
||||
default, it expects to find MySWL database files at
|
||||
$parent/data/mysql, which is mapped inside the
|
||||
container to /var/lib/mysql, and it will set up a home directory for
|
||||
the current user ($USER) and map it to $HOME.
|
||||
|
||||
EOF
|
||||
echo -e "OPTIONS"
|
||||
if [ "$(uname)" = "Linux" ]; then
|
||||
egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | tr -s "\t|" "\t," | sed -r -e 's/\)[ \t]+([A-Z]+)=\$2[^#]*#/=\1\t/' -e 's/\)[^#]*#/\t/'
|
||||
else
|
||||
egrep "^[ ]+[-][A-Za-z| -]+\*?\)[ ]+[A-Za-z].+#" $0 | sed 's/\|.*\$2[^#]*#/ /'| sed -E 's/\|.*\)[^#]*#/ /'
|
||||
fi
|
||||
cat <<EOF
|
||||
|
||||
FILES
|
||||
|
||||
AUTHOR
|
||||
Written by Henrik Levkowetz, <henrik@levkowetz.com>
|
||||
|
||||
COPYRIGHT
|
||||
|
||||
Copyright (c) 2015 IETF Trust and the persons identified as authors of
|
||||
the code. All rights reserved. License 'Simplified BSD', as specified
|
||||
in http://opensource.org/licenses/BSD-3-Clause.
|
||||
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
function die() {
|
||||
echo -e "\n$program: error: $*" > /dev/stderr
|
||||
exit 1
|
||||
}
|
||||
|
||||
function note() {
|
||||
if [ -n "$VERBOSE" ]; then echo -e "$*"; fi
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
function version() {
|
||||
echo -e "$program $version"
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Option parsing
|
||||
|
||||
# Options
|
||||
shortopts=dhi:vVu:m:
|
||||
longopts=download-data,help,ietfdb-url=,verbose,version,user=,mysqldata=,
|
||||
|
||||
# Default values
|
||||
|
||||
if [ "$(uname)" = "Linux" ]; then
|
||||
args=$(getopt -o "$shortopts" --long "$longopts" -n '$program' -- $SV "$@")
|
||||
if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi
|
||||
eval set -- "$args"
|
||||
sed="sed -r"
|
||||
else
|
||||
# Darwin, BSDs
|
||||
args=$(getopt -o$shortopts $SV $*)
|
||||
if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi
|
||||
set -- $args
|
||||
sed="sed -E"
|
||||
fi
|
||||
|
||||
while true ; do
|
||||
case "$1" in
|
||||
-d| --download-data) DOWNLOAD=1;; # Download and set up the database files
|
||||
-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
|
||||
-u| --user) WHO=$2; shift;; # Run container as someone else than $USER
|
||||
-v| --verbose) VERBOSE=1;; # Be more talkative
|
||||
-V| --version) version; exit;; # Show program version, then exit
|
||||
--) shift; break;;
|
||||
*) die "Internal error, inconsistent option specification: '$1'";;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# The program itself
|
||||
|
||||
docker ps | grep -q levkowetz/datatracker:latest && die \
|
||||
"It seems that another docker container is already running the
|
||||
image 'levkowetz/datatracker:latest' -- but only one MySQL instance can bind
|
||||
to the database files at a time. Quitting."
|
||||
|
||||
[ -n "$WHO" ] || WHO=$(whoami)
|
||||
[ -n "$MYSQLDIR" ] || MYSQLDIR=$parent/data/mysql
|
||||
[ -n "$URL"] || URL=https://www.ietf.org/lib/dt/sprint/ietf_utf8.bin.tar.bz2
|
||||
|
||||
if [ -n "$DOWNLOAD" ]; then
|
||||
(
|
||||
cd $(dirname $MYSQLDIR)
|
||||
wget -N https://www.ietf.org/lib/dt/sprint/ietf_utf8.bin.tar.bz2 && tar xjf ietf_utf8.bin.tar.bz2 && chmod -R go+rwX mysql
|
||||
)
|
||||
[ -d "$MYSQLDIR" ] || die "The download seems to have failed; still no $MYSQLDIR. Giving up."
|
||||
else
|
||||
[ -d "$MYSQLDIR" ] || die "Expected $MYSQLDIR to exist, but it\ndidn't. Use '$program -d' to download and unpack the database."
|
||||
fi
|
||||
|
||||
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
|
||||
latest=$(docker ps -lq)
|
||||
echo "Committing changes in the container to an image:"
|
||||
docker commit $latest levkowetz/datatracker:latest
|
|
@ -2,10 +2,10 @@ SECRET_KEY = 'jzv$o93h_lzw4a0%0oz-5t5lk+ai=3f8x@uo*9ahu8w4i300o6'
|
|||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'NAME': 'dev_ietf_utf8',
|
||||
'NAME': 'ietf_utf8',
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'USER': 'django_dev',
|
||||
'PASSWORD': 'mJM+#@Fgec',
|
||||
'USER': 'django',
|
||||
'PASSWORD': 'RkTkDPFnKpko',
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue