Start of dockerisation + running on uWSGI, not complete yet

This commit is contained in:
2018-08-07 16:42:11 +02:00
parent 9e1cec9871
commit b77b6331d5
6 changed files with 155 additions and 16 deletions
-16
View File
@@ -1,16 +0,0 @@
FROM nikolaik/python-nodejs:latest
ENV PYTHONUNBUFFERED 1
RUN pip3 install pipenv
RUN mkdir /code
WORKDIR /code
ADD . /code/
RUN pipenv install --deploy --system
RUN python manage.py collectstatic --noinput
RUN npm install --ignore-optional
RUN npm run build
VOLUME /code/assets
+59
View File
@@ -0,0 +1,59 @@
FROM ubuntu:18.04
RUN set -ex; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
python3 python3-pip uwsgi uwsgi-plugin-python3 nginx postgresql-10 postgresql-client-10; \
rm -rf /var/lib/apt/lists/*; \
locale-gen en_US.UTF-8;
# Configure Postgresql
RUN set -ex; \
pg_conftool set lc_messages 'en_US.UTF-8'; \
pg_conftool set lc_monetary 'en_US.UTF-8'; \
pg_conftool set lc_numeric 'en_US.UTF-8'; \
pg_conftool set lc_time 'en_US.UTF-8'; \
pg_conftool set listen_addresses '';
COPY pg_hba.conf /etc/postgresql/10/main
ENV LANG en_US.UTF-8
VOLUME /var/lib/postgresql/10/main
# Create users and a group for the Django apps.
# Their home dir does not contain the web files; they are in /var/www/{appname}
RUN set -ex; \
groupadd django; \
useradd -g django --no-user-group -m -d /home/mydata mydata; \
useradd -g django --no-user-group -m -d /home/opendata opendata
# Configure uWSGI
COPY uwsgi/mydata.ini /etc/uwsgi/apps-available
RUN set -ex; \
cd /etc/uwsgi/apps-enabled; \
ln -s ../apps-available/*.ini .
# Set up the virtualenvs
RUN pip3 install pipenv
# This creates the Virtualenv inside {project}/.venv
ENV PIPENV_VENV_IN_PROJECT=1
COPY deploy/ /var/www/
WORKDIR /var/www/mydata
RUN pipenv install --deploy
# WORKDIR /var/www/opendata
# RUN pipenv install --deploy
# RUN python manage.py collectstatic --noinput
#
# RUN npm install --ignore-optional
# RUN npm run build
#
# VOLUME /code/assets
VOLUME /var/log
COPY entrypoint.sh /
# ENTRYPOINT ./entrypoint.sh
EXPOSE 80
WORKDIR /
+64
View File
@@ -0,0 +1,64 @@
#!/bin/bash -e
DEPLOY_BRANCH=${DEPLOY_BRANCH:-production}
# macOS does not support readlink -f, so we use greadlink instead
if [[ `uname` == 'Darwin' ]]; then
command -v greadlink 2>/dev/null 2>&1 || { echo >&2 "Install greadlink using brew."; exit 1; }
readlink='greadlink'
else
readlink='readlink'
fi
ROOT="$(dirname "$(dirname "$($readlink -f "$0")")")"
DEPLOYDIR="$ROOT/docker/deploy"
PROJECT_NAME="mydata"
if [ -e "$DEPLOYDIR" ]; then
echo "$DEPLOYDIR already exists, press [ENTER] to DESTROY AND COPY, Ctrl+C to abort."
read dummy
rm -rf "$DEPLOYDIR"
else
echo -n "Deploying to $DEPLOYDIR"
echo "press [ENTER] to continue, Ctrl+C to abort."
read dummy
fi
cd ${ROOT}
mkdir -p $DEPLOYDIR
REMOTE_ROOT="$DEPLOYDIR/$PROJECT_NAME"
# Check that production branch has been pushed.
if [ -n "$(git log origin/$DEPLOY_BRANCH..$DEPLOY_BRANCH --oneline)" ]; then
echo "WARNING: not all changes to the $DEPLOY_BRANCH branch have been pushed."
echo "Press [ENTER] to continue deploying current origin/$DEPLOY_BRANCH, CTRL+C to abort."
read dummy
fi
function git_clone() {
PROJECT_NAME="$1"
URL="$2"
BRANCH="$DEPLOY_BRANCH"
set -e
echo "==================================================================="
echo "CLONING REPO ON $PROJECT_NAME @$BRANCH"
git -C $DEPLOYDIR clone --depth 1 --branch $BRANCH $URL $PROJECT_NAME
}
git_clone mydata git@gitlab.com:armadillica/blender-my-data.git
git_clone opendata git@gitlab.com:armadillica/blender-open-data.git
# Gulp everywhere
GULP=$ROOT/node_modules/.bin/gulp
if [ ! -e $GULP -o gulpfile.js -nt $GULP ]; then
npm install
touch $GULP # installer doesn't always touch this after a build, so we do.
fi
$GULP --cwd $DEPLOYDIR/mydata --production
$GULP --cwd $DEPLOYDIR/opendata --production
echo
echo "==================================================================="
echo "Deploy of ${PROJECT_NAME} is ready for dockerisation."
echo "==================================================================="
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh -ex
# Start our daemons
pg_ctlcluster 10 main start
nginx
+15
View File
@@ -0,0 +1,15 @@
# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only.
# Allow Django to connect via Unix domain sockets the same way as
# usually is done via TCP/IP sockets (so 'md5' instead of 'peer')
local all all md5
+12
View File
@@ -0,0 +1,12 @@
[uwsgi]
vhost = true
plugins = python3
master = true
enable-threads = true
processes = 1
socket = /var/www/mydata/uwsgi.sock
virtualenv = /var/www/mydata/.venv/
chdir = /var/www/mydata
wsgi-file = /var/www/mydata/mydata/wsgi.py
uid = mydata
gid = django