-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·153 lines (135 loc) · 8.42 KB
/
entrypoint.sh
File metadata and controls
executable file
·153 lines (135 loc) · 8.42 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
set -e
# ── Helpers ───────────────────────────────────────────────────────────────────
log() { echo " ▸ $*"; }
warn() { >&2 echo " ⚠ $*"; }
section() {
local title=" ── $* "
local pad=$(( 71 - ${#title} ))
printf '\n%s' "$title"
[ "$pad" -gt 0 ] && printf '─%.0s' $(seq 1 "$pad")
printf '\n\n'
}
# ── Banner ────────────────────────────────────────────────────────────────────
if [ "${FIRESHARE_LITE}" != "true" ]; then
echo ""
echo " ███████╗██╗██████╗ ███████╗███████╗██╗ ██╗ █████╗ ██████╗ ███████╗"
echo " ██╔════╝██║██╔══██╗██╔════╝██╔════╝██║ ██║██╔══██╗██╔══██╗██╔════╝"
echo " █████╗ ██║██████╔╝█████╗ ███████╗███████║███████║██████╔╝█████╗ "
echo " ██╔══╝ ██║██╔══██╗██╔══╝ ╚════██║██╔══██║██╔══██║██╔══██╗██╔══╝ "
echo " ██║ ██║██║ ██║███████╗███████║██║ ██║██║ ██║██║ ██║███████╗"
echo " ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝"
echo " ─────────────────────────────────────────────────────────────────────"
echo ""
fi
# ── User / permissions ────────────────────────────────────────────────────────
PUID=${PUID:-1000}
PGID=${PGID:-1000}
useradd appuser 2>/dev/null || true
groupmod -o -g "$PGID" appuser
usermod -o -u "$PUID" appuser
chown_fail=0
if ! chown -R appuser:appuser "$DATA_DIRECTORY" 2>/dev/null; then
warn "Could not chown data directory ($DATA_DIRECTORY) to $PUID:$PGID"
warn "Files created by Fireshare may not have the expected ownership"
warn "Ensure the container has permissions to access this directory"
chown_fail=1
fi
if ! chown -R appuser:appuser "$PROCESSED_DIRECTORY" 2>/dev/null; then
warn "Could not chown processed directory ($PROCESSED_DIRECTORY) to $PUID:$PGID"
warn "Files created by Fireshare may not have the expected ownership"
warn "Ensure the container has permissions to access this directory"
chown_fail=1
fi
[ $chown_fail -eq 1 ] && warn "One or more chown operations failed — continuing startup"
log "UID=$(id -u appuser) GID=$(id -g appuser)"
# ── Mount validation ──────────────────────────────────────────────────────────
missing_mounts=0
for mount_path in "$DATA_DIRECTORY" "$VIDEO_DIRECTORY" "$PROCESSED_DIRECTORY"; do
if [ -n "$mount_path" ] && ! mountpoint -q "$mount_path" 2>/dev/null; then
warn "Required volume not mounted at $mount_path"
missing_mounts=1
fi
done
if [ "$missing_mounts" -eq 1 ]; then
warn "Fireshare cannot start without /data, /videos, and /processed mounted. Exiting."
exit 1
fi
if [ -n "$IMAGE_DIRECTORY" ] && ! mountpoint -q "$IMAGE_DIRECTORY" 2>/dev/null; then
printf " \033[33m▸ No volume mounted at %s — uploaded images will not persist\033[0m\n" "$IMAGE_DIRECTORY"
fi
# ── Cleanup ───────────────────────────────────────────────────────────────────
rm -f "$DATA_DIRECTORY"/*.lock 2>/dev/null || true
rm -f "$DATA_DIRECTORY/jobs.sqlite" 2>/dev/null || true
# ── Demo mode ─────────────────────────────────────────────────────────────────
DEMO_MODE=${DEMO_MODE:-false}
DEMO_MODE_DELETE_ALL=${DEMO_MODE_DELETE_ALL:-false}
if [ "$DEMO_MODE" = "true" ] && [ "$DEMO_MODE_DELETE_ALL" = "true" ]; then
section "Demo Reset"
log "DEMO_MODE_DELETE_ALL — wiping all data"
for dir in "$DATA_DIRECTORY" "$PROCESSED_DIRECTORY" "$VIDEO_DIRECTORY" "$IMAGE_DIRECTORY"; do
if [ -n "$dir" ] && [ -d "$dir" ]; then
log "Wiping $dir"
find "$dir" -mindepth 1 -delete
fi
done
log "Wipe complete"
fi
# ── Analytics injection ───────────────────────────────────────────────────────
if [ -n "$ANALYTICS_TRACKING_SCRIPT" ]; then
section "Analytics"
log "Injecting tracking script into index.html"
python3 - "$ANALYTICS_TRACKING_SCRIPT" <<'EOF'
import sys, re
script = sys.argv[1].strip()
if not script.startswith('<'):
script = '<' + script
script = re.sub(r'/?script>?$', '', script, flags=re.IGNORECASE).rstrip('/')
script = script.rstrip() + '></script>'
path = '/app/build/index.html'
with open(path, 'r') as f:
content = f.read()
content = content.replace('</head>', script + '</head>', 1)
with open(path, 'w') as f:
f.write(content)
EOF
log "Analytics script injected"
fi
# ── Nginx ─────────────────────────────────────────────────────────────────────
section "Nginx"
log "Starting nginx"
nginx -g 'daemon on;'
log "Nginx ready"
# ── Environment ───────────────────────────────────────────────────────────────
export PATH=/usr/local/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64:/usr/local/lib:/usr/local/cuda/lib64:${LD_LIBRARY_PATH}
if [ -z "$SECRET_KEY" ]; then
export SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_hex(32))")
log "SECRET_KEY not set — generated ephemeral key for this session"
fi
# ── Database ──────────────────────────────────────────────────────────────────
section "Database"
log "Running migrations"
gosu appuser env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" flask db upgrade
log "Migrations complete"
# ── Game assets ───────────────────────────────────────────────────────────────
section "Game Assets"
log "Running asset migration"
gosu appuser env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" fireshare migrate-game-assets
log "Asset migration complete"
# ── Boomerang previews (first boot only) ──────────────────────────────────────
BOOMERANG_FLAG="$DATA_DIRECTORY/.boomerangs_generated"
if [ ! -f "$BOOMERANG_FLAG" ]; then
section "First Boot"
log "Generating boomerang previews"
gosu appuser env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" python -m fireshare.cli create-boomerang-posters || true
touch "$BOOMERANG_FLAG"
log "Boomerang generation complete"
fi
# ── Application ───────────────────────────────────────────────────────────────
section "Application"
log "Starting gunicorn (UID=$PUID GID=$PGID)"
echo ""
exec gosu appuser env PATH="$PATH" LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
gunicorn --config /app/server/gunicorn.conf.py \
--bind=127.0.0.1:5000 "fireshare:create_app(init_schedule=True)"