Spaces:
Running
Running
fix: enable public space with dashboard login
Browse files- Dockerfile +1 -1
- README.md +6 -1
- entrypoint.space.sh +15 -29
Dockerfile
CHANGED
|
@@ -3,7 +3,7 @@ FROM ghcr.io/willxup/cpa-usage-keeper:latest
|
|
| 3 |
ENV APP_PORT=8080 \
|
| 4 |
CPA_BASE_URL=https://pjpjq-daili.hf.space \
|
| 5 |
REDIS_QUEUE_ADDR=127.0.0.1:9 \
|
| 6 |
-
AUTH_ENABLED=
|
| 7 |
TZ=Asia/Shanghai \
|
| 8 |
WORK_DIR=/data \
|
| 9 |
LOG_FILE_ENABLED=true \
|
|
|
|
| 3 |
ENV APP_PORT=8080 \
|
| 4 |
CPA_BASE_URL=https://pjpjq-daili.hf.space \
|
| 5 |
REDIS_QUEUE_ADDR=127.0.0.1:9 \
|
| 6 |
+
AUTH_ENABLED=true \
|
| 7 |
TZ=Asia/Shanghai \
|
| 8 |
WORK_DIR=/data \
|
| 9 |
LOG_FILE_ENABLED=true \
|
README.md
CHANGED
|
@@ -22,6 +22,11 @@ Default variables:
|
|
| 22 |
|
| 23 |
- `CPA_BASE_URL=https://pjpjq-daili.hf.space`
|
| 24 |
- `REDIS_QUEUE_ADDR=127.0.0.1:9` to force fast HTTP fallback to CPA `/v0/management/usage-queue`, because Hugging Face Spaces cannot reach the raw CPA TCP/RESP port across Spaces.
|
| 25 |
-
- `AUTH_ENABLED=
|
| 26 |
|
| 27 |
Persistent history requires Hugging Face persistent storage or another backup strategy for `/data`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
- `CPA_BASE_URL=https://pjpjq-daili.hf.space`
|
| 24 |
- `REDIS_QUEUE_ADDR=127.0.0.1:9` to force fast HTTP fallback to CPA `/v0/management/usage-queue`, because Hugging Face Spaces cannot reach the raw CPA TCP/RESP port across Spaces.
|
| 25 |
+
- `AUTH_ENABLED=true`; set `LOGIN_PASSWORD` as a Space secret. The Space can be public while the dashboard remains password protected.
|
| 26 |
|
| 27 |
Persistent history requires Hugging Face persistent storage or another backup strategy for `/data`.
|
| 28 |
+
|
| 29 |
+
Runtime secrets configured on Hugging Face:
|
| 30 |
+
|
| 31 |
+
- `CPA_MANAGEMENT_KEY`
|
| 32 |
+
- `LOGIN_PASSWORD`
|
entrypoint.space.sh
CHANGED
|
@@ -4,41 +4,27 @@ set -eu
|
|
| 4 |
APP_PORT="${APP_PORT:-8080}"
|
| 5 |
export APP_PORT
|
| 6 |
export CPA_BASE_URL="${CPA_BASE_URL:-https://pjpjq-daili.hf.space}"
|
|
|
|
|
|
|
| 7 |
export REDIS_QUEUE_ADDR="${REDIS_QUEUE_ADDR:-127.0.0.1:9}"
|
| 8 |
export WORK_DIR="${WORK_DIR:-/data}"
|
| 9 |
export TZ="${TZ:-Asia/Shanghai}"
|
| 10 |
-
export AUTH_ENABLED="${AUTH_ENABLED:-
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
mkdir -p /tmp/placeholder
|
| 14 |
-
cat > /tmp/placeholder/index.html <<
|
| 15 |
<!doctype html>
|
| 16 |
-
<html lang="zh-CN">
|
| 17 |
-
<
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
<title>Daili Usage Keeper</title>
|
| 21 |
-
<style>
|
| 22 |
-
body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:0;background:#0f172a;color:#e2e8f0;display:grid;place-items:center;min-height:100vh}
|
| 23 |
-
main{max-width:760px;padding:32px;border:1px solid #334155;border-radius:16px;background:#111827;box-shadow:0 20px 60px #0008}
|
| 24 |
-
code{background:#020617;border:1px solid #334155;border-radius:6px;padding:2px 6px;color:#93c5fd}
|
| 25 |
-
a{color:#93c5fd}
|
| 26 |
-
li{margin:.45rem 0}
|
| 27 |
-
</style>
|
| 28 |
-
</head>
|
| 29 |
-
<body>
|
| 30 |
-
<main>
|
| 31 |
-
<h1>Daili Usage Keeper is deployed</h1>
|
| 32 |
-
<p>The real dashboard is intentionally not started yet because <code>CPA_MANAGEMENT_KEY</code> is not configured.</p>
|
| 33 |
-
<ol>
|
| 34 |
-
<li>Add a Hugging Face Space secret named <code>CPA_MANAGEMENT_KEY</code> with the management key for <code>https://pjpjq-daili.hf.space</code>.</li>
|
| 35 |
-
<li>Restart this Space.</li>
|
| 36 |
-
<li>Keeper will then connect to CPA through <code>/v0/management/usage-queue</code> and store data under <code>/data</code>.</li>
|
| 37 |
-
</ol>
|
| 38 |
-
<p>This placeholder avoids hammering or banning the CPA management endpoint with a wrong key.</p>
|
| 39 |
-
</main>
|
| 40 |
-
</body>
|
| 41 |
-
</html>
|
| 42 |
HTML
|
| 43 |
exec busybox httpd -f -p "0.0.0.0:${APP_PORT}" -h /tmp/placeholder
|
| 44 |
fi
|
|
|
|
| 4 |
APP_PORT="${APP_PORT:-8080}"
|
| 5 |
export APP_PORT
|
| 6 |
export CPA_BASE_URL="${CPA_BASE_URL:-https://pjpjq-daili.hf.space}"
|
| 7 |
+
# Cross-Space raw TCP/RESP is not reachable; force a fast failed TCP attempt so
|
| 8 |
+
# cpa-usage-keeper immediately falls back to CPA /v0/management/usage-queue.
|
| 9 |
export REDIS_QUEUE_ADDR="${REDIS_QUEUE_ADDR:-127.0.0.1:9}"
|
| 10 |
export WORK_DIR="${WORK_DIR:-/data}"
|
| 11 |
export TZ="${TZ:-Asia/Shanghai}"
|
| 12 |
+
export AUTH_ENABLED="${AUTH_ENABLED:-true}"
|
| 13 |
|
| 14 |
+
missing=""
|
| 15 |
+
[ -n "${CPA_MANAGEMENT_KEY:-}" ] || missing="$missing CPA_MANAGEMENT_KEY"
|
| 16 |
+
if [ "${AUTH_ENABLED}" = "true" ] && [ -z "${LOGIN_PASSWORD:-}" ]; then
|
| 17 |
+
missing="$missing LOGIN_PASSWORD"
|
| 18 |
+
fi
|
| 19 |
+
|
| 20 |
+
if [ -n "$missing" ]; then
|
| 21 |
mkdir -p /tmp/placeholder
|
| 22 |
+
cat > /tmp/placeholder/index.html <<HTML
|
| 23 |
<!doctype html>
|
| 24 |
+
<html lang="zh-CN"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/>
|
| 25 |
+
<title>Daili Usage Keeper</title>
|
| 26 |
+
<style>body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;margin:0;background:#0f172a;color:#e2e8f0;display:grid;place-items:center;min-height:100vh}main{max-width:760px;padding:32px;border:1px solid #334155;border-radius:16px;background:#111827;box-shadow:0 20px 60px #0008}code{background:#020617;border:1px solid #334155;border-radius:6px;padding:2px 6px;color:#93c5fd}</style>
|
| 27 |
+
</head><body><main><h1>Daili Usage Keeper is deployed</h1><p>Missing Space secret(s): <code>${missing}</code>.</p><p>Set the secret(s), then restart this Space.</p></main></body></html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
HTML
|
| 29 |
exec busybox httpd -f -p "0.0.0.0:${APP_PORT}" -h /tmp/placeholder
|
| 30 |
fi
|