services:
  db:
    image: postgres:17-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-wedding}
      POSTGRES_USER: ${POSTGRES_USER:-wedding}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-wedding} -d ${POSTGRES_DB:-wedding}"]
      interval: 5s
      timeout: 5s
      retries: 10

  backend:
    image: 192.168.31.100:3847/arrelin/wedding-backend:latest
    environment:
      DATABASE_URL: postgres://${POSTGRES_USER:-wedding}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-wedding}
      PORT: 8080
      RUST_LOG: ${RUST_LOG:-info}
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped
    labels:
      - traefik.enable=true
      - 'traefik.http.routers.wedding-backend.rule=Host(`weddinge.duckdns.org`) && PathPrefix(`/api`)'
      - traefik.http.routers.wedding-backend.entrypoints=https
      - traefik.http.routers.wedding-backend.tls=true
      - traefik.http.routers.wedding-backend.tls.certresolver=letsencrypt
      - traefik.http.services.wedding-backend.loadbalancer.server.port=8080
      - traefik.http.routers.wedding-backend.priority=10

  frontend:
    image: 192.168.31.100:3847/arrelin/wedding-frontend:latest
    depends_on:
      - backend
    restart: unless-stopped
    labels:
      - traefik.enable=true
      - 'traefik.http.routers.wedding-frontend.rule=Host(`weddinge.duckdns.org`)'
      - traefik.http.routers.wedding-frontend.entrypoints=https
      - traefik.http.routers.wedding-frontend.tls=true
      - traefik.http.routers.wedding-frontend.tls.certresolver=letsencrypt
      - traefik.http.services.wedding-frontend.loadbalancer.server.port=80
      - traefik.http.routers.wedding-frontend.priority=1

volumes:
  postgres_data:
