services:
  extrudex-db:
    image: postgres:16-alpine
    container_name: extrudex-db
    environment:
      POSTGRES_USER: extrudex
      POSTGRES_PASSWORD: changeme
      POSTGRES_DB: extrudex
    ports:
      - "5433:5432"
    volumes:
      - extrudex-db-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U extrudex"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    restart: unless-stopped
    networks:
      - extrudex-network

  extrudex-api:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: extrudex-api
    ports:
      - "5080:8080"
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=http://+:8080
      - EXTRUDEX_DB_HOST=extrudex-db
      - EXTRUDEX_DB_PORT=5432
      - EXTRUDEX_DB_NAME=extrudex
      - EXTRUDEX_DB_USER=extrudex
      - EXTRUDEX_DB_PASSWORD=changeme
    depends_on:
      extrudex-db:
        condition: service_healthy
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - extrudex-network

  extrudex-web:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: extrudex-web
    ports:
      - "5081:80"
    depends_on:
      extrudex-api:
        condition: service_healthy
    restart: unless-stopped
    networks:
      - extrudex-network

volumes:
  extrudex-db-data:

networks:
  extrudex-network:
    driver: bridge