version: '3.8'

services:
  web:
    image: nginx:1.23-alpine
    container_name: toby-web
    working_dir: /application
    volumes:
      - ./environment/dev/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
      - .:/application
    networks:
      - toby-dev
    ports:
      - ${EXTERNAL_WEBSERVER_PORT:-80}:80
    restart: unless-stopped
    depends_on:
      - php
      - database

  php:
    build:
      context: environment/dev/php
      args:
        INSTALL_XDEBUG: ${DOCKER_INSTALL_XDEBUG:-false}
    container_name: toby-php
    working_dir: /application
    user: ${CURRENT_UID:-1000}
    volumes:
      - .:/application
      - ./environment/dev/php/php.ini:/usr/local/etc/php/conf.d/php.ini
    networks:
      - toby-dev
    extra_hosts:
      - host.docker.internal:host-gateway
    restart: unless-stopped

  database:
    image: postgres:14
    container_name: toby-db-dev
    environment:
      - PGPASSWORD=${DOCKER_DEV_DB_ROOT_PASSWORD}
      - POSTGRES_DB=${DOCKER_DEV_DB_DATABASE}
      - POSTGRES_USER=${DOCKER_DEV_DB_USERNAME}
      - POSTGRES_PASSWORD=${DOCKER_DEV_DB_PASSWORD}
    ports:
      - ${DOCKER_DEV_DB_EXTERNAL_PORT:-5432}:5432
    volumes:
      - toby-pgsql-data:/var/lib/postgresql/data
    networks:
      - toby-dev
    restart: unless-stopped

  database-test:
    image: postgres:14
    container_name: toby-db-test
    environment:
      - PGPASSWORD=${DOCKER_TEST_DB_ROOT_PASSWORD}
      - POSTGRES_DB=${DOCKER_TEST_DB_DATABASE}
      - POSTGRES_USER=${DOCKER_TEST_DB_USERNAME}
      - POSTGRES_PASSWORD=${DOCKER_TEST_DB_PASSWORD}
    ports:
      - ${DOCKER_TEST_DB_EXTERNAL_PORT:-5433}:5432
    networks:
      - toby-dev
    restart: unless-stopped

  redis:
    image: redis:7
    container_name: toby-redis
    ports:
      - ${FORWARD_REDIS_PORT:-6379}:6379
    volumes:
      - toby-redis-data:/data
    networks:
      - toby-dev
    restart: unless-stopped

  node:
    image: node:18.4.0-alpine3.16
    container_name: toby-node
    working_dir: /application
    volumes:
      - .:/application
    networks:
      - toby-dev
    restart: unless-stopped

  mailhog:
    image: mailhog/mailhog:v1.0.1
    container_name: toby-mailhog
    ports:
      - ${MAIL_PORT}:1025
      - ${MAILHOG_DASHBOARD_PORT}:8025
    networks:
      - toby-dev
    restart: unless-stopped

  selenium:
    image: selenium/standalone-chrome
    container_name: toby-selenium
    volumes:
      - /dev/shm:/dev/shm
    networks:
      - toby-dev
    restart: unless-stopped

networks:
  toby-dev:
    driver: bridge

volumes:
  toby-pgsql-data:
    name: toby-pgsql-data
  toby-redis-data:
    name: toby-redis-data
