version: '3.8'

x-common-variables: &common-variables
  MYSQL_DATABASE: livequiz
  MYSQL_USER: server
  MYSQL_PASSWORD: server

services:

  mysql_db:
    image: mysql:5.7.14
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - "./livequiz.sql:/docker-entrypoint-initdb.d/livequiz.sql"
    ports:
      - "9906:3306"
    environment:
      MYSQL_ROOT_PASSWORD: "root"
      MYSQL_DATABASE: livequiz
      MYSQL_USER: "admin"
      MYSQL_PASSWORD: "admin"

  phpmyadmin:
    image: phpmyadmin
    restart: always
    ports:
      - 8085:80
    depends_on:
      - mysql_db
    environment:
      PMA_HOST: mysql_db
      MYSQL_ROOT_PASSWORD: example

  nginx:
    depends_on:
      - api
      - client
    restart: always
    build:
      dockerfile: Dockerfile
      context: ./nginx
    ports:
      - "8086:80"

  client:
    stdin_open: true
    environment:
      - CHOKIDAR_USEPOLLING=true
    build:
      dockerfile: Dockerfile
      context: ./client
    volumes:
      - /livequiz/node_modules
      - ./client:/livequiz
    ports:
      - "8083:80"

  api:
    restart: always
    build:
      dockerfile: Dockerfile
      context: "./server"
    depends_on:
      - mysql_db
    volumes:
      - /livequiz/node_modules
      - ./server:/livequiz
    environment:
      <<: *common-variables
      MYSQL_HOST_IP: mysql_db
    ports:
      - "8084:8084"
      - "4000:4000"
