# Windows 使用系统 PowerShell，Linux 使用 just 默认的 sh。
set windows-shell := ["powershell.exe", "-NoLogo", "-NoProfile", "-Command"]

default:
    @just --list

# 检查配置，不输出展开后的密码。
check:
    docker compose config --quiet

# 拉取全部官方镜像。
pull: check
    docker compose pull

up: check
    docker compose up -d --no-build --wait

# 保留所有数据卷。
down:
    docker compose down

stop:
    docker compose stop

restart service="app":
    docker compose restart {{service}}

recreate service="app": check
    docker compose up -d --no-build --no-deps --force-recreate --wait {{service}}

# 先修改对应 Compose 文件的版本；默认只升级 CPR。
update service="app": check
    docker compose pull {{service}}
    docker compose up -d --no-build --no-deps --force-recreate --wait {{service}}

status:
    docker compose ps --all

logs service="app":
    docker compose logs --follow --tail=100 {{service}}

health:
    docker compose exec -T app curl -fsS http://127.0.0.1:8080/healthz

xray-check:
    docker compose exec -T xray /usr/local/bin/xray run -test -confdir /etc/xray

# 仅重启 Xray 容器，既有代理连接会中断。
xray-restart: xray-check
    docker compose restart xray

xray-status:
    docker compose ps xray

# 包含访问、错误及 DoH 查询日志，由 Docker 轮转。
xray-logs:
    docker compose logs --follow --tail=100 xray

xray-stats:
    docker compose exec -T xray /usr/local/bin/xray api statsquery --server=127.0.0.1:10085

# 从 CPR 使用同一 HTTP 代理验证出口，不输出节点凭据。
proxy-check:
    docker compose exec -T app curl -fsS --max-time 20 --noproxy "localhost,127.0.0.1" --proxy http://xray:10809 https://api.ipify.org
