generated from br3ndonland/template-python
-
Notifications
You must be signed in to change notification settings - Fork 18
Add app modules, Gunicorn config, and start scripts #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Clarify instructions for running with mounted volume - Add instructions for hitting API endpoints
- identify 1.4.25 -> 1.4.26 - isort 5.3.2 -> 5.4.2
- Base (simple Uvicorn ASGI server) - FastAPI - Starlette
- This commit will refactor and translate the startup scripts from https://github.com/tiangolo/uvicorn-gunicorn-docker. - prestart.py will replace prestart.sh - start.py will replace start.sh and start-reload.sh
First argument must be a list, otherwise an error may be seen, like `bufsize must be an integer` (`bufsize` is the second argument).
- Create /app directory that will be overwritten by downstream images - Copy start.py and gunicorn_conf.py to root to avoid overwriting - Add PYTHONPATH=/app environment variable to simplify module paths - Don't install root package in Docker image: Poetry wasn't installing the project, even when running `poetry install` without `--no-root`. I don't really need the interlink package installed in the Docker image, because I'm changing the directory structure when copying it in. - Remove extra `RUN` commands: only need one in the base image.
- Improve wording and correct URLs in description - Expand instructions for using the images in a Dockerfile - Provide a more thorough explanation of how to hit API endpoints - Add "One programming language" note on pure Python
The container will now look for main.py and gunicorn_conf.py in: 1. /app/main.py or /app/gunicorn_conf.py 2. /app/app/main.py or /app/app/gunicorn_conf.py The order was reversed before.
Separate configuration options into general and Gunicorn/Uvicorn
It's getting a little long to be considered a quickstart.
There were app directories named inboard/fastapi and inboard/starlette. When running main.py files within the Docker containers, Python thought app/fastapi was FastAPI and app/starlette was Starlette. This commit will rename the directories to fastapibase and starlettebase to avoid further conflicts.
5d92088 Hopefully this prevents me from copying __pycache__ directories. https://docs.docker.com/engine/reference/builder/#dockerignore-file
Previously, the base main.py modules would always return f"Hello World,
from Uvicorn, Gunicorn, and Python {version}", even if Gunicorn wasn't
in use. This commit will update the base main.py modules to return
"Uvicorn" if Gunicorn isn't in use, or "Uvicorn, Gunicorn," if Gunicorn.
1 task
br3ndonland
added a commit
that referenced
this pull request
Apr 4, 2021
#2 #3 ff9155a The core logic for running the Uvicorn and Gunicorn+Uvicorn servers is located in start.py. The `start.start_server()` method is what actually starts the servers. Uvicorn and Gunicorn are configured differently, so and the `start.start_server()` method ended up getting quite complex in order to handle these differences. This commit will refactor the configuration options passed to Gunicorn and Uvicorn into separate functions. The result is a start script with the same programming API and almost exactly the same line length, but improved readability and separation of concerns. - Refactor Gunicorn and Uvicorn options into separate functions, `start.set_gunicorn_options()` and `start.set_uvicorn_options()`. - Remove `start.set_conf_path()`: this function was written in a general way to find either Gunicorn or logging configuration files. Starting with ff9155a, it became used only for Gunicorn configuration files. Now that the configuration options for Gunicorn are in a separate function, the logic from `set_conf_path()` can be moved there. - Simplify logger type annotations: simply `import logging` and annotate functions with `logging.Logger` instead of having a separate import for `from logging import Logger`. - Reorganize test_start.py to more clearly reflect order of start.py
1 task
br3ndonland
added a commit
that referenced
this pull request
Mar 6, 2022
#2 inboard optionally runs a pre-start script before starting the server. The path to a pre-start script can be specified with the environment variable `PRE_START_PATH`. If the environment variable is set to a nonzero value, inboard will run the script at the provided path, using the `subprocess` standard library package. Previously, if the script exited with an error, inboard would continue starting the server. However, it may be preferable to stop the server if the pre-start script fails. This commit will update the subprocess call to include `check=True`. If the pre-start script exits with an error, inboard will not start the server. The behavior of successful pre-start script runs will not change. However, failed pre-start script runs will now exit with error codes, and prevent the server from starting.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR will add main.py app modules for ASGI/Uvicorn, FastAPI, and Starlette, a gunicorn_conf.py Gunicorn configuration file, and prestart.py and start.py start scripts.
Changes
App modules
Gunicorn
Start scripts
subprocess.run()syntax (70dfe21)Related