|
1 | 1 | # {{cookiecutter.project_name}} |
2 | 2 |
|
| 3 | +This project was generated using fastapi_template. |
3 | 4 |
|
4 | | -Start a project with: |
| 5 | +## Poetry |
| 6 | + |
| 7 | +This project uses poetry. It's a modern dependency management |
| 8 | +tool. |
| 9 | + |
| 10 | +To run the project use this set of commands: |
5 | 11 |
|
6 | 12 | ```bash |
7 | | -docker-compose -f deploy/docker-compose.yml --project-directory . up |
| 13 | +poetry install |
| 14 | +poetry run python -m {{cookiecutter.project_name}} |
8 | 15 | ``` |
9 | 16 |
|
10 | | -If you want to develop in docker with autoreload, use this command: |
| 17 | +This will start the server on the configured host. |
| 18 | + |
| 19 | +You can find swagger documentation at `/api/docs`. |
| 20 | + |
| 21 | +You can read more about poetry here: https://python-poetry.org/ |
| 22 | + |
| 23 | +## Docker |
| 24 | + |
| 25 | +You can start the project with docker using this command: |
| 26 | + |
| 27 | +```bash |
| 28 | +docker-compose -f deploy/docker-compose.yml --project-directory . up --build |
| 29 | +``` |
| 30 | + |
| 31 | +If you want to develop in docker with autoreload add `-f deploy/docker-compose.dev.yml` to your docker command. |
| 32 | +Like this: |
11 | 33 |
|
12 | 34 | ```bash |
13 | 35 | docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up |
14 | 36 | ``` |
15 | 37 |
|
16 | | -This command exposes application on port 8000, mounts current directory and enables autoreload. |
| 38 | +This command exposes the web application on port 8000, mounts current directory and enables autoreload. |
17 | 39 |
|
18 | 40 | But you have to rebuild image every time you modify `poetry.lock` or `pyproject.toml` with this command: |
19 | 41 |
|
20 | 42 | ```bash |
21 | 43 | docker-compose -f deploy/docker-compose.yml --project-directory . build |
22 | 44 | ``` |
23 | 45 |
|
| 46 | +{%- if cookiecutter.otlp_enabled == "True" %} |
| 47 | +## Opentelemetry |
| 48 | + |
| 49 | +If you want to start your project with opentelemetry collector |
| 50 | +you can add `-f ./deploy/docker-compose.otlp.yml` to your docker command. |
| 51 | + |
| 52 | +Like this: |
| 53 | + |
| 54 | +```bash |
| 55 | +docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.otlp.yml --project-directory . up |
| 56 | +``` |
| 57 | + |
| 58 | +This command will start opentelemetry collector and jaeger. |
| 59 | +After sending a requests you can see traces in jaeger's UI |
| 60 | +at http://localhost:16686/. |
| 61 | + |
| 62 | +This docker configuration is not supposed to be used in production. |
| 63 | +It's only for demo purpose. |
| 64 | + |
| 65 | +You can read more about opentelemetry here: https://opentelemetry.io/ |
| 66 | +{%- endif %} |
| 67 | + |
| 68 | +## Configuration |
| 69 | + |
| 70 | +This application can be configured with environment variables. |
| 71 | + |
| 72 | +You can create `.env` file in the root directory and place all |
| 73 | +environment variables here. |
| 74 | + |
| 75 | +All environment variabels should start with "{{cookiecutter.project_name | upper}}_" prefix. |
| 76 | + |
| 77 | +For example if you see in your "{{cookiecutter.project_name}}/settings.py" a variable named like |
| 78 | +`random_parameter`, you should provide the "{{cookiecutter.project_name | upper}}_RANDOM_PARAMETER" |
| 79 | +variable to configure the value. |
| 80 | + |
| 81 | +An exmaple of .env file: |
| 82 | +```bash |
| 83 | +{{cookiecutter.project_name | upper}}_RELOAD="True" |
| 84 | +{{cookiecutter.project_name | upper}}_PORT="8000" |
| 85 | +{{cookiecutter.project_name | upper}}_ENVIRONMENT="dev" |
| 86 | +``` |
| 87 | + |
| 88 | +You can read more about BaseSettings class here: https://pydantic-docs.helpmanual.io/usage/settings/ |
24 | 89 |
|
25 | 90 | ## Pre-commit |
26 | 91 |
|
27 | 92 | To install pre-commit simply run inside the shell: |
28 | 93 | ```bash |
29 | 94 | pre-commit install |
30 | 95 | ``` |
| 96 | + |
| 97 | +pre-commit is very useful to check your code before publishing it. |
| 98 | +It's configured using .pre-commit-config.yaml file. |
| 99 | + |
| 100 | +By default it runs: |
| 101 | +* black (formats your code); |
| 102 | +* mypy (validates types); |
| 103 | +* isort (sorts imports in all files); |
| 104 | +* flake8 (spots possibe bugs); |
| 105 | +* yesqa (removes useless `# noqa` comments). |
| 106 | + |
| 107 | + |
| 108 | +You can read more about pre-commit here: https://pre-commit.com/ |
| 109 | + |
31 | 110 | {%- if cookiecutter.enable_kube == 'True' %} |
32 | 111 |
|
33 | 112 | ## Kubernetes |
|
0 commit comments