networks:
  tckdev_net:
    name: tckdev_net

services:
  app:
    container_name: tckdev-app
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./src:/var/www/html
      - /etc/localtime:/etc/localtime:ro
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - tckdev_net
    restart: unless-stopped
    environment:
      - TZ=Asia/Kuala_Lumpur
      - RUN_MIGRATIONS=true
      - RUN_SEEDER=true
      - ADMIN_EMAIL=${ADMIN_EMAIL:-admin@example.com}
      - ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin123}

  postgres:
    container_name: tckdev-db
    image: postgres:16
    restart: always
    volumes:
      - pgdata:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - TZ=Asia/Kuala_Lumpur
      - PGTZ=Asia/Kuala_Lumpur
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    ports:
      - "5432:5432"
    networks:
      - tckdev_net
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-tck} -d ${POSTGRES_DB:-sides_db}"]
      interval: 5s
      timeout: 5s
      retries: 5

  web:
    container_name: tckdev-web
    image: nginx:stable-alpine
    restart: always
    ports:
      - "80:80"
    volumes:
      - ./src:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
      - /etc/localtime:/etc/localtime:ro
    depends_on:
      - app
    networks:
      - tckdev_net
    environment:
      - TZ=Asia/Kuala_Lumpur

  pgadmin:
    image: dpage/pgadmin4
    container_name: tckdev-pgAdmin
    environment:
      - TZ=Asia/Kuala_Lumpur
      - PGADMIN_DEFAULT_EMAIL=${PGADMIN_EMAIL}
      - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PASSWORD}
    volumes:
      - pgadmin_data:/var/lib/pgadmin
      - ./backup:/backups
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "5050:80"
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - tckdev_net
    restart: unless-stopped

volumes:
  pgdata:
  pgadmin_data:
