♻️ Refactor prestart (migrations), move that to its own container (#1350)

This commit is contained in:
Sebastián Ramírez
2024-09-20 17:12:40 +02:00
committed by GitHub
parent d87b6391b5
commit 8fe66c1cc1
3 changed files with 47 additions and 4 deletions

View File

@@ -26,3 +26,5 @@ COPY ./prestart.sh /app/
COPY ./tests-start.sh /app/ COPY ./tests-start.sh /app/
COPY ./app /app/app COPY ./app /app/app
CMD ["fastapi", "run", "--workers", "4", "app/main.py"]

View File

@@ -59,7 +59,7 @@ services:
restart: "no" restart: "no"
ports: ports:
- "8888:8888" - "8888:8888"
- "8000:80" - "8000:8000"
volumes: volumes:
- ./backend/:/app - ./backend/:/app
build: build:
@@ -67,7 +67,11 @@ services:
args: args:
INSTALL_DEV: ${INSTALL_DEV-true} INSTALL_DEV: ${INSTALL_DEV-true}
# command: sleep infinity # Infinite loop to keep container alive doing nothing # command: sleep infinity # Infinite loop to keep container alive doing nothing
command: /start-reload.sh command:
- fastapi
- run
- --reload
- "app/main.py"
environment: environment:
SMTP_HOST: "mailcatcher" SMTP_HOST: "mailcatcher"
SMTP_PORT: "1025" SMTP_PORT: "1025"

View File

@@ -42,6 +42,41 @@ services:
- traefik.http.routers.${STACK_NAME?Variable not set}-adminer-https.tls.certresolver=le - 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 - 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: backend:
image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}' image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
restart: always restart: always
@@ -52,6 +87,8 @@ services:
db: db:
condition: service_healthy condition: service_healthy
restart: true restart: true
prestart:
condition: service_completed_successfully
env_file: env_file:
- .env - .env
environment: environment:
@@ -74,7 +111,7 @@ services:
- SENTRY_DSN=${SENTRY_DSN} - SENTRY_DSN=${SENTRY_DSN}
healthcheck: 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 interval: 10s
timeout: 5s timeout: 5s
retries: 5 retries: 5
@@ -88,7 +125,7 @@ services:
- traefik.docker.network=traefik-public - traefik.docker.network=traefik-public
- traefik.constraint-label=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.rule=Host(`api.${DOMAIN?Variable not set}`)
- traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.entrypoints=http - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.entrypoints=http