version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: siged_app
    restart: unless-stopped
    working_dir: /app
    environment:
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_DATABASE=${DB_DATABASE}
      - DB_USERNAME=${DB_USERNAME}
      - DB_PASSWORD=${DB_PASSWORD}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - APP_ENV=${APP_ENV:-local}
      - APP_DEBUG=${APP_DEBUG:-true}
      - APP_KEY=${APP_KEY}
    volumes:
      - ./:/app
      - ./vendor:/app/vendor
      - ./storage:/app/storage
      - ./bootstrap:/app/bootstrap
    ports:
      - "9000:9000"
    depends_on:
      - mysql
      - redis
    networks:
      - siged-network

  mysql:
    image: mysql:8.0
    container_name: siged_mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
    ports:
      - "3306:3306"
    volumes:
      - dbdata:/var/lib/mysql
      - ./docker/mysql-init:/docker-entrypoint-initdb.d
    networks:
      - siged-network
    command: --default-authentication-plugin=mysql_native_password

  redis:
    image: redis:7-alpine
    container_name: siged_redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redisdata:/data
    networks:
      - siged-network

  nginx:
    image: nginx:alpine
    container_name: siged_nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./:/app
      - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf
      - ./docker/ssl:/etc/nginx/ssl
    depends_on:
      - app
    networks:
      - siged-network

volumes:
  dbdata:
    driver: local
  redisdata:
    driver: local

networks:
  siged-network:
    driver: bridge
