Skip to content

Commit

Permalink
Better docker development tools (#318)
Browse files Browse the repository at this point in the history
* Easier docker based development

- allow for UID/GID of user to be determined at image build time
- allow passing in --reload and change log level for gunicorn
- provide a new venueless command `devel` that is used for starting
  in reloading mode

* Add Makefile to buld local docker image
  • Loading branch information
norbusan authored Feb 15, 2025
1 parent c9c58c3 commit 2d0f43d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM python:3.11-bookworm
ARG UID=15371
ARG GID=15371

RUN curl -sL https://deb.nodesource.com/setup_20.x | bash && \
apt-get install -y --install-suggests \
Expand All @@ -23,7 +25,8 @@ RUN curl -sL https://deb.nodesource.com/setup_20.x | bash && \
mkdir /etc/venueless && \
mkdir -p /venueless/webapp && \
mkdir /data && \
useradd -ms /bin/bash -d /venueless -u 15371 venueless && \
groupadd -g $GID venueless && \
useradd -ms /bin/bash -d /venueless -u $UID -g venueless venueless && \
echo 'venueless ALL=(ALL) NOPASSWD:SETENV: /usr/bin/supervisord' >> /etc/sudoers && \
mkdir /static

Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

local:
docker buildx build --progress=plain -f Dockerfile --platform=linux/amd64 \
--build-arg UID=`id -u` --build-arg GID=`id -g` \
-t eventyay/eventyay-video:local .
26 changes: 24 additions & 2 deletions prod/entrypoint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ export VENUELESS_DATA_DIR=/data/
export HOME=/venueless
export NUM_WORKERS=${VENUELESS_WORKERS:-$((2 * $(nproc --all)))}

GUNICORN_RELOAD="${GUNICORN_RELOAD:-false}"
GUNICORN_LOGLEVEL="${GUNICORN_LOGLEVEL:-info}"

if [ "$GUNICORN_RELOAD" = "true" ]; then
RELOAD_ARGUMENT="--reload"
else
RELOAD_ARGUMENT=""
fi

if [ ! -d /data/logs ]; then
mkdir /data/logs;
fi
Expand All @@ -17,17 +26,30 @@ if [ "$1" == "all" ]; then
exec sudo -E /usr/bin/supervisord -n -c /etc/supervisord.conf
fi

# for in-docker development, we want logging to be debug, and
# gunicorn to reload when source files have changed.
if [ "$1" == "devel" ]; then
python3 manage.py migrate --noinput
export GUNICORN_LOGLEVEL=debug
export GUNICORN_RELOAD=true
exec sudo -E /usr/bin/supervisord -n -c /etc/supervisord.conf
fi

if [ "$1" == "celery" ]; then
exec celery -A venueless.celery_app worker -l info
fi

if [ "$1" == "webworker" ]; then
mkdir -p /tmp/venueless
exec gunicorn -k uvicorn.workers.UvicornWorker --bind unix:/tmp/venueless/websocket.sock -w "$NUM_WORKERS" venueless.asgi:application
exec gunicorn -k uvicorn.workers.UvicornWorker \
--bind unix:/tmp/venueless/websocket.sock \
$RELOAD_ARGUMENT \
--log-level="${GUNICORN_LOGLEVEL}" \
-w "$NUM_WORKERS" venueless.asgi:application
fi

if [ "$1" == "shell" ]; then
exec python3 manage.py shell_plus
fi

exec python3 manage.py "$@"
exec python3 manage.py "$@"

0 comments on commit 2d0f43d

Please sign in to comment.