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
1=== added file 'Dockerfile'
2--- Dockerfile 1970-01-01 00:00:00 +0000
3+++ Dockerfile 2017-02-11 21:31:29 +0000
4@@ -0,0 +1,49 @@
5+# This image will be based on the ubuntu:zesty image: https://hub.docker.com/_/ubuntu/
6+FROM ubuntu:zesty
7+ENV PYTHONUNBUFFERED 1
8+
9+# Some magic to make sure that the uid and gid of created files matches your
10+# own. Ignore.
11+ARG UID
12+ARG GID
13+RUN useradd user -u $UID -g $GID -m -s /bin/bash
14+
15+# Install add-apt-repository, so we can add the Widelands repository.
16+RUN apt-get update && apt-get install -y \
17+ software-properties-common
18+
19+RUN add-apt-repository ppa:widelands-dev/widelands-daily
20+
21+# Install all software we require.
22+RUN apt-get update && apt-get install -y \
23+ git \
24+ libjpeg-dev \
25+ libmysqlclient-dev \
26+ libpng-dev \
27+ python \
28+ python-pip \
29+ widelands \
30+ xvfb \
31+ && rm -rf /var/lib/apt/lists/*
32+
33+RUN mkdir /src/ && mkdir /code && chown -R user /src /code
34+
35+# Copy the 'pip_requirements.txt' file into /code. This has also the benefit
36+# that whenever this file changes, i.e. our requirements changes, docker will
37+# rerun this step and build a new image.
38+ADD pip_requirements.txt /code
39+RUN pip install -r /code/pip_requirements.txt
40+
41+# Make sure that when we run this container, we can find the binaries installed by Widelands which end up
42+# in /usr/games.
43+ENV PATH /usr/games:$PATH
44+
45+ADD run_docker.sh /code
46+
47+EXPOSE 8000
48+# TODO(sirver): this should be enabled, but leads to wrong writes
49+# USER user
50+WORKDIR /code
51+
52+# This is the entrypoint if you run this image without any further commands.
53+CMD ["sh", "run_docker.sh"]
54
55=== added file 'Makefile'
56--- Makefile 1970-01-01 00:00:00 +0000
57+++ Makefile 2017-02-11 21:31:29 +0000
58@@ -0,0 +1,51 @@
59+# Arguments to run the website container, we use this a couple of times below.
60+# --link db:db means that the container called 'db' is reachable as 'db' inside this container, i.e.
61+# ping db will work.
62+# -v means "mount the current directory as /code in the container, i.e. all
63+# changes the container writes there are visible in the current directory and
64+# vice versa.
65+# Note the --rm (remove). Each time we run this command, we create a new
66+# container from the image 'wlwebsite' and delete it immediately after it
67+# exits again.
68+DOCKER_RUN:=docker run -it --rm \
69+ --link db:db \
70+ -p 8000:8000 \
71+ -v $(shell pwd):/code \
72+ wlwebsite
73+
74+# Bring up a mysql server. The database will be completely empty the first time
75+# this runs, but if you press ctrl-c, docker will not delete this container
76+# (you could say it hibernates). starting it again gives you access to all your
77+# data again.
78+run_mysql:
79+ docker run -it \
80+ --name db \
81+ -e MYSQL_DATABASE=wl_django \
82+ -e MYSQL_ROOT_PASSWORD=bluba \
83+ -e MYSQL_USER=widelands \
84+ -e MYSQL_PASSWORD=widelands \
85+ -p 3306:3306 \
86+ mysql
87+
88+# Creates a super user and runs ./manage.py migrate
89+init:
90+ $(DOCKER_RUN) ./manage.py migrate
91+ $(DOCKER_RUN) ./manage.py createsuperuser
92+
93+# Builds the 'Dockerfile' into an image called 'wlwebsite'. This image can then
94+# be run which results in a container.
95+docker:
96+ docker build . -t wlwebsite \
97+ --build-arg UID=$(shell id -u) \
98+ --build-arg GID=$(shell id -g)
99+
100+# Runs ./run_docker.sh inside the container. See Dockerfile.
101+serve:
102+ $(DOCKER_RUN)
103+
104+# This will execute the CMD in the Dockerfile which runs the django debug server. Use like this:
105+# CMD="<cmd>" make cmd. For example
106+# CMD="find / | grep foo" make cmd
107+# lists all files that contain foo in their filename inside the container.
108+cmd:
109+ $(DOCKER_RUN) ${CMD}
110
111=== modified file 'pip_requirements.txt'
112--- pip_requirements.txt 2017-01-21 12:39:23 +0000
113+++ pip_requirements.txt 2017-02-11 21:31:29 +0000
114@@ -24,4 +24,3 @@
115 untokenize==0.1.1
116 -e git://github.com/kerin/django-sphinx.git#egg=django-sphinx
117 bleach==1.4.3
118-
119
120=== added file 'run_docker.sh'
121--- run_docker.sh 1970-01-01 00:00:00 +0000
122+++ run_docker.sh 2017-02-11 21:31:29 +0000
123@@ -0,0 +1,6 @@
124+#!/bin/sh
125+
126+Xvfb :99 -screen 0 1024x768x16 &> xvfb.log &
127+export DISPLAY=:99.0
128+
129+python manage.py runserver 0.0.0.0:8000
130
131=== modified file 'settings.py'
132--- settings.py 2017-01-21 12:39:23 +0000
133+++ settings.py 2017-02-11 21:31:29 +0000
134@@ -12,19 +12,6 @@
135
136 MANAGERS = ADMINS
137
138-DATABASES = {
139- 'default': {
140- 'ENGINE': 'django.db.backends.sqlite3',
141- 'NAME': 'dev.db',
142- 'USER': '', # Not used with sqlite3.
143- 'PASSWORD': '', # Not used with sqlite3.
144- # Set to empty string for localhost. Not used with sqlite3.
145- 'HOST': '',
146- # Set to empty string for default. Not used with sqlite3.
147- 'PORT': '',
148- }
149-}
150-
151 # Local time zone for this installation. Choices can be found here:
152 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
153 # although not all choices may be available on all operating systems.
154@@ -48,7 +35,7 @@
155
156 # Absolute path to the directory that holds media.
157 # Example: "/home/media/media.lawrence.com/"
158-MEDIA_ROOT = ''
159+MEDIA_ROOT = '/code/media_root'
160
161 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
162 # trailing slash if there is a path component (optional in other cases).
163@@ -245,7 +232,7 @@
164 ###############################
165 # Sphinx (Search prog) Config #
166 ###############################
167-USE_SPHINX = True
168+USE_SPHINX = False
169 SPHINX_API_VERSION = 0x116
170
171 ############

Subscribers

People subscribed via source and target branches