# IMPORTANT NOTE: Volume paths mounted on containers are relative to the
# directory that this file is in (`docker/`) and so probably need to start with
# `../` to refer to a directory in the main code checkout

volumes:
  redis:
  timescaledb:
  rabbitmq:
  # The contents of /root, so that bash and ipython can store history
  web_home:
  couchdb:

services:

  redis:
    image: redis:6.2.2
    volumes:
      - redis:/data:z

  lb_db:
    image: timescale/timescaledb:2.6.0-pg12
    volumes:
      - timescaledb:/var/lib/postgresql/data:z
    ports:
      - "127.0.0.1:17432:5433"
    expose:
      - "5433"
    environment:
      POSTGRES_PASSWORD: 'postgres'
    command: -p 5433

  couchdb:
    image: couchdb:3.2.2
    environment:
      COUCHDB_USER: listenbrainz
      COUCHDB_PASSWORD: listenbrainz
    volumes:
      - ./couchdb_test.ini:/opt/couchdb/etc/local.ini
      - couchdb:/var/lib/couchdb

  rabbitmq:
    image: rabbitmq:3.8.16-management
    volumes:
      - rabbitmq:/var/lib/rabbitmq:z
    ports:
      - "127.0.0.1:35672:15672"

  web:
    build:
      context: ..
      dockerfile: Dockerfile
      target: listenbrainz-dev
      args:
        GIT_COMMIT_SHA: HEAD
    environment:
      FLASK_APP: listenbrainz.webserver:create_web_app()
    command: flask run -h 0.0.0.0 -p 80 --debug
    image: web
    volumes:
      - web_home:/root
      - ..:/code/listenbrainz:z
      - ../frontend:/static
    ports:
      - "127.0.0.1:8111:80"
    depends_on:
      - redis
      - lb_db
      - rabbitmq

  api_compat:
    image: web
    environment:
      FLASK_APP: listenbrainz.webserver:create_api_compat_app()
    command: flask run -h 0.0.0.0 -p 8101 --debug
    ports:
      - "127.0.0.1:8121:8101"
    volumes:
      - ..:/code/listenbrainz:z
    depends_on:
      - redis
      - lb_db
      - rabbitmq

  timescale_writer:
    image: web
    command: python3 -m "listenbrainz.timescale_writer.timescale_writer"
    volumes:
      - ..:/code/listenbrainz:z
    depends_on:
      - redis
      - rabbitmq

  background_tasks:
    image: web
    command: python3 -m "listenbrainz.background.background_tasks"
    volumes:
      - ..:/code/listenbrainz:z
    depends_on:
      - redis
      - rabbitmq

  spotify_reader:
    image: web
    volumes:
      - ..:/code/listenbrainz:z
    command: python3 -m "listenbrainz.spotify_updater.spotify_read_listens"
    depends_on:
      - redis
      - rabbitmq

  websockets:
    image: web
    volumes:
      - ..:/code/listenbrainz:z
    command: python manage.py run_websockets -h 0.0.0.0 -p 8102
    ports:
      - "127.0.0.1:8112:8102"
    depends_on:
      - redis
      - rabbitmq

  static_builder:
    build:
      context: ..
      dockerfile: Dockerfile
      target: listenbrainz-frontend-dev
    command: npm run build:dev
    user: ${STATIC_BUILD_USER:-node}
    volumes:
      - ../frontend:/code/frontend:z

# Uncomment the following lines if you want to connect the LB network to a musicbrainz-docker network to access a MB replica
# TODO: re-comment these before merging this code
networks:
 default:
   name: musicbrainz-docker_default
   external: true