Refactor Docker setup and migrate to PostgreSQL

Streamlined Dockerfiles with clearer ENV variables and build args. Switched backend database from MySQL to PostgreSQL, updated configurations accordingly, and added robust Docker Compose services for better orchestration, including health checks and persistent storage.
This commit is contained in:
GotthardG
2025-04-09 22:39:53 +02:00
parent a4ed8259da
commit 39bdb735f5

View File

@ -11,7 +11,7 @@ services:
volumes: volumes:
- ./backend:/app/backend # Map backend directory to /app/backend - ./backend:/app/backend # Map backend directory to /app/backend
- ./app:/app/app # Map app directory to /app/app - ./app:/app/app # Map app directory to /app/app
- ./config_dev.json:/app/backend/config_dev.json # Explicitly map config_dev.json - ./config_${ENVIRONMENT}.json:/app/backend/config_${ENVIRONMENT}.json # Explicitly map config_dev.json
- ./backend/ssl:/app/backend/ssl # clearly mount SSL files explicitly into Docker - ./backend/ssl:/app/backend/ssl # clearly mount SSL files explicitly into Docker
working_dir: /app/backend # Set working directory to backend/ working_dir: /app/backend # Set working directory to backend/
command: python main.py # Command to run main.py command: python main.py # Command to run main.py
@ -23,11 +23,11 @@ services:
timeout: 5s timeout: 5s
retries: 5 retries: 5
environment: # ⬅️ Provide DB info to your backend environment: # ⬅️ Provide DB info to your backend
ENVIRONMENT: dev ENVIRONMENT: ${ENVIRONMENT}
DB_USERNAME: dev_user DB_USERNAME: ${DB_USERNAME}
DB_PASSWORD: dev_password DB_PASSWORD: ${DB_PASSWORD}
DB_HOST: postgres DB_HOST: postgres
DB_NAME: aare_dev_db DB_NAME: ${DB_NAME}
postgres: # ⬅️ New service (our PostgreSQL database) postgres: # ⬅️ New service (our PostgreSQL database)
image: postgres:16 image: postgres:16
@ -49,7 +49,7 @@ services:
context: ./frontend context: ./frontend
dockerfile: Dockerfile dockerfile: Dockerfile
args: args:
- VITE_OPENAPI_BASE_DEV=${VITE_OPENAPI_BASE_DEV} - VITE_OPENAPI_BASE=${VITE_OPENAPI_BASE}
- VITE_SSL_KEY_PATH=${VITE_SSL_KEY_PATH} - VITE_SSL_KEY_PATH=${VITE_SSL_KEY_PATH}
- VITE_SSL_CERT_PATH=${VITE_SSL_CERT_PATH} - VITE_SSL_CERT_PATH=${VITE_SSL_CERT_PATH}
- NODE_ENV=${NODE_ENV} - NODE_ENV=${NODE_ENV}
@ -59,7 +59,7 @@ services:
- ./frontend:/app - ./frontend:/app
- /app/node_modules # ⬅️ explicit exclusion! ensures Docker-provided modules retain explicitly. - /app/node_modules # ⬅️ explicit exclusion! ensures Docker-provided modules retain explicitly.
- ./backend/ssl:/app/backend/ssl - ./backend/ssl:/app/backend/ssl
- ./backend/config_dev.json:/app/backend/config_${ENVIRONMENT}.json # Dynamically maps config based on environment - ./backend/config_${ENVIRONMENT}.json:/app/backend/config_${ENVIRONMENT}.json # Dynamically maps config based on environment
command: sh -c "npm run dev & ENVIRONMENT=dev npm run watch:openapi" command: sh -c "npm run dev & ENVIRONMENT=dev npm run watch:openapi"
@ -68,7 +68,7 @@ services:
context: ./logistics context: ./logistics
dockerfile: Dockerfile dockerfile: Dockerfile
args: # 👈 explicitly pass build args from .env args: # 👈 explicitly pass build args from .env
- VITE_OPENAPI_BASE_DEV=${VITE_OPENAPI_BASE_DEV} - VITE_OPENAPI_BASE=${VITE_OPENAPI_BASE}
- VITE_SSL_KEY_PATH=${VITE_SSL_KEY_PATH} - VITE_SSL_KEY_PATH=${VITE_SSL_KEY_PATH}
- VITE_SSL_CERT_PATH=${VITE_SSL_CERT_PATH} - VITE_SSL_CERT_PATH=${VITE_SSL_CERT_PATH}
- NODE_ENV=${NODE_ENV} - NODE_ENV=${NODE_ENV}
@ -80,7 +80,7 @@ services:
- ./logistics/src:/app/src # explicitly for active dev (hot reload) - ./logistics/src:/app/src # explicitly for active dev (hot reload)
- ./backend/ssl:/app/backend/ssl # clearly mount SSL files explicitly into Docker - ./backend/ssl:/app/backend/ssl # clearly mount SSL files explicitly into Docker
environment: environment:
- VITE_OPENAPI_BASE_DEV=${VITE_OPENAPI_BASE_DEV} - VITE_OPENAPI_BASE=${VITE_OPENAPI_BASE}
volumes: # ⬅️ Persistent storage for PostgreSQL data volumes: # ⬅️ Persistent storage for PostgreSQL data