Skip to content

Commit 13e3747

Browse files
authored
fix(Template): Docker compose (#54)
1 parent 21fc0ce commit 13e3747

3 files changed

Lines changed: 21 additions & 48 deletions

File tree

fastapi_forge/template/{{cookiecutter.project_name}}/.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RELOAD=True
66
{{ cookiecutter.project_name|upper|replace('-', '_') }}_WORKERS=1
77
{% if cookiecutter.use_postgres %}
8-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_HOST={{ cookiecutter.project_name }}
8+
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_HOST={{ cookiecutter.project_name }}-pg
99
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_PORT=5432
1010
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_USER={{ cookiecutter.project_name }}
1111
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_PASSWORD={{ cookiecutter.project_name }}
@@ -29,4 +29,7 @@
2929
{%- if cookiecutter.use_builtin_auth %}
3030
{{ cookiecutter.project_name|upper|replace('-', '_') }}_JWT_SECRET="secret"
3131
{{ cookiecutter.project_name|upper|replace('-', '_') }}_JWT_ALGORITHM="HS256"
32+
{% endif %}
33+
{%- if cookiecutter.use_prometheus %}
34+
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PROMETHEUS_ENABLED=True
3235
{% endif %}

fastapi_forge/template/{{cookiecutter.project_name}}/docker-compose.yaml

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,10 @@ services:
2525
condition: service_healthy
2626
{%- endif %}
2727
{%- endif %}
28-
environment:
29-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RELOAD: "True"
30-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_SERVER_HOST: 0.0.0.0
31-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_SERVER_PORT: 8000
32-
{%- if cookiecutter.use_postgres %}
33-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_HOST: {{ cookiecutter.project_name }}-pg
34-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_PORT: 5432
35-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_USER: {{ cookiecutter.project_name }}
36-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_PASS: {{ cookiecutter.project_name }}
37-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PG_DATABASE: {{ cookiecutter.project_name }}
38-
{% endif %}
39-
{%- if cookiecutter.use_redis %}
40-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_REDIS_HOST: "redis"
41-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_REDIS_PORT: 6379
42-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_REDIS_PASSWORD: ""
43-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_REDIS_MAX_CONNECTIONS: 50
44-
{% endif %}
45-
{%- if cookiecutter.use_rabbitmq -%}
46-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RABBITMQ_HOST: "rabbitmq"
47-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RABBITMQ_PORT: 5672
48-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RABBITMQ_USER: "user"
49-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RABBITMQ_PASSWORD: "password"
50-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RABBITMQ_VHOST: "/"
51-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RABBITMQ_CONNECTION_POOL_SIZE: 2
52-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_RABBITMQ_CHANNEL_POOL_SIZE: 10
53-
{% endif %}
54-
{%- if cookiecutter.use_rabbitmq -%}
55-
{{ cookiecutter.project_name|upper|replace('-', '_') }}_PROMETHEUS_ENABLED: true
56-
{% endif %}
5728
{%- if cookiecutter.use_alembic %}
5829
volumes:
5930
- ./migrations:/app/migrations
60-
{% endif %}
31+
{%- endif %}
6132
develop:
6233
watch:
6334
- action: sync
@@ -66,31 +37,27 @@ services:
6637
- action: sync
6738
path: ./tests
6839
target: /app/tests
69-
{%- if cookiecutter.use_alembic %}
70-
- action: sync
71-
path: ./migrations
72-
target: /app/migrations
73-
{%- endif %}
7440
- action: rebuild
7541
path: pyproject.toml
7642
- action: rebuild
7743
path: uv.lock
78-
{% if cookiecutter.use_taskiq %}
44+
45+
{% if cookiecutter.use_taskiq -%}
7946
taskiq-worker:
8047
<<: *api
81-
container_name: game_zone-taskiq-worker
48+
container_name: {{ cookiecutter.project_name }}-taskiq-worker
8249
ports: []
8350
command: [ taskiq, worker, -fsd, src.services.taskiq.broker:broker, -w, "1", --max-fails, "1"]
8451

8552
taskiq-scheduler:
8653
<<: *api
87-
container_name: game_zone-taskiq-scheduler
54+
container_name: {{ cookiecutter.project_name }}-taskiq-scheduler
8855
ports: []
8956
command: [ taskiq, scheduler, -fsd, src.services.taskiq.scheduler:scheduler ]
90-
{%- endif %}
91-
{% if cookiecutter.use_postgres %}
57+
{% endif %}
58+
{%- if cookiecutter.use_postgres %}
9259
postgres:
93-
image: postgres:13.8-bullseye
60+
image: postgres:17.4-bookworm
9461
hostname: {{ cookiecutter.project_name }}-pg
9562
container_name: {{ cookiecutter.project_name }}-pg
9663
environment:
@@ -123,7 +90,7 @@ services:
12390
volumes:
12491
- {{ cookiecutter.project_name }}-redis-data:/bitnami/redis/data
12592
{% endif %}
126-
{%- if cookiecutter.use_rabbitmq -%}
93+
{% if cookiecutter.use_rabbitmq -%}
12794
rabbitmq:
12895
image: rabbitmq:3.8.27-management-alpine
12996
container_name: {{ cookiecutter.project_name }}-rabbitmq
@@ -142,9 +109,9 @@ services:
142109
volumes:
143110
- {{ cookiecutter.project_name }}-rabbitmq-data:/var/lib/rabbitmq
144111
{% endif %}
145-
{%- if cookiecutter.use_prometheus -%}
112+
{% if cookiecutter.use_prometheus -%}
146113
prometheus:
147-
image: prom/prometheus:latest
114+
image: prom/prometheus:v3.3.0
148115
restart: always
149116
volumes:
150117
- ./observability/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yaml
@@ -157,14 +124,11 @@ services:
157124
volumes:
158125
{%- if cookiecutter.use_postgres %}
159126
{{ cookiecutter.project_name }}-pg-data:
160-
name: {{ cookiecutter.project_name }}-pg-data
161127
{%- endif %}
162128
{%- if cookiecutter.use_redis %}
163129
{{ cookiecutter.project_name }}-redis-data:
164-
name: {{ cookiecutter.project_name }}-redis-data
165130
{% endif %}
166131
{%- if cookiecutter.use_rabbitmq -%}
167132
{{ cookiecutter.project_name }}-rabbitmq-data:
168-
name: {{ cookiecutter.project_name }}-rabbitmq-data
169133
{% endif %}
170134
{%- endif %}

fastapi_forge/template/{{cookiecutter.project_name}}/src/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ def get_app() -> FastAPI:
6262
{% if cookiecutter.use_alembic %}
6363
logger.info("Alembic enabled - see Makefile for migration commands")
6464
{% endif %}
65+
{%- if cookiecutter.use_prometheus %}
66+
logger.info(
67+
"Prometheus enabled - metrics available at /metrics, "
68+
"and queryable at localhost:9090"
69+
)
70+
{% endif %}
6571
app = FastAPI(lifespan=lifespan)
6672
add_middleware(app)
6773
app.include_router(base_router)

0 commit comments

Comments
 (0)