-
Everything is working great with this project except that apparently gunicorn is not able to survive from e.g. coding errors. App crashes -> I fix the error -> code changes are not being monitored anymore and app does not reload. As a workaround I have to manually restart the web container. Am I missing something here or could there be e.g. dev configuration for using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Here's my fix unless better solution is provided 😄
And then build image again. Obviously UPDATE: My previous solution will mess up the
And you're done. |
Beta Was this translation helpful? Give feedback.
-
I fine-tuned my original solution some more, will write it here, maybe someone finds it useful:
ENTRYPOINT ["/app/bin/docker-entrypoint-web"]
EXPOSE 8000
CMD ["gunicorn", "-c", "python:config.gunicorn", "config.wsgi"] to this: EXPOSE 8000
ENTRYPOINT ["/app/bin/docker-entrypoint-web"]
#!/usr/bin/env bash
set -e
# Always keep this here as it ensures your latest built assets make their way
# into your volume persisted public directory.
cp -r /public_collected /app
# Execute command that was passed from compose.yaml or from run script
# E.g. deps:install passes command `cd .. && bin/pip3-install`
# to `docker compose run`. It overrides whatever is defined in the compose
# file.
if [ "$#" -gt 0 ]; then
echo "Executing additional command: $*"
exec "$@" # Execute the provided command and exit
exit 1
fi
# If no commands are passed, check if DOCKER_ENV is set to 'development'
if [ "$DOCKER_ENV" = "development" ]; then
# Run the Django development server
echo "Running in development mode. Starting Django development server..."
exec python manage.py runserver 0.0.0.0:8000
else
# Run the Gunicorn server using config file from src/config/gunicorn.py
echo "Running in production mode. Starting Gunicorn server..."
exec gunicorn -c python:config.gunicorn config.wsgi
fi And that's it! With env variables, you can easily add more automation to if [ "$RUN_MIGRATIONS" = "true" ]; then
echo "Running migrations..."
until python manage.py migrate
do
echo "Waiting for db to be ready..."
sleep 2
done
fi |
Beta Was this translation helpful? Give feedback.
That is one way to solve it. The concern there is not using the same app server in development vs production. That's why I tend to stick with gunicorn in all environments although it shouldn't be too bad.
I'm not aware of too many other options unless you had a wrapper process start gunicorn which always stays up and then if it detects gunicorn went down it would restart it. Basically a process monitor.