Skip to content

Commit 32dc086

Browse files
committed
Add reload option to dev.start
1 parent 38f593f commit 32dc086

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

development/docker-compose.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,6 @@ services:
116116
target: backend
117117
image: "${IMAGE_NAME}:${IMAGE_VER}"
118118
pull_policy: always
119-
command: >
120-
gunicorn --config backend/infrahub/serve/gunicorn_config.py -w ${WEB_CONCURRENCY:-4} --logger-class infrahub.serve.log.GunicornLogger infrahub.server:app
121-
depends_on:
122-
database:
123-
condition: service_healthy
124-
message-queue:
125-
condition: service_healthy
126-
cache:
127-
condition: service_healthy
128-
task-manager:
129-
condition: service_healthy
130119
environment:
131120
<<: *infrahub_config
132121
INFRAHUB_INTERNAL_ADDRESS: "http://server:8000"
@@ -145,6 +134,19 @@ services:
145134
INFRAHUB_DB_PORT: 7687
146135
INFRAHUB_DB_PROTOCOL: bolt
147136
INFRAHUB_STORAGE_DRIVER: local
137+
# INFRAHUB_SERVER_COMMAND is defined while running with reload option as it requires to run server using `uvicorn`.
138+
COMMAND: ${INFRAHUB_SERVER_COMMAND:- gunicorn --config backend/infrahub/serve/gunicorn_config.py -w ${WEB_CONCURRENCY:-4} --logger-class infrahub.serve.log.GunicornLogger infrahub.server:app}
139+
command: >
140+
sh -c "$$COMMAND"
141+
depends_on:
142+
database:
143+
condition: service_healthy
144+
message-queue:
145+
condition: service_healthy
146+
cache:
147+
condition: service_healthy
148+
task-manager:
149+
condition: service_healthy
148150
volumes:
149151
- "storage_data:/opt/infrahub/storage"
150152
tty: true

tasks/dev.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
from typing import TYPE_CHECKING
45

56
from invoke.tasks import task
@@ -172,8 +173,16 @@ def status(
172173

173174

174175
@task(optional=["database"])
175-
def start(context: Context, database: str = INFRAHUB_DATABASE, wait: bool = False) -> None:
176+
def start(context: Context, database: str = INFRAHUB_DATABASE, wait: bool = False, reload: bool = False) -> None:
176177
"""Start a local instance of Infrahub within docker compose."""
178+
179+
if reload:
180+
# Need to use `uvicorn` instead of `gunicorn` for reload option because of this issue:
181+
# https://github.com/benoitc/gunicorn/issues/2339
182+
os.environ["INFRAHUB_SERVER_COMMAND"] = (
183+
"uvicorn infrahub.server:app --host 0.0.0.0 --port 8000 --workers 4 --timeout-keep-alive 90 --reload"
184+
)
185+
177186
start_services(context=context, database=database, namespace=NAMESPACE, wait=wait)
178187

179188

0 commit comments

Comments
 (0)