Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork371
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
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 |
BetaWas this translation helpful?Give feedback.
All reactions
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.
Replies: 2 comments 2 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
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. |
BetaWas this translation helpful?Give feedback.
All reactions
-
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. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I fine-tuned my original solution some more, will write it here, maybe someone finds it useful:
ENTRYPOINT ["/app/bin/docker-entrypoint-web"]EXPOSE 8000CMD ["gunicorn","-c","python:config.gunicorn","config.wsgi"] to this: EXPOSE 8000ENTRYPOINT ["/app/bin/docker-entrypoint-web"]
#!/usr/bin/env bashset -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 ];thenecho"Executing additional command:$*"exec"$@"# Execute the provided command and exitexit 1fi# If no commands are passed, check if DOCKER_ENV is set to 'development'if ["$DOCKER_ENV"="development" ];then# Run the Django development serverecho"Running in development mode. Starting Django development server..."exec python manage.py runserver 0.0.0.0:8000else# Run the Gunicorn server using config file from src/config/gunicorn.pyecho"Running in production mode. Starting Gunicorn server..."exec gunicorn -c python:config.gunicorn config.wsgifi And that's it! With env variables, you can easily add more automation to if ["$RUN_MIGRATIONS"="true" ];thenecho"Running migrations..."until python manage.py migratedoecho"Waiting for db to be ready..." sleep 2donefi |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hi, yep that would work. Thanks for posting it. You can also consider piggy backing off I'd be careful about running migrations in an entrypoint btw. In certain runtime environments you might have multiple containers get started up. Technically the migration process is idempotent but I much prefer running tasks like that in a post-deploy hook. This way it only gets run once, no matter if you're using Docker Compose, Kubernetes with Helm / Argo CD or a managed provider like Heroku. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1