# ISISeg clean deployment template.
# Copy this file as docker_compose.yaml, then fill the TODO values below.
# Start app only:
#   docker compose -f docker_compose.yaml up -d --build
# Start app + frpc:
#   docker compose -f docker_compose.yaml --profile frpc up -d --build

name: isiseg

services:
  isiseg_app:
    image: isiseg/app:latest
    build:
      context: .
      dockerfile: Dockerfile
      # TODO: Uncomment args only if this host needs a proxy during docker build.
      # args:
      #   HTTP_PROXY: http://<proxy-host>:<proxy-port>
      #   HTTPS_PROXY: http://<proxy-host>:<proxy-port>
      #   NO_PROXY: localhost,127.0.0.1,<your-lan-cidr>,isiseg_app
    restart: unless-stopped
    environment:
      TZ: Asia/Shanghai
      PORT: 8001
      # TODO: Fill with your public URL, for example https://isiseg.example.com
      PUBLIC_URL: ""
    ports:
      # TODO: Change host port if 10004 is occupied.
      - "${ISISEG_HOST_PORT:-10004}:8001"
    volumes:
      - ./data/uploads:/app/storage/uploads
      - ./data/jobs:/app/storage/jobs
    healthcheck:
      test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8001/api/health', timeout=3).read()\""]
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 20s

  isiseg_frpc:
    # TODO: Remove profiles if you want frpc to start by default.
    profiles: ["frpc"]
    image: snowdreamtech/frpc:latest
    restart: unless-stopped
    environment:
      # TODO: Fill these values before enabling frpc.
      FRP_SERVER_ADDR: "<FRP_SERVER_ADDR>"
      FRP_SERVER_PORT: "7000"
      FRP_AUTH_TOKEN: "<FRP_AUTH_TOKEN>"
      FRP_PROXY_NAME: "ISISeg"
      FRP_REMOTE_PORT: "10004"
    entrypoint: ["/bin/sh"]
    command:
      - -c
      - |
        cat > /tmp/frpc.toml <<EOF
        serverAddr = "$${FRP_SERVER_ADDR}"
        serverPort = $${FRP_SERVER_PORT}

        auth.method = "token"
        auth.token = "$${FRP_AUTH_TOKEN}"

        transport.poolCount = 5
        transport.heartbeatTimeout = -1

        [[proxies]]
        name = "$${FRP_PROXY_NAME}"
        type = "tcp"
        localIP = "isiseg_app"
        localPort = 8001
        remotePort = $${FRP_REMOTE_PORT}
        EOF
        exec frpc -c /tmp/frpc.toml
    depends_on:
      isiseg_app:
        condition: service_healthy
