version: '3.7'

services:
  web:
    depends_on:
      server:
        condition: service_healthy

  server:
    tty: true
    depends_on:
      mysqldb:
        condition: service_healthy
      cache:
        condition: service_started
    build:
      context: .
      target: dev
    env_file:
      - .env
    restart: on-failure
    volumes:
      - ./:/app
      - /app/node_modules
    command: [ "bash", "-c", "./db_deploy.sh && npm run dev" ]

  mysqldb:
    tty: true
    restart: on-failure
    env_file:
      - .env
    volumes:
      - mysql_dev:/var/lib/mysql
    ports:
      - '$DB_PORT:3306'

  cache:
    tty: true
    restart: on-failure
    env_file:
      - .env
    ports:
      - '$REDIS_PORT:6379'
    volumes:
      - cache_dev:/data

volumes:
  mysql_dev:
    driver: local
  cache_dev:
    driver: local

networks:
  my_project:
    driver: bridge
