From 10474b2e47213552029e93e121e63593938d7cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 20 Sep 2024 16:17:24 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20prestart=20?= =?UTF-8?q?(migrations)=20to=20move=20them=20to=20its=20own=20container?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/Dockerfile | 2 ++ docker-compose.override.yml | 6 +++++- docker-compose.yml | 39 ++++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index c3187aeb28..716aa231ad 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -26,3 +26,5 @@ COPY ./prestart.sh /app/ COPY ./tests-start.sh /app/ COPY ./app /app/app + +CMD ["fastapi", "run", "--workers", "4", "app/main.py"] diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 55965e4cf1..eee222a399 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -67,7 +67,11 @@ services: args: INSTALL_DEV: ${INSTALL_DEV-true} # command: sleep infinity # Infinite loop to keep container alive doing nothing - command: /start-reload.sh + command: + - fastapi + - run + - --reload + - "app/main.py" environment: SMTP_HOST: "mailcatcher" SMTP_PORT: "1025" diff --git a/docker-compose.yml b/docker-compose.yml index d65519135d..44f8526c52 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,6 +42,41 @@ services: - traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.tls.certresolver=le - traefik.http.services.${STACK_NAME?Variable not set}-adminer.loadbalancer.server.port=8080 + prestart: + image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}' + build: + context: ./backend + args: + INSTALL_DEV: ${INSTALL_DEV-false} + networks: + - traefik-public + - default + depends_on: + db: + condition: service_healthy + restart: true + command: bash prestart.sh + env_file: + - .env + environment: + - DOMAIN=${DOMAIN} + - FRONTEND_HOST=${FRONTEND_HOST?Variable not set} + - ENVIRONMENT=${ENVIRONMENT} + - BACKEND_CORS_ORIGINS=${BACKEND_CORS_ORIGINS} + - SECRET_KEY=${SECRET_KEY?Variable not set} + - FIRST_SUPERUSER=${FIRST_SUPERUSER?Variable not set} + - FIRST_SUPERUSER_PASSWORD=${FIRST_SUPERUSER_PASSWORD?Variable not set} + - SMTP_HOST=${SMTP_HOST} + - SMTP_USER=${SMTP_USER} + - SMTP_PASSWORD=${SMTP_PASSWORD} + - EMAILS_FROM_EMAIL=${EMAILS_FROM_EMAIL} + - POSTGRES_SERVER=db + - POSTGRES_PORT=${POSTGRES_PORT} + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER?Variable not set} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD?Variable not set} + - SENTRY_DSN=${SENTRY_DSN} + backend: image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}' restart: always @@ -52,6 +87,8 @@ services: db: condition: service_healthy restart: true + prestart: + condition: service_completed_successfully env_file: - .env environment: @@ -88,7 +125,7 @@ services: - traefik.docker.network=traefik-public - traefik.constraint-label=traefik-public - - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=80 + - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=8000 - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=Host(`api.${DOMAIN?Variable not set}`) - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.entrypoints=http From 7d48edee933f4e4df1dee35beb9d0acd77367d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 20 Sep 2024 16:47:37 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=A7=20Tweak=20Docker=20Compose=20h?= =?UTF-8?q?ealthcheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 44f8526c52..ce92e3e3d7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -111,7 +111,7 @@ services: - SENTRY_DSN=${SENTRY_DSN} healthcheck: - test: ["CMD", "curl", "-f", "http://localhost/api/v1/utils/health-check/"] + test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1/utils/health-check/"] interval: 10s timeout: 5s retries: 5 From b90d95d143e817c25a14d19b146efb6b9b0e2c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 20 Sep 2024 17:02:13 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Update=20port=20for=20?= =?UTF-8?q?backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.override.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.override.yml b/docker-compose.override.yml index eee222a399..9257ab8aaa 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -59,7 +59,7 @@ services: restart: "no" ports: - "8888:8888" - - "8000:80" + - "8000:8000" volumes: - ./backend/:/app build: