version: '3'

services:
  web:
    build:
      context: ./docker/apache
      args:
        APACHE_SERVER_NAME: ${SERVER_NAME}
    ports:
      - "${WEB_PORT}:80"
    volumes:
      - "${VOLUME_PATH}:/var/www/html"
    networks:
      app:
        aliases:
            - ${SERVER_NAME}
      traefik: {}
    labels:
      - traefik.enable=true
      - traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(`${SERVER_NAME}`)

  php-fpm:
    build:
      context: ./docker/php-fpm
      args:
        WWW_USER_ID: ${WWW_USER_ID}
    tty: true
    volumes:
      - "${VOLUME_PATH}:/var/www/html"
    networks:
      - app

  workspace:
    build:
      context: docker/workspace
      args:
        WWW_USER_ID: ${WWW_USER_ID}
    environment:
      COMPOSER_MEMORY_LIMIT: -1
      CHOKIDAR_USEPOLLING: 1
    tty: true
    ports:
      - "3000:3000"
      - "3001:3001"
    volumes:
      - "${VOLUME_PATH}:/var/www/html"
      - ~/.composer/cache:/home/app/.composer/cache
    networks:
      - app

  mysql:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: "root"
      MYSQL_DATABASE: "${DB_DATABASE}"
      MYSQL_USER: "${DB_USERNAME}"
      MYSQL_PASSWORD: "${DB_PASSWORD}"
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    ports:
      - "${DB_PORT}:3306"
    volumes:
      - data-mysql:/var/lib/mysql
    networks:
      - app

  redis:
    image: redis:alpine
    volumes:
      - data-redis:/data
    networks:
      - app

networks:
  app: {}
  traefik:
    external:
      name: traefik

volumes:
  data-mysql: {}
  data-redis: {}
