File size: 1,245 Bytes
b1d6098
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
set -euo pipefail

if [ -z "${GH_REPO_TOKEN:-}" ]; then
  echo "GH_REPO_TOKEN secret missing. Configure it in Hugging Face Space Settings -> Variables and secrets." >&2
  exit 1
fi

REPO_SLUG="${GH_REPO_SLUG:-shs3131/pulltime}"
REPO_REF="${GH_REPO_REF:-main}"
APP_SUBDIR="${GH_APP_SUBDIR:-server/storage-service}"
APP_DIR="/runtime/app"

mkdir -p /runtime
rm -rf "$APP_DIR"

git clone --depth 1 --branch "$REPO_REF" "https://x-access-token:${GH_REPO_TOKEN}@github.com/${REPO_SLUG}.git" "$APP_DIR"

# Resolve app directory safely even if GH_APP_SUBDIR is misconfigured.
APP_SUBDIR="${APP_SUBDIR#/}"
RESOLVED_SUBDIR=""

for candidate in "$APP_SUBDIR" "server/storage-service" "storage-service"; do
  if [ -f "$APP_DIR/$candidate/package.json" ]; then
    RESOLVED_SUBDIR="$candidate"
    break
  fi
done

if [ -z "$RESOLVED_SUBDIR" ]; then
  echo "package.json not found. Checked: $APP_SUBDIR, server/storage-service, storage-service" >&2
  exit 1
fi

cd "$APP_DIR/$RESOLVED_SUBDIR"
echo "Using app subdir: $RESOLVED_SUBDIR"

if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then
  npm ci --omit=dev
else
  echo "Lockfile not found, falling back to npm install --omit=dev"
  npm install --omit=dev
fi

exec npm start