Skip to content

Commit fd71c89

Browse files
committed
dev: update Dockerfile/docker-compose development environment setup
1 parent 54d7cb0 commit fd71c89

File tree

9 files changed

+95
-10
lines changed

9 files changed

+95
-10
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ RUN apt-get update && \
77
rm -rf /var/lib/apt/lists/*
88

99
RUN mkdir /code
10+
RUN mkdir /config
11+
RUN mkdir /static
1012
WORKDIR /code
1113
COPY requirements.txt requirements_dev.txt /code/
1214
RUN pip install -r requirements_dev.txt
1315
RUN pip install psycopg2-binary==2.8.4
1416
COPY . /code/
17+
COPY pytition/pytition/settings/config_example.py /config/docker_config.py
18+
RUN touch /config/__init__.py
19+
RUN /code/dev/generate_docker_config.sh

dev/generate_docker_config.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
SECRET_KEY=$(python3 -c "from django.core.management.utils import get_random_secret_key as g; print(g())")
3+
sed -i -e '/SECRET_KEY/d' /config/docker_config.py
4+
sed -i -e '/DATABASES/d' /config/docker_config.py
5+
sed -i -e '/STATIC_ROOT/d' /config/docker_config.py
6+
echo "SECRET_KEY = \"${SECRET_KEY}\"" >> /config/docker_config.py
7+
echo "STATIC_ROOT = \"/static/\"" >> /config/docker_config.py
8+
echo "DEBUG = True" >> /config/docker_config.py
9+
echo "ALLOWED_HOSTS.append('0.0.0.0')" >> /config/docker_config.py

dev/initialize.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ echo "Running database migrations"
44

55
cd pytition && python3 ./manage.py migrate && cd -
66

7+
echo "Installing static files"
8+
9+
cd pytition && python3 ./manage.py collectstatic && cd -
10+
11+
echo "Generating translation files"
12+
13+
cd pytition && python3 ./manage.py compilemessages && cd -
14+
715
echo "Creating superuser account"
816

917
cd pytition && python3 ./manage.py createsuperuser && cd -

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#
1313
import os
1414
import sys
15-
sys.path.insert(0, os.path.abspath('..'))
15+
sys.path.insert(0, os.path.abspath('../pytition'))
1616
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "_ext")))
1717

1818
# -- Project information -----------------------------------------------------

doc/configuration.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Configuration
22
*************
33

4-
A configuration example is provided in `pytition/pytition/settings/config_example.py`.
4+
A configuration example is provided in `pytition/settings/config_example.py`.
55
You should copy and edit it to configure Pytition.
66

77

@@ -10,7 +10,7 @@ Mandatory settings
1010

1111
You **must** set the following variables:
1212

13-
.. automodule:: pytition.pytition.settings.config_example
13+
.. automodule:: pytition.settings.config_example
1414
:members:
1515

1616

@@ -22,8 +22,8 @@ You are **highly encouraged** to set the following variables in a production env
2222
Pytition specific settings
2323
--------------------------
2424

25-
.. autodata:: pytition.pytition.settings.base.USE_MAIL_QUEUE
26-
.. autodata:: pytition.pytition.settings.base.ALLOW_REGISTER
25+
.. autodata:: pytition.settings.base.USE_MAIL_QUEUE
26+
.. autodata:: pytition.settings.base.ALLOW_REGISTER
2727

2828
Django settings
2929
---------------
@@ -48,5 +48,5 @@ Other optional settings
4848

4949
Those are things you can configure to customize your Pytition instance:
5050

51-
.. autodata:: pytition.pytition.settings.base.SITE_NAME
52-
.. autodata:: pytition.pytition.settings.base.FOOTER_TEMPLATE
51+
.. autodata:: pytition.settings.base.SITE_NAME
52+
.. autodata:: pytition.settings.base.FOOTER_TEMPLATE

doc/installation.rst

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Installation
22
************
33

4-
Manual installation (recommended)
5-
=================================
4+
Manual installation (recommended for production)
5+
================================================
66

77
Install system dependencies:
88

@@ -228,3 +228,59 @@ Start uwsgi and nginx servers:
228228
Your Pytition home page should be available over there: http://mydomain.tld
229229

230230
Now it's time to :ref:`Configure<Configuration>` your Pytition instance the way you want!
231+
232+
Installation via Docker (recommended for development)
233+
=====================================================
234+
235+
.. warning:: Please, do **NOT** use this in production. You would have tons of security and performance issues. You could lose your SECRET_KEY, you would run with Django's DEBUG setting enabled, you would be serving static files via Django basic webserver. You would be running with no HTTPS possibility at all. etc etc. Please : don't.
236+
237+
Clone latest development version of Pytition:
238+
239+
.. code-block:: bash
240+
241+
$ git clone https://github.com/pytition/pytition
242+
243+
Install docker and docker-compose:
244+
245+
.. code-block:: bash
246+
247+
$ sudo apt install docker.io docker-compose
248+
249+
Put your user in the docker group (needed for Ubuntu 18.04) and start docker daemon:
250+
251+
.. code-block:: bash
252+
253+
$ sudo usermod -a -G docker $USER
254+
$ # log-in again as your user for group change to take effect
255+
$ # or just type the following line
256+
$ su -l $USER
257+
$ sudo systemctl enable docker
258+
$ sudo systemctl start docker
259+
260+
For the first run you need to create the database container and let it be ready:
261+
262+
.. code-block:: bash
263+
264+
$ docker-compose up --build db
265+
266+
Wait until it prints something like::
267+
268+
LOG: database system is ready to accept connections
269+
270+
Then hit ^C (ctrl+C) to shutdown the database container.
271+
272+
From now on, you can just type this to run Pytition in a container:
273+
274+
.. code-block:: bash
275+
276+
$ docker-compose up --build
277+
278+
Last command before being able to click on the "http://0.0.0.0:8000/" link that the "web" container prints to out on the console. You need to run migrations, install static files, compile language files, create an admin account and lastly populate your database with some dummy data. You can do all of this with the `dev/initialize.sh` script:
279+
280+
.. code-block:: bash
281+
282+
$ docker-compose exec web ./dev/initialize.sh
283+
284+
Aaaand that's it! You can now just click on the "http://0.0.0.0:8000/" link!
285+
286+
Next time, just run ``$ docker-compose up --build``

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ version: '3'
33
services:
44
db:
55
image: postgres
6+
environment:
7+
- POSTGRES_USER=postgres
8+
- POSTGRES_PASSWORD=postgres
69
web:
10+
environment:
11+
- DJANGO_SETTINGS_MODULE=config.docker_config
12+
- PYTHONPATH=/
713
build: .
814
command: python pytition/manage.py runserver 0.0.0.0:8000
915
volumes:

pytition/pytition/settings/config_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .base import *
1+
from pytition.settings.base import *
22

33
# 1/ The following settings MUST be set
44

pytition/pytition/settings/pgsql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'ENGINE': 'django.db.backends.postgresql',
55
'NAME': 'postgres',
66
'USER': 'postgres',
7+
'PASSWORD': 'postgres',
78
'HOST': 'db',
89
'PORT': 5432,
910
}

0 commit comments

Comments
 (0)