[PATCH 4/6] docker-compose: Switch to 3.0 syntax
Daniel Axtens
dja at axtens.net
Tue May 1 02:41:52 AEST 2018
Stephen Finucane <stephen at that.guru> writes:
> 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/
> ---
> .gitignore | 3 ++
> docker-compose-pg.yml | 60 ++++++++++++++++++++-------------------
> docker-compose.yml | 56 ++++++++++++++++++------------------
> docs/development/installation.rst | 48 +++++++++++++------------------
> tools/docker/Dockerfile | 5 +++-
> 5 files changed, 86 insertions(+), 86 deletions(-)
>
> diff --git a/.gitignore b/.gitignore
> index 04b66702..f37caccf 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -52,3 +52,6 @@ htmlcov/
>
> # Patchwork configuration files
> patchwork/settings/production.py
> +
> +# docker-compose configuration files
> +/.env
> diff --git a/docker-compose-pg.yml b/docker-compose-pg.yml
> index 81dde3e5..e403547c 100644
> --- a/docker-compose-pg.yml
> +++ b/docker-compose-pg.yml
> @@ -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
Somehow this seems to be breaking auth:
db_1 | FATAL: password authentication failed for user "postgres"
db_1 | DETAIL: Password does not match for user "postgres".
db_1 | Connection matched pg_hba.conf line 95: "host all all all md5"
Does this occur for you? Any thoughts on what might have changed?
Regards,
Daniel
>
> -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
> diff --git a/docker-compose.yml b/docker-compose.yml
> index 47786eca..18d60b7b 100644
> --- a/docker-compose.yml
> +++ b/docker-compose.yml
> @@ -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
> diff --git a/docs/development/installation.rst b/docs/development/installation.rst
> index f2ed0f2d..f857ff6f 100644
> --- a/docs/development/installation.rst
> +++ b/docs/development/installation.rst
> @@ -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
> diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
> index 109410bb..e25c381c 100644
> --- a/tools/docker/Dockerfile
> +++ b/tools/docker/Dockerfile
> @@ -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
> --
> 2.14.3
>
> _______________________________________________
> Patchwork mailing list
> Patchwork at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/patchwork
More information about the Patchwork
mailing list