CoolFace
Apppublic

kingcap/openapi

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
entrypoint.sh105 linesDownload Raw Back to docker
1#!/bin/sh2set -eu3 4apply_extra_hosts() {5  if [ -z "${CPA_EXTRA_HOSTS:-}" ]; then6    return 07  fi8 9  echo "Applying CPA_EXTRA_HOSTS to /etc/hosts"10  printf '%s\n' "$CPA_EXTRA_HOSTS" | tr ',' '\n' | while IFS= read -r entry; do11    entry="$(printf '%s' "$entry" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"12    if [ -z "$entry" ]; then13      continue14    fi15 16    case "$entry" in17      *=*)18        host="${entry%%=*}"19        ip="${entry#*=}"20        line="$ip $host"21        ;;22      *)23        line="$entry"24        ;;25    esac26 27    if printf '%s\n' "$line" | grep -Eq '^[0-9A-Fa-f:.]+[[:space:]]+[A-Za-z0-9_.-]'; then28      printf '%s\n' "$line" >> /etc/hosts29      echo "  + $line"30    else31      echo "WARN: skip invalid CPA_EXTRA_HOSTS entry: $entry" >&232    fi33  done34}35 36apply_extra_hosts37 38mkdir -p \39  /app \40  /data \41  /run/nginx \42  /tmp/.cli-proxy-api \43  /tmp/logs \44  /tmp/pg_cache/pgstore \45  /tmp/nginx/client_temp \46  /tmp/nginx/proxy_temp \47  /tmp/nginx/fastcgi_temp \48  /tmp/nginx/uwsgi_temp \49  /tmp/nginx/scgi_temp50 51# eceasy/cli-proxy-api:v7.1.40+ 使用 DATABASE_URL;52# 老版本和本项目同步脚本曾使用 PGSTORE_DSN。两边互补,保证 HF Space53# 只配置其中任意一个变量时,子进程都能拿到同一份 PG 连接串。54if [ -z "${DATABASE_URL:-}" ] && [ -n "${PGSTORE_DSN:-}" ]; then55  export DATABASE_URL="$PGSTORE_DSN"56fi57 58if [ -z "${PGSTORE_DSN:-}" ] && [ -n "${DATABASE_URL:-}" ]; then59  export PGSTORE_DSN="$DATABASE_URL"60fi61 62python3 /app/prestart_migrate.py63 64python3 - <<'PY'65import json66import os67from pathlib import Path68 69host = os.getenv("CPA_BIND_HOST", "127.0.0.1")70port = int(os.getenv("CPA_BIND_PORT", "8317"))71auth_dir = os.getenv("CPA_AUTH_DIR", "/tmp/.cli-proxy-api")72secret = os.getenv("CPA_BOOTSTRAP_MANAGEMENT_KEY", "changeme")73 74content = f"""host: {host}75port: {port}76auth-dir: {json.dumps(auth_dir)}77usage-statistics-enabled: true78 79tls:80  enable: false81 82remote-management:83  allow-remote: false84  secret-key: {json.dumps(secret)}85  disable-control-panel: false86"""87 88Path("/app/config.yaml").write_text(content, encoding="utf-8")89Path("/app/config.example.yaml").write_text(content, encoding="utf-8")90PY91 92if [ "$(id -u)" = "0" ]; then93  chown -R app:app \94    /app \95    /data \96    /run/nginx \97    /tmp/.cli-proxy-api \98    /tmp/logs \99    /tmp/pg_cache \100    /tmp/nginx \101    /home/app102fi103 104exec /usr/bin/supervisord -c /etc/supervisord.conf105