Spaces:
Paused
Paused
Create docker-entrypoint-wrapper.sh
Browse files- docker-entrypoint-wrapper.sh +84 -0
docker-entrypoint-wrapper.sh
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/sh
|
2 |
+
|
3 |
+
# Create necessary directories in the persistent /data volume
|
4 |
+
echo "Creating necessary directories in the persistent /data volume..."
|
5 |
+
mkdir -p /data/postgresql/data /data/postgresql/run
|
6 |
+
chmod 0700 /data/postgresql/data
|
7 |
+
chmod 0755 /data/postgresql/run
|
8 |
+
|
9 |
+
# Initialize PostgreSQL if not already initialized
|
10 |
+
echo "Initializing PostgreSQL if not already initialized..."
|
11 |
+
if [ ! -f "/data/postgresql/data/PG_VERSION" ]; then
|
12 |
+
# Initialize database
|
13 |
+
echo "Initializing database..."
|
14 |
+
initdb -D /data/postgresql/data
|
15 |
+
|
16 |
+
# Modify pg_hba.conf to allow local connections
|
17 |
+
echo "local all all trust" > /data/postgresql/data/pg_hba.conf
|
18 |
+
echo "host all all 127.0.0.1/32 trust" >> /data/postgresql/data/pg_hba.conf
|
19 |
+
echo "host all all ::1/128 trust" >> /data/postgresql/data/pg_hba.conf
|
20 |
+
echo "host all all 0.0.0.0/0 trust" >> /data/postgresql/data/pg_hba.conf
|
21 |
+
echo "host all all ::/0 trust" >> /data/postgresql/data/pg_hba.conf
|
22 |
+
fi
|
23 |
+
|
24 |
+
# Start PostgreSQL with the persistent directories
|
25 |
+
echo "Starting PostgreSQL..."
|
26 |
+
pg_ctl -D /data/postgresql/data -o "-c listen_addresses='*' -c unix_socket_directories='/data/postgresql/run'" start
|
27 |
+
|
28 |
+
# Wait for PostgreSQL to be ready
|
29 |
+
echo "Waiting for PostgreSQL to be ready..."
|
30 |
+
until pg_isready -h localhost; do
|
31 |
+
echo "Waiting for PostgreSQL to be ready..."
|
32 |
+
sleep 1
|
33 |
+
done
|
34 |
+
|
35 |
+
# Create database and roles
|
36 |
+
echo "Creating database and roles..."
|
37 |
+
createuser -h /data/postgresql/run -s postgres || true
|
38 |
+
createdb -h /data/postgresql/run node || true
|
39 |
+
|
40 |
+
# Set NEXTAUTH_URL based on SPACE_HOST if available
|
41 |
+
if [ -n "$SPACE_ID" ]; then
|
42 |
+
echo "Setting NEXTAUTH_URL to https://huggingface.co/spaces/${SPACE_ID}"
|
43 |
+
# export NEXTAUTH_URL="https://huggingface.co/spaces/${SPACE_ID}"
|
44 |
+
export NEXTAUTH_URL="https://${SPACE_HOST}"
|
45 |
+
else
|
46 |
+
echo "WARNING: SPACE_ID not found"
|
47 |
+
fi
|
48 |
+
|
49 |
+
# Update DATABASE_URL to use TCP connection
|
50 |
+
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/node"
|
51 |
+
|
52 |
+
# Export these environment variables to influence Next.js binding
|
53 |
+
export HOSTNAME="0.0.0.0"
|
54 |
+
export HOST="0.0.0.0"
|
55 |
+
export PORT=3000
|
56 |
+
|
57 |
+
# Disable CSP headers to allow for embedded use within HF
|
58 |
+
export LANGFUSE_CSP_DISABLE="true"
|
59 |
+
|
60 |
+
# Preset oauth env vars based on injected space variables
|
61 |
+
# See https://huggingface.co/docs/hub/en/spaces-oauth#create-an-oauth-app
|
62 |
+
export AUTH_CUSTOM_CLIENT_ID=$OAUTH_CLIENT_ID
|
63 |
+
export AUTH_CUSTOM_CLIENT_SECRET=$OAUTH_CLIENT_SECRET
|
64 |
+
export AUTH_CUSTOM_ISSUER=$OPENID_PROVIDER_URL
|
65 |
+
export AUTH_CUSTOM_SCOPE=$OAUTH_SCOPES
|
66 |
+
export AUTH_CUSTOM_NAME="Hugging Face"
|
67 |
+
|
68 |
+
# Disable authentication via username/password to enforce authentication via HF
|
69 |
+
export AUTH_DISABLE_USERNAME_PASSWORD="true"
|
70 |
+
|
71 |
+
# Setup default org and project
|
72 |
+
export LANGFUSE_INIT_ORG_ID="default"
|
73 |
+
export LANGFUSE_INIT_ORG_NAME="default"
|
74 |
+
export LANGFUSE_INIT_PROJECT_ID="default"
|
75 |
+
export LANGFUSE_INIT_PROJECT_NAME="default"
|
76 |
+
export LANGFUSE_DEFAULT_ORG_ID="default"
|
77 |
+
export LANGFUSE_DEFAULT_PROJECT_ID="default"
|
78 |
+
export LANGFUSE_DEFAULT_ORG_ROLE="MEMBER"
|
79 |
+
export LANGFUSE_DEFAULT_PROJECT_ROLE="MEMBER"
|
80 |
+
|
81 |
+
# Start Next.js in the background
|
82 |
+
echo "Starting Next.js..."
|
83 |
+
./web/entrypoint.sh node ./web/server.js \
|
84 |
+
--keepAliveTimeout 110000
|