From f35550a9f450879a0a58087ff6cad72f4690de79 Mon Sep 17 00:00:00 2001 From: sushi-chaaaan Date: Wed, 15 May 2024 14:42:53 +0900 Subject: [PATCH] refactor(docker): use healthcheck for wait db setup --- compose.yml | 11 +++++++++-- migrate/Dockerfile | 7 +------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/compose.yml b/compose.yml index b422ba2..7d36098 100644 --- a/compose.yml +++ b/compose.yml @@ -8,13 +8,19 @@ services: POSTGRES_USER: postgres POSTGRES_PASSWORD: ${BX_STORAGE_SETTINGS__PASSWORD} POSTGRES_DB: postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 10s + timeout: 5s + retries: 5 ports: - '5432:5432' volumes: - postgres_data:/var/lib/postgresql/data app: depends_on: - - db + db: + condition: service_healthy build: args: - ENVIRONMENT=dev @@ -31,7 +37,8 @@ services: target: /app/api migrate: depends_on: - - db + db: + condition: service_healthy build: args: - ENVIRONMENT=dev diff --git a/migrate/Dockerfile b/migrate/Dockerfile index 0be3434..32e5ab1 100644 --- a/migrate/Dockerfile +++ b/migrate/Dockerfile @@ -14,8 +14,6 @@ COPY pyproject.toml README.md ./ COPY birdxplorer_migration/__init__.py ./birdxplorer_migration/ RUN pip install --no-cache-dir -e ".[${ENVIRONMENT}]" -COPY --from=ghcr.io/ufoscout/docker-compose-wait:latest /wait /wait - FROM python:${PYTHON_VERSION_CODE}-slim-bookworm as runner ARG PYTHON_VERSION_CODE @@ -25,10 +23,7 @@ RUN groupadd -r app && useradd -r -g app app RUN chown -R app:app /app USER app - -COPY --from=builder /wait /wait COPY --from=builder /usr/local/lib/python${PYTHON_VERSION_CODE}/site-packages /usr/local/lib/python${PYTHON_VERSION_CODE}/site-packages COPY --chown=app:app . ./ -ENV WAIT_COMMAND="python birdxplorer_migration/scripts/migrate_all.py birdxplorer_migration/data/appv1/" -ENTRYPOINT ["/wait"] +ENTRYPOINT ["python", "birdxplorer_migration/scripts/migrate_all.py", "birdxplorer_migration/data/appv1/"]