Skip to content

Commit

Permalink
🔨(prefect) improve cross-service dependencies
Browse files Browse the repository at this point in the history
Having health checks on the prefect server avoids the worker to run and
fail when the server is not up yet.
  • Loading branch information
jmaupetit committed Nov 5, 2024
1 parent b4ac801 commit edf255c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bootstrap: ## bootstrap the project for development
bootstrap: \
build \
migrate-api \
migrate-prefect \
create-api-test-db \
create-metabase-db \
create-prefect-db \
Expand Down Expand Up @@ -207,6 +208,20 @@ migrate-api: ## run alembic database migrations for the api service
@bin/alembic upgrade head
.PHONY: migrate-api

migrate-prefect: ## run prefect database migrations
@echo "Running prefect service database engine…"
@$(COMPOSE_UP) --wait postgresql
@echo "Running migrations for prefect service…"
@$(COMPOSE_RUN_PREFECT_PIPENV) prefect server database upgrade -y
.PHONY: migrate-prefect

post-deploy-prefect: ## run prefect post-deployment script
@echo "Running prefect service…"
@$(COMPOSE_UP) --wait prefect
@echo "Running postdeploy script for prefect service…"
@$(COMPOSE) exec prefect pipenv run honcho start postdeploy
.PHONY: post-deploy-prefect

create-superuser: ## create super user
@echo "Creating super user…"
@$(COMPOSE_RUN_API_PIPENV) python -m qualicharge create-user \
Expand Down Expand Up @@ -236,6 +251,7 @@ reset-db: ## Reset the PostgreSQL database
$(MAKE) create-metabase-db
$(MAKE) seed-metabase
$(MAKE) create-prefect-db
$(MAKE) migrate-prefect
.PHONY: reset-db

seed-api: ## seed the API database (static data)
Expand Down
16 changes: 13 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ services:
environment:
NB_UID: ${DOCKER_UID:-1000}
NB_GID: ${DOCKER_GID:-1000}
CHOWN_HOME: 'yes'
CHOWN_HOME: "yes"
CHOWN_HOME_OPTS: -R
env_file:
- env.d/notebook
Expand Down Expand Up @@ -137,6 +137,15 @@ services:
env_file:
- env.d/prefect
- env.d/prefect-qc
healthcheck:
test:
- "CMD"
- "curl"
- "--fail"
- "http://localhost:4200/api/health"
interval: 2s
timeout: 5s
retries: 20
volumes:
- ./src/prefect:/app
depends_on:
Expand All @@ -147,12 +156,13 @@ services:
command: ["pipenv", "run", "honcho", "start", "worker"]
user: ${DOCKER_USER:-1000}
env_file:
- env.d/prefect
- env.d/prefect-worker
- env.d/prefect-qc
volumes:
- ./src/prefect:/app
depends_on:
- prefect
prefect:
condition: service_healthy

prefect-test:
image: "qualicharge:prefect"
Expand Down
2 changes: 1 addition & 1 deletion env.d/prefect
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ PREFECT_API_DATABASE_NAME=prefect
PREFECT_API_DATABASE_CONNECTION_URL=postgresql+asyncpg://qualicharge:pass@postgresql:5432/prefect
PREFECT_API_DATABASE_ECHO=False
PREFECT_API_DATABASE_MIGRATE_ON_START=False
PREFECT_API_URL=http://prefect:4200/api
PREFECT_API_URL=http://localhost:4200/api
PREFECT_SERVER_API_HOST=0.0.0.0
PREFECT_SERVER_ALLOW_EPHEMERAL_MODE=False
1 change: 1 addition & 0 deletions env.d/prefect-worker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PREFECT_API_URL=http://prefect:4200/api
1 change: 1 addition & 0 deletions src/prefect/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ARG DOCKER_GID 1000
# Upgrade system packages to install security updates
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y curl && \
rm -rf /var/lib/apt/lists/*

# Upgrade pip to its latest release to speed up dependencies
Expand Down

0 comments on commit edf255c

Please sign in to comment.