version: "3.8"

services:
  backend:
    build: ./backend
    restart: ${RESTART_POLICY}
    volumes:
      - ./.git:/opt/app/.parent_git:ro
      - /opt/app/node_modules
      - ./backend/config:/opt/app/config
    links:
      - mongo
      - redis
    stdin_open: true
    tty: true

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

  mongo:
    image: docker.io/mongo:${MONGO_VERSION}
    restart: ${RESTART_POLICY}
    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
      - ${MONGO_DATA_LOCATION}:/data/db

  redis:
    image: docker.io/redis:6.2
    restart: ${RESTART_POLICY}
    command: "--notify-keyspace-events Ex --requirepass ${REDIS_PASSWORD} --appendonly yes"
