services:
  hub:
    image: hub:latest
    build:
      context: .
      target: "${BUILD_TARGET:-dev}"
    volumes:
      - ./src:/app
      - hubrun:/run/hub/
    environment:
      DJANGO_MIGRATE: "${DJANGO_MIGRATE:-yes}"
      DJANGO_LOAD_FIXTURE: ${DJANGO_LOAD_FIXTURE:-core/fixtures/anhalter.json}
      DATABASE_URL: "postgis://${HUB_DB_USER:-postgres}:${HUB_DB_PASSWORD:-postgres}@${HUB_DB_HOST:-db}:${DB_PORT:-5432}/${HUB_DB:-postgres}"
      CLIENT_IP_HEADER: "HTTP_X_REAL_IP"
      NUM_WORKERS: 1
      SERVE_ADMIN: True
      PYDEVD_DISABLE_FILE_VALIDATION: 1
    network_mode: service:db
    depends_on:
      - db
      - nginx

  hubtest:
    image: hub:latest
    restart: "no"
    entrypoint: tox
    volumes:
      - ./src:/app
    environment:
      DATABASE_URL: "postgis://${HUB_DB_USER:-postgres}:${HUB_DB_PASSWORD:-postgres}@${HUB_DB_HOST:-db}:${DB_PORT:-5432}/${HUB_DB:-hub_test}"
      SSO_SECRET_GENERATE: True
    depends_on:
      - db
    profiles:
      - test

  local-static:
    image: node-builder:latest
    build:
      context: .
      target: node-build
    volumes:
      # Mount only the static files, as we need the node_modules to be installed from build
      - ./src/plainui/styles:/app/plainui/styles
      - ./src/plainui/static:/app/plainui/static
    profiles:
      - build

  nginx:
    image: hubnginx:latest
    build:
      context: .
      target: nginx
    volumes:
      - hubrun:/run/hub/
    network_mode: service:db

  db:
    image: postgis/postgis:latest
    restart: unless-stopped
    volumes:
      - postgres-data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: "${HUB_DB_USER:-postgres}"
      POSTGRES_DB: "${HUB_DB:-postgres}"
      POSTGRES_PASSWORD: "${HUB_DB_PASSWORD:-postgres}"
    ports:
      - "5432:5432"
      - "80:80"

volumes:
  postgres-data:
  hubrun:
