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:
- ./backend:/app/backend # Map backend directory to /app/backend
- ./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
working_dir: /app/backend # Set working directory to backend/
command: python main.py # Command to run main.py
@ -23,11 +23,11 @@ services:
timeout: 5s
retries: 5
environment: # ⬅️ Provide DB info to your backend
ENVIRONMENT: dev
DB_USERNAME: dev_user
DB_PASSWORD: dev_password
ENVIRONMENT: ${ENVIRONMENT}
DB_USERNAME: ${DB_USERNAME}
DB_PASSWORD: ${DB_PASSWORD}
DB_HOST: postgres
DB_NAME: aare_dev_db
DB_NAME: ${DB_NAME}
postgres: # ⬅️ New service (our PostgreSQL database)
image: postgres:16
@ -49,7 +49,7 @@ services:
context: ./frontend
dockerfile: Dockerfile
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_CERT_PATH=${VITE_SSL_CERT_PATH}
- NODE_ENV=${NODE_ENV}
@ -59,7 +59,7 @@ services:
- ./frontend:/app
- /app/node_modules # ⬅️ explicit exclusion! ensures Docker-provided modules retain explicitly.
- ./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"
@ -68,7 +68,7 @@ services:
context: ./logistics
dockerfile: Dockerfile
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_CERT_PATH=${VITE_SSL_CERT_PATH}
- NODE_ENV=${NODE_ENV}
@ -80,7 +80,7 @@ services:
- ./logistics/src:/app/src # explicitly for active dev (hot reload)
- ./backend/ssl:/app/backend/ssl # clearly mount SSL files explicitly into Docker
environment:
- VITE_OPENAPI_BASE_DEV=${VITE_OPENAPI_BASE_DEV}
- VITE_OPENAPI_BASE=${VITE_OPENAPI_BASE}
volumes: # ⬅️ Persistent storage for PostgreSQL data