]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
docker-compose: Switch to 3.0 syntax
authorStephen Finucane <stephen@that.guru>
Tue, 17 Apr 2018 08:58:00 +0000 (09:58 +0100)
committerStephen Finucane <stephen@that.guru>
Thu, 26 Apr 2018 09:47:02 +0000 (10:47 +0100)
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>
.gitignore
docker-compose-pg.yml
docker-compose.yml
docs/development/installation.rst
tools/docker/Dockerfile

index 04b66702ba2f58819d7401ffc8d5d90ad30d0546..f37caccf5f784025bedd79715742392832d2b216 100644 (file)
@@ -52,3 +52,6 @@ htmlcov/
 
 # Patchwork configuration files
 patchwork/settings/production.py
+
+# docker-compose configuration files
+/.env
index 81dde3e534cab7d8aef9bb84239b20b10f93b073..e403547cae6fa79fbeff7064c744424719848fc8 100644 (file)
@@ -1,30 +1,32 @@
-# the version of docker-compose shipped in ubuntu 16.04 is
-# 1.5.2, which doesn't support version 2 syntax. Yay!
-# also, v1 doesn't support explicit build args, so if you're not
-# uid 1000, you will either need to manually hack the Dockerfile
-# or upgrade to v2 and use the build-arg to override it.
+version: "3"
+services:
+  db:
+    image: postgres:9.6
+    volumes:
+      - ./tools/docker/db/postdata:/var/lib/postgresql/data
+    environment:
+      - POSTGRES_PASSWORD=password
 
-db:
-  image: postgres:9.6
-  environment:
-    - POSTGRES_PASSWORD=password
-  volumes:
-    - ./tools/docker/db/postdata:/var/lib/postgresql/data
-
-web:
-  build: .
-  dockerfile: ./tools/docker/Dockerfile
-  command: python3 manage.py runserver 0.0.0.0:8000
-  volumes:
-    - .:/home/patchwork/patchwork/
-  ports:
-    - "8000:8000"
-  links:
-    - db
-  environment:
-    - PGPASSWORD=password
-    - PW_TEST_DB_HOST=db
-    - PW_TEST_DB_PORT=5432
-    - PW_TEST_DB_TYPE=postgres
-    - PW_TEST_DB_USER=postgres
-    - PW_TEST_DB_PASS=password
+  web:
+    build:
+      context: .
+      dockerfile: ./tools/docker/Dockerfile
+      args:
+        - UID
+    command: python3 manage.py runserver 0.0.0.0:8000
+    volumes:
+      - .:/home/patchwork/patchwork/
+    ports:
+      - "8000:8000"
+    # TODO(stephenfin): links are deprecated and should be replaced
+    # with user-defined networks
+    links:
+      - db
+    environment:
+      - UID
+      - PGPASSWORD=password
+      - PW_TEST_DB_HOST=db
+      - PW_TEST_DB_PORT=5432
+      - PW_TEST_DB_TYPE=postgres
+      - PW_TEST_DB_USER=postgres
+      - PW_TEST_DB_PASS=password
index 47786eca98367f995a9465191fbad5136419ab9a..18d60b7ba689c80252c18f4df8a8114a1c54633b 100644 (file)
@@ -1,28 +1,30 @@
-# the version of docker-compose shipped in ubuntu 16.04 is
-# 1.5.2, which doesn't support version 2 syntax. Yay!
-# also, v1 doesn't support explicit build args, so if you're not
-# uid 1000, you will either need to manually hack the Dockerfile
-# or upgrade to v2 and use the build-arg to override it.
+version: "3"
+services:
+  db:
+    image: mysql:5.7
+    volumes:
+      - ./tools/docker/db/data:/var/lib/mysql
+    environment:
+      - MYSQL_ROOT_PASSWORD=password
+      - MYSQL_USER=patchwork
+      - MYSQL_PASSWORD=password
 
-db:
-  image: mysql:5.7
-  volumes:
-    - ./tools/docker/db/data:/var/lib/mysql
-  environment:
-    - MYSQL_ROOT_PASSWORD=password
-    - MYSQL_USER=patchwork
-    - MYSQL_PASSWORD=password
-
-web:
-  build: .
-  dockerfile: ./tools/docker/Dockerfile
-  command: python3 manage.py runserver 0.0.0.0:8000
-  volumes:
-    - .:/home/patchwork/patchwork/
-  ports:
-    - "8000:8000"
-  links:
-    - db
-  environment:
-    - PW_TEST_DB_HOST=db
-    - PW_TEST_DB_PORT=3306
+  web:
+    build:
+      context: .
+      dockerfile: ./tools/docker/Dockerfile
+      args:
+        - UID
+    command: python3 manage.py runserver 0.0.0.0:8000
+    volumes:
+      - .:/home/patchwork/patchwork/
+    ports:
+      - "8000:8000"
+    # TODO(stephenfin): links are deprecated and should be replaced
+    # with user-defined networks
+    links:
+      - db
+    environment:
+      - UID
+      - PW_TEST_DB_HOST=db
+      - PW_TEST_DB_PORT=3306
index f2ed0f2dd5646f45c26eb58fb7f7766f578c0c62..f857ff6f1fbcbb9a8ba3b448d68f01e3c807ca69 100644 (file)
@@ -19,15 +19,22 @@ Patchwork provides a Docker-based environment for quick configuration of a
 development environment. This is the preferred installation method. To
 configure Patchwork using Docker:
 
-1. Install `docker`_ and `docker-compose`_.
+#. Install `docker`_ and `docker-compose`_.
 
-2. Build the images. This will download over 200MB from the internet:
+#. Create a ``.env`` file in the root directory of the project and store your
+   ``UID`` attribute there.
+
+   .. code-block:: shell
+
+      $ echo "UID=$UID" > .env
+
+#. Build the images. This will download over 200MB from the internet:
 
    .. code-block:: shell
 
       $ docker-compose build
 
-3. Run `docker-compose up`:
+#. Run ``docker-compose up``:
 
    .. code-block:: shell
 
@@ -118,38 +125,18 @@ For more information on Docker itself, please refer to the `docker`_ and
 
    If you see an error like the below::
 
-     py.error.EACCES: [Permission denied]: open('/home/patchwork/patchwork/.tox/py27-django18/.tox-config1', 'w')
-
-   your host user account is likely using a different UID to the one hardcoded
-   in the Dockerfile.  You can confirm this like so:
+     You must define UID in .env
 
-   .. code-block:: shell
-
-      $ echo $UID
-      1234
-
-   If this is anything other than `1000`, you must must modify the `Dockerfile`
-   found in `tools/docker` to use your UID and then rebuild:
-
-   .. code-block:: shell
+   Ensure you have created a ``.env`` file in the root of your project
+   directory and stored the ``UID`` attribute there. For more information on
+   why this is necessary, refer to this `docker-compose issue`__.
 
-      $ sed -i "/ARG UID=/c\ARG UID=$(echo $UID)" tools/docker/Dockerfile
-      $ docker-compose build web
-
-   This change must be retained in the event that you rebuild the container.
-   You can "hide" the change from Git like so:
-
-   .. code-block:: shell
-
-      $ git update-index --assume-unchanged tools/docker/Dockerfile
-      $ git update-index --skip-worktree tools/docker/Dockerfile
-
-   This should be resolved in a future release when we support docker-compose
-   2.1 syntax in `docker-compose.yml`.
+   __ https://github.com/docker/compose/issues/2380
 
 .. _docker: https://docs.docker.com/compose/install/
 .. _docker-compose: https://docs.docker.com/engine/installation/linux/
 
+
 Manual Installation
 -------------------
 
@@ -375,6 +362,7 @@ using the aptly-named `createsuperuser` command:
 
    (.venv)$ ./manage.py createsuperuser
 
+
 Import Mailing List Archives
 ----------------------------
 
@@ -429,6 +417,7 @@ script again.
 
 __ http://blog.behnel.de/posts/indexp118.html
 
+
 Django Debug Toolbar
 --------------------
 
@@ -437,6 +426,7 @@ by default this is only displayed if you are developing on localhost. If
 developing on a different machine, you should configure an SSH tunnel such
 that, for example, `localhost:8000` points to `[DEV_MACHINE_IP]:8000`.
 
+
 .. _dev-envvar:
 
 Environment Variables
index 109410bb1ff4c71a53440320b777539d3c2759ae..e25c381c8613b9f3b1ad20e811aa49b861cddf9f 100644 (file)
@@ -1,8 +1,11 @@
 FROM ubuntu:17.10
 
-ARG UID=1000
+ARG UID
 ARG TZ="Australia/Canberra"
 
+RUN echo $UID
+RUN [ -n "$UID" ] || { echo "You must define UID in .env" 1>&2; exit 1; }
+
 ENV PROJECT_HOME /home/patchwork/patchwork
 
 ENV db_user root