name: safetwitch

services:
  safetwitch-frontend:
    container_name: safetwitch-frontend
    hostname: safetwitch-frontend
    restart: always
    image: safetwitch-local:latest
    build:
      context: "../"
      dockerfile: "./docker/Dockerfile"
    ports:
      - "127.0.0.1:${SAFETWITCH_FRONTEND_PORT:-8280}:8280"
    environment:
      - SAFETWITCH_BACKEND_DOMAIN=${SAFETWITCH_BACKEND_DOMAIN:-api.safetwitch.darkness.services}
      - SAFETWITCH_INSTANCE_DOMAIN=${SAFETWITCH_INSTANCE_DOMAIN:-safetwitch.darkness.services}
      - SAFETWITCH_HTTPS=${SAFETWITCH_HTTPS:-true}
      - SAFETWITCH_DEFAULT_LOCALE=${SAFETWITCH_DEFAULT_LOCALE:-en}
      - SAFETWITCH_FALLBACK_LOCALE=${SAFETWITCH_FALLBACK_LOCALE:-en}
      - SAFETWITCH_DEFAULT_THEME=${SAFETWITCH_DEFAULT_THEME:-dark}
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.safetwitch.rule=Host(`safetwitch.darkness.services`)"
      - "traefik.http.routers.safetwitch.entrypoints=https"
      - "traefik.http.routers.safetwitch.tls.certresolver=myresolver"
      - "traefik.http.services.safetwitch.loadbalancer.server.port=8280"

  safetwitch-frontend-tor:
    container_name: safetwitch-frontend-tor
    hostname: safetwitch-frontend-tor
    restart: always
    image: safetwitch-local:latest
    ports:
      - "127.0.0.1:${SAFETWITCH_FRONTEND_TOR_PORT:-8281}:8280"
    environment:
      - SAFETWITCH_BACKEND_DOMAIN=api.safetwitch.darknessrdor43qkl2ngwitj72zdavfz2cead4t5ed72bybgauww5lyd.onion
      - SAFETWITCH_INSTANCE_DOMAIN=safetwitch.darknessrdor43qkl2ngwitj72zdavfz2cead4t5ed72bybgauww5lyd.onion
      - SAFETWITCH_HTTPS=false
      - SAFETWITCH_DEFAULT_LOCALE=${SAFETWITCH_DEFAULT_LOCALE:-en}
      - SAFETWITCH_FALLBACK_LOCALE=${SAFETWITCH_FALLBACK_LOCALE:-en}
      - SAFETWITCH_DEFAULT_THEME=${SAFETWITCH_DEFAULT_THEME:-dark}
    labels:
      - "traefik.enable=true"
      - "traefik.http.services.safetwitch-tor.loadbalancer.server.port=8280"
      - "traefik.http.routers.safetwitch-tor.entrypoints=tor"
      - "traefik.http.routers.safetwitch-tor.rule=Host(`safetwitch.darknessrdor43qkl2ngwitj72zdavfz2cead4t5ed72bybgauww5lyd.onion`)"

  safetwitch-backend:
    container_name: safetwitch-backend
    hostname: safetwitch-backend
    read_only: true
    security_opt:
      - no-new-privileges:true
    cap_drop:
      - ALL
    restart: always
    image: codeberg.org/safetwitch/safetwitch-backend:latest
    ports:
      - "127.0.0.1:${SAFETWITCH_BACKEND_PORT:-7100}:7000"
    environment:
      - PORT=7000
      - URL=${SAFETWITCH_BACKEND_URL:-https://api.safetwitch.darkness.services}
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.apisafetwitch.rule=Host(`api.safetwitch.darkness.services`)"
      - "traefik.http.routers.apisafetwitch.entrypoints=https"
      - "traefik.http.routers.apisafetwitch.tls.certresolver=myresolver"
      - "traefik.http.services.apisafetwitch.loadbalancer.server.port=7000"

  safetwitch-backend-tor:
    container_name: safetwitch-backend-tor
    hostname: safetwitch-backend-tor
    read_only: true
    security_opt:
      - no-new-privileges:true
    cap_drop:
      - ALL
    restart: always
    image: codeberg.org/safetwitch/safetwitch-backend:latest
    ports:
      - "127.0.0.1:${SAFETWITCH_BACKEND_TOR_PORT:-7101}:7000"
    environment:
      - PORT=7000
      - URL=http://api.safetwitch.darknessrdor43qkl2ngwitj72zdavfz2cead4t5ed72bybgauww5lyd.onion
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.apisafetwitch-tor.rule=Host(`api.safetwitch.darknessrdor43qkl2ngwitj72zdavfz2cead4t5ed72bybgauww5lyd.onion`)"
      - "traefik.http.routers.apisafetwitch-tor.entrypoints=tor"
      - "traefik.http.services.apisafetwitch-tor.loadbalancer.server.port=7000"

  safetwitch-search-fallback:
    container_name: safetwitch-search-fallback
    hostname: safetwitch-search-fallback
    restart: always
    image: docker.io/node:22-alpine
    read_only: true
    security_opt:
      - no-new-privileges:true
    cap_drop:
      - ALL
    tmpfs:
      - /tmp
    command: ["node", "/app/server.mjs"]
    volumes:
      - "./search-fallback/server.mjs:/app/server.mjs:ro"
    environment:
      - PORT=7171
      - BACKEND_BASE_URL=http://safetwitch-backend:7000
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.apisafetwitch-search.rule=Host(`api.safetwitch.darkness.services`) && PathPrefix(`/api/search`)"
      - "traefik.http.routers.apisafetwitch-search.entrypoints=https"
      - "traefik.http.routers.apisafetwitch-search.tls.certresolver=myresolver"
      - "traefik.http.routers.apisafetwitch-search.priority=100"
      - "traefik.http.routers.apisafetwitch-search.service=apisafetwitch-search"
      - "traefik.http.routers.apisafetwitch-search-tor.rule=Host(`api.safetwitch.darknessrdor43qkl2ngwitj72zdavfz2cead4t5ed72bybgauww5lyd.onion`) && PathPrefix(`/api/search`)"
      - "traefik.http.routers.apisafetwitch-search-tor.entrypoints=tor"
      - "traefik.http.routers.apisafetwitch-search-tor.priority=100"
      - "traefik.http.routers.apisafetwitch-search-tor.service=apisafetwitch-search"
      - "traefik.http.services.apisafetwitch-search.loadbalancer.server.port=7171"

networks:
  default:
    name: ${SAFETWITCH_DOCKER_NETWORK:-npm_default}
    external: ${SAFETWITCH_DOCKER_NETWORK_EXTERNAL:-true}
