Merge lp:~widelands-dev/widelands-website/wlwebsite_docker into lp:widelands-website

Proposed by SirVer
Status: Rejected
Rejected by: SirVer
Proposed branch: lp:~widelands-dev/widelands-website/wlwebsite_docker
Merge into: lp:widelands-website
Diff against target: 171 lines (+108/-16)
5 files modified
Dockerfile (+49/-0)
Makefile (+51/-0)
pip_requirements.txt (+0/-1)
run_docker.sh (+6/-0)
settings.py (+2/-15)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/wlwebsite_docker
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+317036@code.launchpad.net

Description of the change

Experimental branch, not sure if this should be merged.

I set up a docker workflow to run the website against a real mysql database on any development system (windows, mac, linux) easily. The goals here are

1) get rid of installing dependencies (like the python modules) on dev machines.
2) make sure all devs have always the exactly same set of python modules and python version,
3) dev workflows can use external tools (like wl_map_info) also on their dev machine, i.e. less differences between production and dev,
4) quicker setup for new devs.

How does this work? The flow is based around a tool named Docker (https://www.docker.com/). Docker runs containers and links them together. You can think of a container as a zero-cost virtual Linux machine (when running on Linux).

A container is described by a Dockerfile - which is a Build rule for assembling these virtual machines. And the core of this patch is a Dockerfile for the website. The idea is now to run a container with a mysql database[1], then build the website docker container and run it against this mysql. This means you run the full setup of the website on your dev machine.

Read the patch starting from the Makefile, then into the Dockerfile.

The workflow to get this up and running is this:

1) Install docker and do the docker tutorial[2] to get a basic understanding of docker.
2) bring up in one terminal the mysql database (make run_mysql).
3) build an image from the dockerfile: make docker
4) initialize the database and create a superuser: make init
5) run the website and try to upload a map: make serve

[1] https://hub.docker.com/_/mysql/
[2] https://docs.docker.com/engine/getstarted/

To post a comment you must log in.
453. By SirVer

More documentation.

Revision history for this message
SirVer (sirver) :
Revision history for this message
kaputtnik (franku) wrote :

Sounds interesting.

I will test it in the next days.

Revision history for this message
kaputtnik (franku) wrote :

I got a failure on make init:

django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
make: *** [Makefile:32: init] Fehler 1

I am unsure about the benefits:

> 1) get rid of installing dependencies (like the python modules)
> on dev machines.
Instead one has to install other things (docker itself, docker-files).

> 2) make sure all devs have always the exactly same set of python
> modules and python version,
Good point. On the other side: If one is using a more up to date version we are able to find a trap early, before deploying.

> 3) dev workflows can use external tools (like wl_map_info) also
> on their dev machine, i.e. less differences between production and dev,
Also a good point. On the other side a website dev should have current trunk from widelands somewhere on his disk, to develop the encyclopedia or the documentation. So it should be possible to give also access to wl_map_info.

> 4) quicker setup for new devs.
I don't know. The whole setup relies on docker which basics have to be understood. From my point of view having our README is much clearer and cleaner than reading and executing the docker example. Using docker will hide some of the installation process to a new dev which could lead into other questions.

Also running docker means each docker-file has some access to the root file system. The 'make init' command produce *.pyc files owned by the root user here.

Regarding mysql, and database in general:
The main Problem for a new dev is that he has no data. All the forum and wiki is empty. For testing purposes a dev has to spend some time to get such data.
I had worked on a text file regarding setting up and maintain a mysql database containing some hints on using utf8, collation, backup and so on. Maybe this is the better way to go?

All this installations takes round about 2 GB of disk space. Can't say why, but i don't like that...

I think this proposal is meant to get more developers for the webpage, but i don't believe it would help here because the process is as 'complicated' as using the README. Maybe i am wrong...

Unmerged revisions

453. By SirVer

More documentation.

452. By SirVer

Folded database running into Makefile to not require docker compose.

451. By SirVer

First working iteration of a dockerized dev environment.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'Dockerfile'
--- Dockerfile 1970-01-01 00:00:00 +0000
+++ Dockerfile 2017-02-11 21:31:29 +0000
@@ -0,0 +1,49 @@
1# This image will be based on the ubuntu:zesty image: https://hub.docker.com/_/ubuntu/
2FROM ubuntu:zesty
3ENV PYTHONUNBUFFERED 1
4
5# Some magic to make sure that the uid and gid of created files matches your
6# own. Ignore.
7ARG UID
8ARG GID
9RUN useradd user -u $UID -g $GID -m -s /bin/bash
10
11# Install add-apt-repository, so we can add the Widelands repository.
12RUN apt-get update && apt-get install -y \
13 software-properties-common
14
15RUN add-apt-repository ppa:widelands-dev/widelands-daily
16
17# Install all software we require.
18RUN apt-get update && apt-get install -y \
19 git \
20 libjpeg-dev \
21 libmysqlclient-dev \
22 libpng-dev \
23 python \
24 python-pip \
25 widelands \
26 xvfb \
27 && rm -rf /var/lib/apt/lists/*
28
29RUN mkdir /src/ && mkdir /code && chown -R user /src /code
30
31# Copy the 'pip_requirements.txt' file into /code. This has also the benefit
32# that whenever this file changes, i.e. our requirements changes, docker will
33# rerun this step and build a new image.
34ADD pip_requirements.txt /code
35RUN pip install -r /code/pip_requirements.txt
36
37# Make sure that when we run this container, we can find the binaries installed by Widelands which end up
38# in /usr/games.
39ENV PATH /usr/games:$PATH
40
41ADD run_docker.sh /code
42
43EXPOSE 8000
44# TODO(sirver): this should be enabled, but leads to wrong writes
45# USER user
46WORKDIR /code
47
48# This is the entrypoint if you run this image without any further commands.
49CMD ["sh", "run_docker.sh"]
050
=== added file 'Makefile'
--- Makefile 1970-01-01 00:00:00 +0000
+++ Makefile 2017-02-11 21:31:29 +0000
@@ -0,0 +1,51 @@
1# Arguments to run the website container, we use this a couple of times below.
2# --link db:db means that the container called 'db' is reachable as 'db' inside this container, i.e.
3# ping db will work.
4# -v means "mount the current directory as /code in the container, i.e. all
5# changes the container writes there are visible in the current directory and
6# vice versa.
7# Note the --rm (remove). Each time we run this command, we create a new
8# container from the image 'wlwebsite' and delete it immediately after it
9# exits again.
10DOCKER_RUN:=docker run -it --rm \
11 --link db:db \
12 -p 8000:8000 \
13 -v $(shell pwd):/code \
14 wlwebsite
15
16# Bring up a mysql server. The database will be completely empty the first time
17# this runs, but if you press ctrl-c, docker will not delete this container
18# (you could say it hibernates). starting it again gives you access to all your
19# data again.
20run_mysql:
21 docker run -it \
22 --name db \
23 -e MYSQL_DATABASE=wl_django \
24 -e MYSQL_ROOT_PASSWORD=bluba \
25 -e MYSQL_USER=widelands \
26 -e MYSQL_PASSWORD=widelands \
27 -p 3306:3306 \
28 mysql
29
30# Creates a super user and runs ./manage.py migrate
31init:
32 $(DOCKER_RUN) ./manage.py migrate
33 $(DOCKER_RUN) ./manage.py createsuperuser
34
35# Builds the 'Dockerfile' into an image called 'wlwebsite'. This image can then
36# be run which results in a container.
37docker:
38 docker build . -t wlwebsite \
39 --build-arg UID=$(shell id -u) \
40 --build-arg GID=$(shell id -g)
41
42# Runs ./run_docker.sh inside the container. See Dockerfile.
43serve:
44 $(DOCKER_RUN)
45
46# This will execute the CMD in the Dockerfile which runs the django debug server. Use like this:
47# CMD="<cmd>" make cmd. For example
48# CMD="find / | grep foo" make cmd
49# lists all files that contain foo in their filename inside the container.
50cmd:
51 $(DOCKER_RUN) ${CMD}
052
=== modified file 'pip_requirements.txt'
--- pip_requirements.txt 2017-01-21 12:39:23 +0000
+++ pip_requirements.txt 2017-02-11 21:31:29 +0000
@@ -24,4 +24,3 @@
24untokenize==0.1.124untokenize==0.1.1
25-e git://github.com/kerin/django-sphinx.git#egg=django-sphinx25-e git://github.com/kerin/django-sphinx.git#egg=django-sphinx
26bleach==1.4.326bleach==1.4.3
27
2827
=== added file 'run_docker.sh'
--- run_docker.sh 1970-01-01 00:00:00 +0000
+++ run_docker.sh 2017-02-11 21:31:29 +0000
@@ -0,0 +1,6 @@
1#!/bin/sh
2
3Xvfb :99 -screen 0 1024x768x16 &> xvfb.log &
4export DISPLAY=:99.0
5
6python manage.py runserver 0.0.0.0:8000
07
=== modified file 'settings.py'
--- settings.py 2017-01-21 12:39:23 +0000
+++ settings.py 2017-02-11 21:31:29 +0000
@@ -12,19 +12,6 @@
1212
13MANAGERS = ADMINS13MANAGERS = ADMINS
1414
15DATABASES = {
16 'default': {
17 'ENGINE': 'django.db.backends.sqlite3',
18 'NAME': 'dev.db',
19 'USER': '', # Not used with sqlite3.
20 'PASSWORD': '', # Not used with sqlite3.
21 # Set to empty string for localhost. Not used with sqlite3.
22 'HOST': '',
23 # Set to empty string for default. Not used with sqlite3.
24 'PORT': '',
25 }
26}
27
28# Local time zone for this installation. Choices can be found here:15# Local time zone for this installation. Choices can be found here:
29# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name16# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
30# although not all choices may be available on all operating systems.17# although not all choices may be available on all operating systems.
@@ -48,7 +35,7 @@
4835
49# Absolute path to the directory that holds media.36# Absolute path to the directory that holds media.
50# Example: "/home/media/media.lawrence.com/"37# Example: "/home/media/media.lawrence.com/"
51MEDIA_ROOT = ''38MEDIA_ROOT = '/code/media_root'
5239
53# URL that handles the media served from MEDIA_ROOT. Make sure to use a40# URL that handles the media served from MEDIA_ROOT. Make sure to use a
54# trailing slash if there is a path component (optional in other cases).41# trailing slash if there is a path component (optional in other cases).
@@ -245,7 +232,7 @@
245###############################232###############################
246# Sphinx (Search prog) Config #233# Sphinx (Search prog) Config #
247###############################234###############################
248USE_SPHINX = True235USE_SPHINX = False
249SPHINX_API_VERSION = 0x116236SPHINX_API_VERSION = 0x116
250237
251############238############

Subscribers

People subscribed via source and target branches