Skip to content

Commit

Permalink
fix(docker): properly propagate default ARG PORT
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vit-zikmund committed Mar 18, 2024
1 parent b15675c commit c65a00b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
.pytest_cache
.mypy_cache
/.idea
.tox
.make-cache
15 changes: 9 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 9 additions & 0 deletions scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c65a00b

Please sign in to comment.