From c65a00bf16374520e8d9550d151dd437575674e2 Mon Sep 17 00:00:00 2001 From: Vit Zikmund Date: Mon, 18 Mar 2024 12:53:53 +0100 Subject: [PATCH 1/2] fix(docker): properly propagate default ARG PORT Shell parameter expansion doesn't happen inside the CMD array, one either needs to pass an ENV var and use it in an entrypoint shell script or, if one doesn't want to pollute the container's env space, modify the argument (with sed) within the entrypoint itself. Also ignore a couple fat directories that complicate local development. --- .dockerignore | 2 ++ Dockerfile | 15 +++++++++------ scripts/docker-entrypoint.sh | 9 +++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 scripts/docker-entrypoint.sh diff --git a/.dockerignore b/.dockerignore index 799025e..9391b47 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,3 +7,5 @@ .pytest_cache .mypy_cache /.idea +.tox +.make-cache \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 93bf9fb..ebd3ee2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,18 +49,21 @@ RUN chown $USER_NAME $STORAGE_DIR ARG EXTRA_PACKAGES="wsgi_cors_middleware" RUN pip install ${EXTRA_PACKAGES} -USER $USER_NAME - WORKDIR /app ENV UWSGI_MODULE "giftless.wsgi_entrypoint" ARG PORT=5000 EXPOSE $PORT +# embed the default port into docker-entrypoint.sh, and make it executable +RUN set -eu ;\ + de=scripts/docker-entrypoint.sh ;\ + sed -i "/^default_port=/s/5000/$PORT/" "$de" ;\ + chmod +x "$de" + +USER $USER_NAME + +ENTRYPOINT ["tini", "--", "scripts/docker-entrypoint.sh"] -ENTRYPOINT ["tini", "uwsgi", "--"] # TODO remove this STOPSIGNAL override after uwsgi>=2.1 STOPSIGNAL SIGQUIT - -CMD ["-s", "127.0.0.1:${PORT}", "-M", "-T", "--threads", "2", "-p", "2", \ - "--manage-script-name", "--callable", "app"] diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh new file mode 100644 index 0000000..793cd09 --- /dev/null +++ b/scripts/docker-entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh +default_port=5000 +if [ $# -eq 0 ]; then + # listen on localhost:PORT by default + exec uwsgi -s "127.0.0.1:$default_port" -M -T --threads 2 -p 2 --manage-script-name --callable app +else + # use custom arguments + exec uwsgi "$@" +fi \ No newline at end of file From bc5ef89f088e133f39bc50993b77f11e7179b6a0 Mon Sep 17 00:00:00 2001 From: Vit Zikmund Date: Thu, 28 Mar 2024 13:19:24 +0100 Subject: [PATCH 2/2] chore(dockerfile): fix default port to 5000 Making it configurable via a build arg complicates the whole dockerfile setup way too much for such a useless feature :) --- Dockerfile | 16 +++++----------- scripts/docker-entrypoint.sh | 9 --------- 2 files changed, 5 insertions(+), 20 deletions(-) delete mode 100644 scripts/docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index ebd3ee2..6b2f7d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,21 +49,15 @@ RUN chown $USER_NAME $STORAGE_DIR ARG EXTRA_PACKAGES="wsgi_cors_middleware" RUN pip install ${EXTRA_PACKAGES} +USER $USER_NAME + WORKDIR /app ENV UWSGI_MODULE "giftless.wsgi_entrypoint" -ARG PORT=5000 -EXPOSE $PORT -# embed the default port into docker-entrypoint.sh, and make it executable -RUN set -eu ;\ - de=scripts/docker-entrypoint.sh ;\ - sed -i "/^default_port=/s/5000/$PORT/" "$de" ;\ - chmod +x "$de" - -USER $USER_NAME - -ENTRYPOINT ["tini", "--", "scripts/docker-entrypoint.sh"] +ENTRYPOINT ["tini", "uwsgi", "--"] +CMD ["-s", "127.0.0.1:5000", "-M", "-T", "--threads", "2", "-p", "2", \ + "--manage-script-name", "--callable", "app"] # TODO remove this STOPSIGNAL override after uwsgi>=2.1 STOPSIGNAL SIGQUIT diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh deleted file mode 100644 index 793cd09..0000000 --- a/scripts/docker-entrypoint.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -default_port=5000 -if [ $# -eq 0 ]; then - # listen on localhost:PORT by default - exec uwsgi -s "127.0.0.1:$default_port" -M -T --threads 2 -p 2 --manage-script-name --callable app -else - # use custom arguments - exec uwsgi "$@" -fi \ No newline at end of file