services:
  backend-management:
    build:
      context: ".."
      dockerfile: "backend/Dockerfile"
      target: "development"
    image: "docker-hosted.nexus.bthlabs.pl/hotpocket/backend:local"
    command: "echo 'NOOP'"
    environment: &backend-env
      PYTHONBREAKPOINT: "ipdb.set_trace"
      PYTHONPATH: "/srv/packages/common"
      DJANGO_SETTINGS_MODULE: "hotpocket_backend.settings.docker.webapp"
      DJANGO_TESTING_SETTINGS_MODULE: "hotpocket_backend.settings.docker.testing"
      HOTPOCKET_BACKEND_ENV: "${HOTPOCKET_BACKEND_ENV:-docker}"
      HOTPOCKET_BACKEND_APP: "webapp"
      POSTGRES_HOSTPORT: "${POSTGRES_HOST:-postgres.hotpocket.work.bthlabs.net}:${POSTGRES_PORT:-5432}"
      RABBITMQ_HOSTPORT: "${RABBITMQ_HOST:-rabbitmq.hotpocket.work.bthlabs.net}:${RABBITMQ_PORT:-5672}"
      KEYCLOAK_HOSTPORT: "${KEYCLOAK_HOST:-auth.hotpocket.work.bthlabs.net}:${KEYCLOAK_PORT:-8080}"
      REQUESTS_CA_BUNDLE: "/srv/tls/requests_ca_bundle.pem"
      RUN_POETRY_INSTALL: "true"
      RUN_YARN_INSTALL: "true"
      SETUP_BACKEND: "true"
      SETUP_FRONTEND: "true"
    volumes:
      - "backend_venv:/srv/venv"
      - "backend_node_modules:/srv/node_modules"
      - ".:/srv/app"
      - "./ops/docker/settings:/srv/app/hotpocket_backend/settings/docker"
      - "./ops/docker/secrets:/srv/app/hotpocket_backend/secrets/docker"
      - "../packages:/srv/packages"
      - "../tls:/srv/tls"
    restart: "no"
    stdin_open: true
    tty: true
    depends_on:
      - "postgres"
      - "keycloak"
      - "rabbitmq"

  backend-webapp:
    build:
      context: ".."
      dockerfile: "backend/Dockerfile"
      target: "development"
    image: "docker-hosted.nexus.bthlabs.pl/hotpocket/backend:local"
    command:
      - "./manage.py"
      - "runserver"
      - "0.0.0.0:8000"
    environment:
      <<: *backend-env
      RUN_POETRY_INSTALL: "nope"
      RUN_YARN_INSTALL: "nope"
    volumes:
      - "backend_venv:/srv/venv"
      - "backend_node_modules:/srv/node_modules"
      - ".:/srv/app"
      - "./ops/docker/settings:/srv/app/hotpocket_backend/settings/docker"
      - "./ops/docker/secrets:/srv/app/hotpocket_backend/secrets/docker"
      - "../packages:/srv/packages"
      - "../tls:/srv/tls"
    networks:
      default:
        aliases:
          - "backend-webapp.hotpocket.work.bthlabs.net"
    restart: "unless-stopped"
    stdin_open: true
    tty: true
    depends_on:
      - "postgres"
      - "keycloak"
      - "rabbitmq"

  backend-admin:
    build:
      context: ".."
      dockerfile: "backend/Dockerfile"
      target: "development"
    image: "docker-hosted.nexus.bthlabs.pl/hotpocket/backend:local"
    command:
      - "./manage.py"
      - "runserver"
      - "0.0.0.0:8000"
    environment:
      <<: *backend-env
      DJANGO_SETTINGS_MODULE: "hotpocket_backend.settings.docker.admin"
      HOTPOCKET_BACKEND_APP: "admin"
      RUN_POETRY_INSTALL: "nope"
      RUN_YARN_INSTALL: "nope"
    volumes:
      - "backend_venv:/srv/venv"
      - "backend_node_modules:/srv/node_modules"
      - ".:/srv/app"
      - "./ops/docker/settings:/srv/app/hotpocket_backend/settings/docker"
      - "./ops/docker/secrets:/srv/app/hotpocket_backend/secrets/docker"
      - "../packages:/srv/packages"
      - "../tls:/srv/tls"
    networks:
      default:
        aliases:
          - "backend-admin.hotpocket.work.bthlabs.net"
    restart: "unless-stopped"
    stdin_open: true
    tty: true
    depends_on:
      - "postgres"
      - "keycloak"
      - "rabbitmq"

  backend-celery-worker:
    build:
      context: ".."
      dockerfile: "backend/Dockerfile"
      target: "development"
    image: "docker-hosted.nexus.bthlabs.pl/hotpocket/backend:local"
    command:
      - "celery"
      - "-A"
      - "hotpocket_backend.celery:app"
      - "worker"
      - "--loglevel=INFO"
      - "-Q"
      - "celery,webapp"
      - "-c"
      - "4"
    environment:
      <<: *backend-env
      RUN_POETRY_INSTALL: "nope"
      RUN_YARN_INSTALL: "nope"
    volumes:
      - "backend_venv:/srv/venv"
      - "backend_node_modules:/srv/node_modules"
      - ".:/srv/app"
      - "./ops/docker/settings:/srv/app/hotpocket_backend/settings/docker"
      - "./ops/docker/secrets:/srv/app/hotpocket_backend/secrets/docker"
      - "../packages:/srv/packages"
      - "../tls:/srv/tls"
    restart: "unless-stopped"
    stdin_open: true
    tty: true
    depends_on:
      - "postgres"
      - "keycloak"
      - "rabbitmq"

  backend-celery-beat:
    build:
      context: ".."
      dockerfile: "backend/Dockerfile"
      target: "development"
    image: "docker-hosted.nexus.bthlabs.pl/hotpocket/backend:local"
    command:
      - "celery"
      - "-A"
      - "hotpocket_backend.celery:app"
      - "beat"
      - "--loglevel=INFO"
      - "-s"
      - "/srv/app/run/celery-beat-schedule-docker"
    environment:
      <<: *backend-env
      RUN_POETRY_INSTALL: "nope"
      RUN_YARN_INSTALL: "nope"
    volumes:
      - "backend_venv:/srv/venv"
      - "backend_node_modules:/srv/node_modules"
      - ".:/srv/app"
      - "./ops/docker/settings:/srv/app/hotpocket_backend/settings/docker"
      - "./ops/docker/secrets:/srv/app/hotpocket_backend/secrets/docker"
      - "../packages:/srv/packages"
      - "../tls:/srv/tls"
    restart: "unless-stopped"
    stdin_open: true
    tty: true
    depends_on:
      - "postgres"
      - "keycloak"
      - "rabbitmq"

volumes:
  backend_venv:
  backend_node_modules:
