version: '3'
services:

  backend:
    build: ./backend
    restart: ${RESTART_POLICY}
    ports:
      - "${BACKEND_HOST}:${BACKEND_PORT}:8080"
    volumes:
      - ./backend:/opt/app
      - ./log:/opt/log
      - ./.git:/opt/app/.parent_git:ro
    links:
      - mongo
      - redis
    stdin_open: true
    tty: true

  frontend:
    build: ./frontend
    restart: ${RESTART_POLICY}
    ports:
      - "${FRONTEND_HOST}:${FRONTEND_PORT}:80"
    volumes:
      - ./frontend:/opt/app
      - /opt/app/node_modules/
      - ./.git:/opt/app/.parent_git:ro
    environment:
      - FRONTEND_MODE=${FRONTEND_MODE}
    links:
      - backend

  mongo:
    image: mongo:5.0
    restart: ${RESTART_POLICY}
    ports:
      - "${MONGO_HOST}:${MONGO_PORT}:${MONGO_PORT}"
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
      - MONGO_INITDB_DATABASE=musare
      - MONGO_PORT=${MONGO_PORT}
      - MONGO_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
      - MONGO_USER_USERNAME=${MONGO_USER_USERNAME}
      - MONGO_USER_PASSWORD=${MONGO_USER_PASSWORD}
    volumes:
      - ./tools/docker/setup-mongo.sh:/docker-entrypoint-initdb.d/setup-mongo.sh
      - ./.db:/data/db

  redis:
    image: redis:6.2
    restart: ${RESTART_POLICY}
    ports:
      - "${REDIS_HOST}:${REDIS_PORT}:6379"
    command: "--notify-keyspace-events Ex --requirepass ${REDIS_PASSWORD} --appendonly yes"
    volumes:
      - .redis:/data
