mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-09 18:57:43 +08:00
2.3 KiB
2.3 KiB
DS2API Deployment Guide (Go)
This guide is aligned with the current Go codebase.
Deployment Modes
- Local run:
go run ./cmd/ds2api - Docker:
docker-compose up -d - Vercel: serverless entry at
api/index.go - Linux service mode: systemd
0. Prerequisites
- Go 1.25+
- Node.js 20+ (only if you need to build WebUI locally)
config.jsonorDS2API_CONFIG_JSON
1. Local Run
git clone https://github.com/CJackHwang/ds2api.git
cd ds2api
cp config.example.json config.json
# edit config.json
go run ./cmd/ds2api
Default port is 5001 (override with PORT).
Build WebUI if /admin reports missing assets:
./scripts/build-webui.sh
2. Docker Deployment
cp .env.example .env
# edit .env
docker-compose up -d
docker-compose logs -f
Rebuild after updates:
docker-compose up -d --build
Notes:
Dockerfileuses multi-stage build (WebUI + Go binary)- Container entry command is
/usr/local/bin/ds2api
3. Vercel Deployment
- Serverless entry:
api/index.go - Rewrites and cache headers:
vercel.json
Minimum environment variables:
DS2API_ADMIN_KEYDS2API_CONFIG_JSON(raw JSON or Base64)
Optional:
VERCEL_TOKENVERCEL_PROJECT_IDVERCEL_TEAM_ID
After deploy, verify:
/healthz/v1/models/admin
4. Reverse Proxy (Nginx)
Disable buffering for SSE:
location / {
proxy_pass http://127.0.0.1:5001;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding on;
tcp_nodelay on;
}
5. systemd Example (Linux)
[Unit]
Description=DS2API (Go)
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/ds2api
Environment=PORT=5001
Environment=DS2API_CONFIG_PATH=/opt/ds2api/config.json
Environment=DS2API_ADMIN_KEY=admin
ExecStart=/opt/ds2api/ds2api
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
Common commands:
sudo systemctl daemon-reload
sudo systemctl enable ds2api
sudo systemctl start ds2api
sudo systemctl status ds2api
6. Post-Deploy Checks
curl -s http://127.0.0.1:5001/healthz
curl -s http://127.0.0.1:5001/readyz
curl -s http://127.0.0.1:5001/v1/models
If admin UI is required:
curl -s http://127.0.0.1:5001/admin