version: '3.8'

services:
  postgres:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: url_db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
    ports:
      - "5431:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - app-network

  backend:
    image: ctwj/urldb-backend:1.3.0
    environment:
      DB_HOST: postgres
      DB_PORT: 5432
      DB_USER: postgres
      DB_PASSWORD: password
      DB_NAME: url_db
      PORT: 8080
      TIMEZONE: Asia/Shanghai
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - ./uploads:/root/uploads
    networks:
      - app-network

  frontend:
    image: ctwj/urldb-frontend:1.3.0
    environment:
      NODE_ENV: production
      NUXT_PUBLIC_API_SERVER: http://backend:8080/api
    depends_on:
      - backend
    networks:
      - app-network

  nginx:
    image: nginx:alpine
    ports:
      - "3030:80"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/conf.d:/etc/nginx/conf.d:ro
    depends_on:
      - backend
      - frontend
    networks:
      - app-network
    restart: unless-stopped

volumes:
  postgres_data:

networks:
  app-network:
    driver: bridge 