name: monkeytype
version: "3.8"
services:
  redis:
    container_name: monkeytype-redis
    image: redis:6.2.6
    restart: on-failure
    ports:
      - "${DOCKER_REDIS_PORT:-6379}:6379"
    volumes:
      - redis-data:/data

  mongodb:
    container_name: monkeytype-mongodb
    image: mongo:5.0.13
    restart: on-failure
    ports:
      - "${DOCKER_DB_PORT:-27017}:27017"
    volumes:
      - mongo-data:/data/db

  api-server:
    container_name: monkeytype-api-server
    build:
      dockerfile_inline: |
        FROM node:20.16.0
        RUN npm i -g pnpm@9.6.0
        RUN mkdir /pnpm-store && chown -R 1000:1000 /pnpm-store
    user: "node"    ##this works as long as your local user has uid=1000
    restart: on-failure
    depends_on:
      - redis
      - mongodb
    environment:
      - DB_URI=mongodb://mongodb:27017
      - REDIS_URI=redis://redis:6379
    ports:
      - "${DOCKER_SERVER_PORT:-5005}:5005"
    volumes:
      - ../../:/monkeytype
    entrypoint: 'bash -c "echo starting, this may take a while... \
      && cd /monkeytype \
      && pnpm config set store-dir /pnpm-store
      && pnpm i \
      && npm run dev-be"'

volumes:
  mongo-data:
  redis-data:
