[PATCH 1/2] tools: add arguments for home directory and tag in a dockerfile

Stephen Finucane stephen at that.guru
Fri Nov 1 08:56:59 AEDT 2024


On Tue, 2024-10-29 at 19:09 +0000, Herakliusz Lipiec wrote:
> Currently to change the home directory for docker image it has
> to be changed in many places. Dockerfile allows for use of
> arguments and env variables, by using those now it can be changed
> by passing arguments to docker-compose. Also adding TAG argument
> for the same reason.

Could I ask why you want to do this? Changing the tag shouldn't be necessary,
since 'latest' should always contain the runtimes needed to test Patchwork.
Similarly, there should be no need to customise the directory that Patchwork
runs under since those paths are relative to the container, not the host? I
don't have a Mac to test this on, but this feels like a local configuration
issue more so than anything else?  We could probably remove the 'PROJECT_HOME'
configuration variable though since it's not used any more ('git log -S
PROJECT_HOME' shows I should have removed it in commit a0db473213 some time
back).

Cheers,
Stephen

> 
> Signed-off-by: Herakliusz Lipiec <hero24 at icloud.com>
> ---
>  docker-compose-pg.yml      |  2 ++
>  docker-compose-sqlite3.yml |  2 ++
>  docker-compose.yml         |  2 ++
>  tools/docker/Dockerfile    | 10 ++++++----
>  tools/docker/entrypoint.sh |  9 +++++----
>  5 files changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/docker-compose-pg.yml b/docker-compose-pg.yml
> index 44bc3ec..a9593bd 100644
> --- a/docker-compose-pg.yml
> +++ b/docker-compose-pg.yml
> @@ -15,6 +15,8 @@ services:
>        args:
>          - UID
>          - GID
> +        - TAG
> +        - PATCHWORK_DIR
>      depends_on:
>        - db
>      volumes:
> diff --git a/docker-compose-sqlite3.yml b/docker-compose-sqlite3.yml
> index 900cb71..d26e74b 100644
> --- a/docker-compose-sqlite3.yml
> +++ b/docker-compose-sqlite3.yml
> @@ -7,6 +7,8 @@ services:
>        args:
>          - UID
>          - GID
> +        - TAG
> +        - PATCHWORK_DIR
>      command: python3 manage.py runserver 0.0.0.0:8000
>      volumes:
>        - .:/home/patchwork/patchwork/
> diff --git a/docker-compose.yml b/docker-compose.yml
> index 73f080a..f6a59b2 100644
> --- a/docker-compose.yml
> +++ b/docker-compose.yml
> @@ -20,6 +20,8 @@ services:
>        args:
>          - UID
>          - GID
> +        - TAG
> +        - PATCHWORK_DIR
>      depends_on:
>        - db
>      volumes:
> diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
> index 0a55b54..4a18c44 100644
> --- a/tools/docker/Dockerfile
> +++ b/tools/docker/Dockerfile
> @@ -1,12 +1,14 @@
> -FROM ghcr.io/getpatchwork/pyenv:latest
> +ARG TAG="latest"
> +FROM ghcr.io/getpatchwork/pyenv:${TAG}
>  
>  ARG UID=1000
>  ARG GID=1000
> -
> +ARG PATCHWORK_DIR="/home/patchwork/patchwork"
>  ARG TZ="Australia/Canberra"
> +
>  ENV DEBIAN_FRONTEND noninteractive
>  ENV PYTHONUNBUFFERED 1
> -ENV PROJECT_HOME /home/patchwork/patchwork
> +ENV PROJECT_HOME ${PATCHWORK_DIR}
>  ENV DJANGO_SETTINGS_MODULE patchwork.settings.dev
>  
>  RUN groupadd --gid=$GID patchwork && \
> @@ -38,4 +40,4 @@ COPY tools/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
>  ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
>  CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
>  USER patchwork
> -WORKDIR /home/patchwork/patchwork
> +WORKDIR $PATCHWORK_DIR
> diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh
> index c78c058..5a4085d 100755
> --- a/tools/docker/entrypoint.sh
> +++ b/tools/docker/entrypoint.sh
> @@ -5,6 +5,7 @@ export DATABASE_HOST=${DATABASE_HOST:-}
>  export DATABASE_PORT=${DATABASE_PORT:-}
>  export DATABASE_USER=${DATABASE_USER:-patchwork}
>  export DATABASE_PASSWORD=${DATABASE_PASSWORD:-password}
> +export PROJECT_HOME=${PROJECT_HOME:-/home/patchwork/patchwork/}
>  
>  case "${DATABASE_TYPE:-}" in
>  postgres)
> @@ -40,13 +41,13 @@ test_database() {
>  
>  # check if patchwork is mounted. Checking if we exist is a
>  # very good start!
> -if [ ! -f ~patchwork/patchwork/tools/docker/entrypoint.sh ]; then
> +if [ ! -f $PROJECT_HOME/tools/docker/entrypoint.sh ]; then
>      cat << EOF
>  The patchwork directory doesn't seem to be mounted!
>  
>  Are you using docker-compose? If so, you may need to create an SELinux rule.
>  Refer to the development installation documentation for more information.
> -If not, you need -v PATH_TO_PATCHWORK:/home/patchwork/patchwork
> +If not, you need -v PATH_TO_PATCHWORK:$PROJECT_HOME
>  EOF
>      exit 1
>  fi
> @@ -55,7 +56,7 @@ set +e
>  
>  # check if we need to rebuild because requirements changed
>  for x in /opt/requirements-*.txt; do
> -    if ! cmp $x ~/patchwork/$(basename $x); then
> +    if ! cmp $x $PROJECT_HOME/$(basename $x); then
>          cat << EOF
>  A requirements file has changed.
>  
> @@ -63,7 +64,7 @@ You may need to rebuild the patchwork image:
>  
>      docker-compose build web
>  EOF
> -        diff -u $x ~/patchwork/$(basename $x)
> +        diff -u $x $PROJECT_HOME/$(basename $x)
>      fi
>  done
>  



More information about the Patchwork mailing list