version: '2.4'

volumes:
  mysql_data:

networks:
  web:
    external:
      name: traefik_proxy

services:
  nginx:
    image: nginx:1-alpine
    working_dir: /app
    volumes:
      - ./:/app
      - ./tools/docker/images/nginx/configs/vhost.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      node:
        condition: service_started
      php:
        condition: service_started
    networks:
      default: {}
      web: {}
    labels:
      - traefik.docker.network=traefik_proxy
      - traefik.enable=true
      - traefik.http.routers.oliverdavies.rule=Host(`oliverdavies.docker.localhost`)

  php:
    build:
      context: .
      dockerfile: tools/docker/Dockerfile
      target: dev
    volumes:
      - ./:/app
    env_file:
      - .docker.env
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      default: {}
    labels:
      - "traefik.enable=false"

  mysql:
    image: mariadb:10
    volumes:
      - mysql_data:/var/lib/mysql
      - ./tools/docker/images/mysql/databases.sql:/docker-entrypoint-initdb.d/databases.sql
    env_file:
      - .docker.env
    healthcheck:
      test: ["CMD-SHELL", "bash", "-c", "echo > /dev/tcp/localhost/3306"]
      interval: 1s
    networks:
      default: {}
    labels:
      - "traefik.enable=false"

  node:
    image: node:12
    working_dir: /node
    volumes:
      - ./web:/node
    labels:
      - "traefik.enabled=false"