version: '3.9'

services:
  # PostgreSQL-Datenbank
  postgres:
    image: postgres:17
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - /mnt/DockerMount/taskmanager/data:/var/lib/postgresql/data
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER}" ]
      interval: 60s
      timeout: 10s
      retries: 10
    networks:
      - taskflow-network

  # Backend und Frontend Anwendung
  app:
    image: registry.local.nothaft.cloud/taskflow:latest
    environment:
      NODE_ENV: production
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
      PORT: 5000
      SESSION_SECRET: ${SESSION_SECRET}
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test: [ "CMD", "node", "-e", "require('http').get('http://localhost:5000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - taskflow-network
      - proxy
    restart: unless-stopped
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.task.rule=Host(`task.local.nothaft.cloud`) || Host(`task.nothaft.cloud`)"
        - "traefik.http.routers.task.entrypoints=https"
        - "traefik.http.routers.task.tls.certresolver=dns"
        - "traefik.http.services.task.loadbalancer.server.port=5000"
        - "traefik.docker.network=proxy"
        - "homepage.group=Shared Services"
        - "homepage.name=Task Manager"
        - "homepage.icon=mdi-tasks"
        - "homepage.href=https://task.local.nothaft.cloud/"
        - "homepage.description=Task Manager"

networks:
  proxy:
    external: true
  taskflow-network:
