Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

WiP: Dockerfile for turnkey deployments #1178

Merged
merged 6 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
FROM debian:stretch-backports
MAINTAINER Yaroslav O. Halchenko <[email protected]>

# TODO: convert generation to neurodocker call after all is cool

# Define some ARGs which could be passed into while building
# TODO: in reality there some hardcoding already probably present
# in the entrypoint.sh script.
ARG WEB2PY_PATH=/srv/web2py
ARG WEB2PY_APPS_PATH=${WEB2PY_PATH}/applications
ARG WEB2PY_PORT=8080
# And export some as env vars so they could be available at run time
ENV WEB2PY_PATH=${WEB2PY_PATH}
ENV BOOKS_PATH=${WEB2PY_APPS_PATH}/runestone/books

# Expose that port on the network
EXPOSE ${WEB2PY_PORT}


# To prevent interactive debconf during installations
ARG DEBIAN_FRONTEND=noninteractive
# Components from requirements.txt which are available in Debian
# Missing ones:
# runestone -- is the RunestoneComponents, https://pypi.org/project/runestone/, may be install from Git?
# paver -- too old in Debian filed bug report
# selenium -- also a bit too old (2.53.2+dfsg1-1)
# sphinxcontrib-paverutils -- N/A
# sphinx -- we need stretch-backports
# pytz ... ?
# A few missing ones
# rsync is needed when deploying a built book
# vim - just for pleasure of being able to do any changes right within
# wget - just in case
RUN apt-get update && \
apt-get install -y eatmydata && \
eatmydata apt-get update && echo "count 1" && \
eatmydata apt-get install -y --no-install-recommends \
git \
python-pip libfreetype6-dev postgresql-common postgresql postgresql-contrib \
libpq-dev libxml2-dev libxslt1-dev \
python-diff-match-patch \
python-lxml \
python-numpy \
python-numpy \
python-psycopg2 \
pylint \
python-dateutil \
python-requests \
python-selenium \
python-six \
python-sphinx \
python-sqlalchemy \
python-cssselect \
python-oauth2client \
python-wheel rsync wget && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*


# The rest could be done and ran under a regular (well, staff for installing under /usr/local) user
RUN useradd -s /bin/bash -M -g staff --home-dir ${WEB2PY_PATH} runestone
RUN mkdir -p /srv && chown -R runestone /srv

USER runestone

# Install additional components
RUN git clone --recursive https://github.com/web2py/web2py ${WEB2PY_PATH}

RUN mkdir -p ${WEB2PY_APPS_PATH} && \
cd ${WEB2PY_APPS_PATH} && \
git clone https://github.com/RunestoneInteractive/RunestoneServer runestone


RUN cd ${WEB2PY_APPS_PATH}/runestone && \
pip install --system -r requirements.txt && \
rm -rf ${WEB2PY_PATH}/.cache/*

USER root
WORKDIR ${WEB2PY_PATH}

# All configuration will be done within entrypoint.sh upon initial run
# of the container
COPY docker/entrypoint.sh /usr/local/sbin/entrypoint.sh
CMD /bin/bash /usr/local/sbin/entrypoint.sh
75 changes: 75 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# TODO - this location also allow to do needed copying etc to keep DB outside as well
stamp=/var/lib/postgresql/9.6/main/initialized.stamp

# Fail early upon error
set -eu

info () {
echo "I: $@"
}

# Start service(s)
info "Starting the DB server"
service postgresql start
trap "service postgresql stop" 0

export WEB2PY_CONFIG=production
export WEB2PY_MIGRATE=Yes
export DBURL=postgresql://runestone:${DB_PASSWORD}@localhost/runestone

if [ ! -e "$stamp" ]; then
info "Initializing"
su -c "psql postgres -c \"CREATE USER runestone superuser password '${DB_PASSWORD}';\"" postgres
su -c "createdb --owner=runestone runestone" postgres
cd "$BOOKS_PATH/.."
su -c "rsmanage initdb" runestone
cp $WEB2PY_PATH/applications/runestone/scripts/run_scheduler.py $WEB2PY_PATH/

# Let's use https
# Wouldn't "just work" magically. Requires certificates etc. Eventually!
# echo -e '\nsettings.server_type = "https://"' >> $WEB2PY_PATH/applications/runestone/models/0.py

# Setup students
if [ -e '/srv/configs/instructors.csv' ]; then
info "Setting up instructors"
su -c "rsmanage inituser --fromfile /srv/configs/instructors.csv" runestone
cut -d, -f1,6 /srv/configs/instructors.csv \
| tr ',' ' ' \
| while read n c ; do
su -c "rsmanage addinstructor --username $n --course $c" runestone;
done
fi
if [ -e '/srv/configs/students.csv' ]; then
info "Setting up students"
su -c "rsmanage inituser --fromfile /srv/configs/students.csv" runestone
info "Students were provided -- disabling signup!"
# Disable signup
echo -e "\nauth.settings.actions_disabled.append('register')" >> $WEB2PY_PATH/applications/runestone/models/db.py
fi
touch "$stamp"
else
info "Already initialized"
fi

# Go through all books and do what needs to be done
info "Building & Deploying books"
cd "${BOOKS_PATH}"
/bin/ls | while read b; do
(
cd $b;
su -c "runestone build && runestone deploy" runestone;
);
done

# for debugging
# su -c 'bash' runestone

# Run the beast
info "Starting the server"
cd "$WEB2PY_PATH"
su -c "python web2py.py --ip=0.0.0.0 --port=8080 --password='$DB_PASSWORD' -K runestone --nogui -X" runestone &
sleep 3
info "Starting the scheduler"
su -c "python run_scheduler.py" runestone