Skip to content

Commit 98abead

Browse files
committed
docker-compose: Switch to 3.0 syntax
Ubuntu 18.04 (Bionic Beaver) providers 'docker-compose' 1.17.1 [1] at release which supports the 3.0 syntax [2]. Using this allows some users (me) to resolve a long standing issue caused by a UID that's not 1000. [1] https://packages.ubuntu.com/bionic/docker-compose [2] https://docs.docker.com/compose/compose-file/ Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 7484a8c commit 98abead

5 files changed

Lines changed: 86 additions & 86 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ htmlcov/
5252

5353
# Patchwork configuration files
5454
patchwork/settings/production.py
55+
56+
# docker-compose configuration files
57+
/.env

docker-compose-pg.yml

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
# the version of docker-compose shipped in ubuntu 16.04 is
2-
# 1.5.2, which doesn't support version 2 syntax. Yay!
3-
# also, v1 doesn't support explicit build args, so if you're not
4-
# uid 1000, you will either need to manually hack the Dockerfile
5-
# or upgrade to v2 and use the build-arg to override it.
1+
version: "3"
2+
services:
3+
db:
4+
image: postgres:9.6
5+
volumes:
6+
- ./tools/docker/db/postdata:/var/lib/postgresql/data
7+
environment:
8+
- POSTGRES_PASSWORD=password
69

7-
db:
8-
image: postgres:9.6
9-
environment:
10-
- POSTGRES_PASSWORD=password
11-
volumes:
12-
- ./tools/docker/db/postdata:/var/lib/postgresql/data
13-
14-
web:
15-
build: .
16-
dockerfile: ./tools/docker/Dockerfile
17-
command: python3 manage.py runserver 0.0.0.0:8000
18-
volumes:
19-
- .:/home/patchwork/patchwork/
20-
ports:
21-
- "8000:8000"
22-
links:
23-
- db
24-
environment:
25-
- PGPASSWORD=password
26-
- PW_TEST_DB_HOST=db
27-
- PW_TEST_DB_PORT=5432
28-
- PW_TEST_DB_TYPE=postgres
29-
- PW_TEST_DB_USER=postgres
30-
- PW_TEST_DB_PASS=password
10+
web:
11+
build:
12+
context: .
13+
dockerfile: ./tools/docker/Dockerfile
14+
args:
15+
- UID
16+
command: python3 manage.py runserver 0.0.0.0:8000
17+
volumes:
18+
- .:/home/patchwork/patchwork/
19+
ports:
20+
- "8000:8000"
21+
# TODO(stephenfin): links are deprecated and should be replaced
22+
# with user-defined networks
23+
links:
24+
- db
25+
environment:
26+
- UID
27+
- PGPASSWORD=password
28+
- PW_TEST_DB_HOST=db
29+
- PW_TEST_DB_PORT=5432
30+
- PW_TEST_DB_TYPE=postgres
31+
- PW_TEST_DB_USER=postgres
32+
- PW_TEST_DB_PASS=password

docker-compose.yml

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
# the version of docker-compose shipped in ubuntu 16.04 is
2-
# 1.5.2, which doesn't support version 2 syntax. Yay!
3-
# also, v1 doesn't support explicit build args, so if you're not
4-
# uid 1000, you will either need to manually hack the Dockerfile
5-
# or upgrade to v2 and use the build-arg to override it.
1+
version: "3"
2+
services:
3+
db:
4+
image: mysql:5.7
5+
volumes:
6+
- ./tools/docker/db/data:/var/lib/mysql
7+
environment:
8+
- MYSQL_ROOT_PASSWORD=password
9+
- MYSQL_USER=patchwork
10+
- MYSQL_PASSWORD=password
611

7-
db:
8-
image: mysql:5.7
9-
volumes:
10-
- ./tools/docker/db/data:/var/lib/mysql
11-
environment:
12-
- MYSQL_ROOT_PASSWORD=password
13-
- MYSQL_USER=patchwork
14-
- MYSQL_PASSWORD=password
15-
16-
web:
17-
build: .
18-
dockerfile: ./tools/docker/Dockerfile
19-
command: python3 manage.py runserver 0.0.0.0:8000
20-
volumes:
21-
- .:/home/patchwork/patchwork/
22-
ports:
23-
- "8000:8000"
24-
links:
25-
- db
26-
environment:
27-
- PW_TEST_DB_HOST=db
28-
- PW_TEST_DB_PORT=3306
12+
web:
13+
build:
14+
context: .
15+
dockerfile: ./tools/docker/Dockerfile
16+
args:
17+
- UID
18+
command: python3 manage.py runserver 0.0.0.0:8000
19+
volumes:
20+
- .:/home/patchwork/patchwork/
21+
ports:
22+
- "8000:8000"
23+
# TODO(stephenfin): links are deprecated and should be replaced
24+
# with user-defined networks
25+
links:
26+
- db
27+
environment:
28+
- UID
29+
- PW_TEST_DB_HOST=db
30+
- PW_TEST_DB_PORT=3306

docs/development/installation.rst

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,22 @@ Patchwork provides a Docker-based environment for quick configuration of a
1919
development environment. This is the preferred installation method. To
2020
configure Patchwork using Docker:
2121

22-
1. Install `docker`_ and `docker-compose`_.
22+
#. Install `docker`_ and `docker-compose`_.
2323

24-
2. Build the images. This will download over 200MB from the internet:
24+
#. Create a ``.env`` file in the root directory of the project and store your
25+
``UID`` attribute there.
26+
27+
.. code-block:: shell
28+
29+
$ echo "UID=$UID" > .env
30+
31+
#. Build the images. This will download over 200MB from the internet:
2532

2633
.. code-block:: shell
2734
2835
$ docker-compose build
2936
30-
3. Run `docker-compose up`:
37+
#. Run ``docker-compose up``:
3138

3239
.. code-block:: shell
3340
@@ -118,38 +125,18 @@ For more information on Docker itself, please refer to the `docker`_ and
118125

119126
If you see an error like the below::
120127

121-
py.error.EACCES: [Permission denied]: open('/home/patchwork/patchwork/.tox/py27-django18/.tox-config1', 'w')
122-
123-
your host user account is likely using a different UID to the one hardcoded
124-
in the Dockerfile. You can confirm this like so:
128+
You must define UID in .env
125129

126-
.. code-block:: shell
127-
128-
$ echo $UID
129-
1234
130-
131-
If this is anything other than `1000`, you must must modify the `Dockerfile`
132-
found in `tools/docker` to use your UID and then rebuild:
133-
134-
.. code-block:: shell
130+
Ensure you have created a ``.env`` file in the root of your project
131+
directory and stored the ``UID`` attribute there. For more information on
132+
why this is necessary, refer to this `docker-compose issue`__.
135133

136-
$ sed -i "/ARG UID=/c\ARG UID=$(echo $UID)" tools/docker/Dockerfile
137-
$ docker-compose build web
138-
139-
This change must be retained in the event that you rebuild the container.
140-
You can "hide" the change from Git like so:
141-
142-
.. code-block:: shell
143-
144-
$ git update-index --assume-unchanged tools/docker/Dockerfile
145-
$ git update-index --skip-worktree tools/docker/Dockerfile
146-
147-
This should be resolved in a future release when we support docker-compose
148-
2.1 syntax in `docker-compose.yml`.
134+
__ https://github.com/docker/compose/issues/2380
149135

150136
.. _docker: https://docs.docker.com/compose/install/
151137
.. _docker-compose: https://docs.docker.com/engine/installation/linux/
152138

139+
153140
Manual Installation
154141
-------------------
155142

@@ -375,6 +362,7 @@ using the aptly-named `createsuperuser` command:
375362
376363
(.venv)$ ./manage.py createsuperuser
377364
365+
378366
Import Mailing List Archives
379367
----------------------------
380368
@@ -429,6 +417,7 @@ script again.
429417
430418
__ http://blog.behnel.de/posts/indexp118.html
431419
420+
432421
Django Debug Toolbar
433422
--------------------
434423
@@ -437,6 +426,7 @@ by default this is only displayed if you are developing on localhost. If
437426
developing on a different machine, you should configure an SSH tunnel such
438427
that, for example, `localhost:8000` points to `[DEV_MACHINE_IP]:8000`.
439428
429+
440430
.. _dev-envvar:
441431
442432
Environment Variables

tools/docker/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
FROM ubuntu:17.10
22

3-
ARG UID=1000
3+
ARG UID
44
ARG TZ="Australia/Canberra"
55

6+
RUN echo $UID
7+
RUN [ -n "$UID" ] || { echo "You must define UID in .env" 1>&2; exit 1; }
8+
69
ENV PROJECT_HOME /home/patchwork/patchwork
710

811
ENV db_user root

0 commit comments

Comments
 (0)