diff --git a/Makefile b/Makefile index 968638f6..6bf9b831 100644 --- a/Makefile +++ b/Makefile @@ -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 \ @@ -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 \ @@ -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) diff --git a/docker-compose.yml b/docker-compose.yml index eb5a7c69..68058cbe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -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: @@ -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" diff --git a/env.d/prefect b/env.d/prefect index a478e53d..263deba0 100644 --- a/env.d/prefect +++ b/env.d/prefect @@ -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 diff --git a/env.d/prefect-worker b/env.d/prefect-worker new file mode 100644 index 00000000..c411ee16 --- /dev/null +++ b/env.d/prefect-worker @@ -0,0 +1 @@ +PREFECT_API_URL=http://prefect:4200/api diff --git a/src/prefect/Dockerfile b/src/prefect/Dockerfile index 0d17d4f3..34289b4d 100644 --- a/src/prefect/Dockerfile +++ b/src/prefect/Dockerfile @@ -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