Update docker-entrypoint-wrapper.sh

#8
Files changed (1) hide show
  1. docker-entrypoint-wrapper.sh +22 -47
docker-entrypoint-wrapper.sh CHANGED
@@ -1,55 +1,29 @@
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
@@ -57,25 +31,26 @@ export PORT=3000
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
- # Pass through AUTH_DISABLE_SIGNUP value if set, default to false if not set
72
  if [ -n "$AUTH_DISABLE_SIGNUP" ]; then
73
  export AUTH_DISABLE_SIGNUP="$AUTH_DISABLE_SIGNUP"
74
  else
75
  export AUTH_DISABLE_SIGNUP="false"
76
  fi
77
 
78
- # Start Next.js in the background
 
 
 
79
  echo "Starting Next.js..."
80
- ./web/entrypoint.sh node ./web/server.js \
81
- --keepAliveTimeout 110000
 
1
  #!/bin/sh
2
 
3
+ echo "Using remote PostgreSQL on Neon.tech..."
 
 
 
 
4
 
5
+ # Skip local PostgreSQL init and start
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  # Set NEXTAUTH_URL based on SPACE_HOST if available
8
  if [ -n "$SPACE_ID" ]; then
9
+ echo "Setting NEXTAUTH_URL to https://${SPACE_HOST}"
 
10
  export NEXTAUTH_URL="https://${SPACE_HOST}"
11
  else
12
  echo "WARNING: SPACE_ID not found"
13
  fi
14
 
15
+ # Set Neon PostgreSQL connection environment variables
16
+ export PGHOST='ep-steep-dream-adqtvjel-pooler.c-2.us-east-1.aws.neon.tech'
17
+ export PGDATABASE='neondb'
18
+ export PGUSER='neondb_owner'
19
+ export PGPASSWORD='npg_Qq0B1uWRXavx'
20
+ export PGSSLMODE='require'
21
+ export PGCHANNELBINDING='require'
22
+
23
+ # Compose the DATABASE_URL
24
+ export DATABASE_URL="postgresql://${PGUSER}:${PGPASSWORD}@${PGHOST}:5432/${PGDATABASE}?sslmode=${PGSSLMODE}&channel_binding=${PGCHANNELBINDING}"
25
 
26
+ # Export environment variables to influence Next.js binding
27
  export HOSTNAME="0.0.0.0"
28
  export HOST="0.0.0.0"
29
  export PORT=3000
 
31
  # Disable CSP headers to allow for embedded use within HF
32
  export LANGFUSE_CSP_DISABLE="true"
33
 
34
+ # Preset OAuth env vars based on injected space variables
 
35
  export AUTH_CUSTOM_CLIENT_ID=$OAUTH_CLIENT_ID
36
  export AUTH_CUSTOM_CLIENT_SECRET=$OAUTH_CLIENT_SECRET
37
  export AUTH_CUSTOM_ISSUER=$OPENID_PROVIDER_URL
38
  export AUTH_CUSTOM_SCOPE=$OAUTH_SCOPES
39
  export AUTH_CUSTOM_NAME="Hugging Face"
40
 
41
+ # Disable authentication via username/password
42
  export AUTH_DISABLE_USERNAME_PASSWORD="true"
43
 
44
+ # Handle signup disabling logic
45
  if [ -n "$AUTH_DISABLE_SIGNUP" ]; then
46
  export AUTH_DISABLE_SIGNUP="$AUTH_DISABLE_SIGNUP"
47
  else
48
  export AUTH_DISABLE_SIGNUP="false"
49
  fi
50
 
51
+ # Log connection details (don't do this in production with real passwords!)
52
+ echo "Connecting to Neon PostgreSQL at $PGHOST"
53
+
54
+ # Start Next.js app
55
  echo "Starting Next.js..."
56
+ ./web/entrypoint.sh node ./web/server.js