File size: 1,422 Bytes
bc332b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh
set -eu

# Hugging Face Spaces exposes port 7860 by default. The upstream image sets
# PORT=3001, so override that explicitly here. Use HF_SPACE_PORT only if you
# also change app_port in the Space README front matter.
export PORT="${HF_SPACE_PORT:-7860}"

# Put the SQLite database and (fallback) encryption key in the same mount.
# Attach a persistent Storage Bucket at /data if you want data to survive
# Space restarts/rebuilds. Without a persistent volume, both are ephemeral.
DATA_DIR="${FREELLMAPI_DATA_DIR:-/data}"
mkdir -p "$DATA_DIR"
export FREEAPI_DB_PATH="${FREEAPI_DB_PATH:-$DATA_DIR/freeapi.db}"

# Official FreeLLMAPI requires ENCRYPTION_KEY. Prefer setting it as a Space
# Secret; otherwise create/reuse a key file alongside the database. Keeping
# the file beside the DB means a normal restart does not mismatch the key.
if [ -z "${ENCRYPTION_KEY:-}" ]; then
  KEY_FILE="${ENCRYPTION_KEY_FILE:-$DATA_DIR/.encryption-key}"
  if [ ! -s "$KEY_FILE" ]; then
    umask 077
    TMP_KEY="${KEY_FILE}.tmp.$$"
    node -e "process.stdout.write(require('crypto').randomBytes(32).toString('hex'))" > "$TMP_KEY"
    mv "$TMP_KEY" "$KEY_FILE"
  fi
  ENCRYPTION_KEY="$(tr -d '\r\n' < "$KEY_FILE")"
  export ENCRYPTION_KEY
fi

# Call the upstream entrypoint so it can set ownership and drop privileges
# before starting the original server command from the image.
exec /usr/local/bin/docker-entrypoint.sh "$@"