Leon4gr45 commited on
Commit
fbde0f1
·
verified ·
1 Parent(s): cbb648b

Add Supabase config and HF webhook URL

Browse files
Files changed (1) hide show
  1. start.sh +42 -61
start.sh CHANGED
@@ -3,39 +3,18 @@ set -e # Exit immediately if a command exits with a non-zero status.
3
 
4
  echo "--- Script Start ---"
5
  echo "Running as user: $(whoami) (UID: $(id -u), GID: $(id -g))"
 
6
 
7
  # --- Persistent Data Setup ---
8
  N8N_DATA_DIR="/data/.n8n"
9
- POSTGRES_DATA_DIR="/data/postgres"
10
- QDRANT_DATA_DIR="/data/qdrant_storage"
11
- OLLAMA_MODELS_DIR="/data/.ollama"
12
 
13
  echo "Ensuring application data directories exist..."
14
-
15
- # Create directories if they don't exist (may need root permissions)
16
- if [ ! -d "/data" ]; then
17
- echo "Creating /data directory..."
18
- mkdir -p /data
19
- fi
20
-
21
- # Try to create subdirectories, if we fail (permission denied), assume we're not root
22
- # and the directories should already exist with correct permissions from HF
23
- if ! mkdir -p "$N8N_DATA_DIR" "$POSTGRES_DATA_DIR" "$QDRANT_DATA_DIR" "$OLLAMA_MODELS_DIR" 2>/dev/null; then
24
- echo "Note: Could not create directories (may already exist or permission denied). Continuing..."
25
- fi
26
-
27
- # Change ownership to n8nuser if we have permissions
28
- if [ "$(id -u)" -eq 0 ]; then
29
- echo "Running as root. Changing ownership of /data to n8nuser..."
30
- chown -R n8nuser:n8nuser /data
31
- chmod -R u+rwx /data
32
- echo "Ownership changed successfully."
33
- else
34
- echo "Not running as root. Checking current permissions..."
35
- fi
36
-
37
- echo "Permissions of data directories in /data:"
38
- ls -ld "$N8N_DATA_DIR" "$POSTGRES_DATA_DIR" "$QDRANT_DATA_DIR" "$OLLAMA_MODELS_DIR" 2>/dev/null || echo "Some directories may not exist yet."
39
 
40
  ln -sfn "$N8N_DATA_DIR" /home/n8nuser/.n8n
41
  export OLLAMA_MODELS="$OLLAMA_MODELS_DIR"
@@ -49,8 +28,8 @@ POSTGRES_PORT="${DB_POSTGRESDB_PORT:-5432}" # Define port for consistency
49
  chmod u+rwx "$POSTGRES_DATA_DIR"
50
 
51
  if [ ! -d "$POSTGRES_DATA_DIR/base" ]; then
52
- echo "Initializing PostgreSQL database in $POSTGRES_DATA_DIR as user n8nuser..."
53
- su - n8nuser -c "/usr/lib/postgresql/14/bin/initdb -D '$POSTGRES_DATA_DIR' --username=n8nuser --no-locale --encoding=UTF8"
54
  if [ $? -ne 0 ]; then echo "ERROR: PostgreSQL initdb failed."; ls -ld "$POSTGRES_DATA_DIR"; exit 1; fi
55
 
56
  echo "PostgreSQL Initialized. Ownership/permissions of $POSTGRES_DATA_DIR after initdb:"
@@ -59,7 +38,7 @@ if [ ! -d "$POSTGRES_DATA_DIR/base" ]; then
59
  echo "Temporarily starting PostgreSQL to create database role and database..."
60
  # For pg_ctl, it's good practice to point to the PGDATA explicitly.
61
  # pg_ctl will find postgresql.conf within PGDATA.
62
- su - n8nuser -c "/usr/lib/postgresql/14/bin/pg_ctl -D '$POSTGRES_DATA_DIR' -o \"-p $POSTGRES_PORT -c listen_addresses='localhost'\" -w start"
63
 
64
  PG_ROLE_NAME="${DB_POSTGRESDB_USER:-n8n}"
65
  PG_PASSWORD="${DB_POSTGRESDB_PASSWORD}"
@@ -68,26 +47,27 @@ if [ ! -d "$POSTGRES_DATA_DIR/base" ]; then
68
  if [ -z "$PG_PASSWORD" ]; then echo "ERROR: DB_POSTGRESDB_PASSWORD is not set."; exit 1; fi
69
 
70
  echo "Creating PostgreSQL role '$PG_ROLE_NAME' and database '$PG_DB_NAME'..."
71
- su - n8nuser -c "psql -v ON_ERROR_STOP=1 --username=n8nuser --port='$POSTGRES_PORT' --host=localhost postgres <<-EOSQL
72
- CREATE ROLE \"$PG_ROLE_NAME\" WITH LOGIN PASSWORD '$PG_PASSWORD';
73
- CREATE DATABASE \"$PG_DB_NAME\" OWNER \"$PG_ROLE_NAME\";
74
  EOSQL
75
- "
76
  echo "PostgreSQL role and database created."
77
- su - n8nuser -c "/usr/lib/postgresql/14/bin/pg_ctl -D '$POSTGRES_DATA_DIR' -m fast -w stop"
78
  echo "Temporary PostgreSQL server stopped."
79
  else
80
  echo "PostgreSQL database found in $POSTGRES_DATA_DIR."
81
  fi
82
 
83
- echo "Starting PostgreSQL server for application use (as n8nuser)..."
84
- # Switch to n8nuser for running services
85
- su - n8nuser -c "/usr/lib/postgresql/14/bin/postgres -D '$POSTGRES_DATA_DIR' -p '$POSTGRES_PORT'" &
 
 
86
  PG_PID=$!
87
  echo "Waiting for PostgreSQL to start (PID: $PG_PID)..."
88
  max_wait=30
89
  count=0
90
- until pg_isready -h localhost -p "$POSTGRES_PORT" -U n8nuser -q || [ $count -eq $max_wait ]; do
91
  echo -n "."
92
  sleep 1
93
  count=$((count+1))
@@ -115,8 +95,8 @@ QDRANT_CONFIG_DIR="/qdrant/config"
115
  QDRANT_STORAGE_PATH_IN_CONFIG="/qdrant/storage"
116
  ln -sfn "$QDRANT_DATA_DIR" "$QDRANT_STORAGE_PATH_IN_CONFIG"
117
 
118
- echo "Starting Qdrant (as n8nuser)..."
119
- su - n8nuser -c "/usr/local/bin/qdrant --config-path '$QDRANT_CONFIG_DIR/config.yaml'" &
120
  QDRANT_PID=$!
121
  echo "Waiting for Qdrant to start (PID: $QDRANT_PID)..."
122
  until curl -sf http://localhost:6333/readyz > /dev/null; do
@@ -131,8 +111,8 @@ echo "Qdrant started."
131
  echo "--- Ollama Setup (running as $(whoami)) ---"
132
  echo "Ollama models will be stored in: $OLLAMA_MODELS_DIR"
133
 
134
- echo "Starting Ollama server (as n8nuser)..."
135
- su - n8nuser -c "ollama serve" &
136
  OLLAMA_PID=$!
137
  echo "Waiting for Ollama to start (PID: $OLLAMA_PID)..."
138
  until curl -sf http://localhost:11434/api/tags > /dev/null 2>&1 ; do
@@ -177,25 +157,26 @@ export N8N_USER_FOLDER="/home/n8nuser/.n8n"
177
  export GENAI_MODELS_N8N_DEFAULT_MODEL="$DEFAULT_MODEL"
178
  export DB_POSTGRESDB_PORT="$POSTGRES_PORT"
179
 
180
- # URLs are already set in Dockerfile ENV, but we can override if needed
181
- echo "N8N URLs configured:"
182
- echo " N8N_EDITOR_BASE_URL: $N8N_EDITOR_BASE_URL"
183
- echo " WEBHOOK_URL: $WEBHOOK_URL"
184
- echo " N8N_HOST: $N8N_HOST"
185
- echo " N8N_PORT: $N8N_PORT"
186
- echo " N8N_PROTOCOL: $N8N_PROTOCOL"
 
 
187
 
188
- # OAuth callback configuration for ClickUp compatibility
189
- # n8n's OAuth callback URL is constructed from WEBHOOK_URL + /rest/oauth2-credential/callback
190
- # ClickUp trims the path, so we need to ensure the base URL is correctly configured
191
- # In ClickUp's app settings, register: https://leon4gr45-n8n.hf.space/
192
- # n8n will automatically handle the full callback path internally
 
 
193
 
194
  # Optional: Increase n8n log level for more startup details
195
  # export N8N_LOG_LEVEL="debug"
196
 
197
- echo "Before su: environment variables"
198
- env | grep N8N
199
-
200
- echo "Starting n8n (as n8nuser) with highly permissive (INSECURE) embedding rules for diagnosis..."
201
- su n8nuser -c "echo 'Inside su:' && env | grep N8N && n8n start"
 
3
 
4
  echo "--- Script Start ---"
5
  echo "Running as user: $(whoami) (UID: $(id -u), GID: $(id -g))"
6
+ # ... (rest of initial echos and directory setup remains the same) ...
7
 
8
  # --- Persistent Data Setup ---
9
  N8N_DATA_DIR="/data/.n8n"
10
+ POSTGRES_DATA_DIR="/data/postgres" # Should be owned by n8nuser (UID 1000)
11
+ QDRANT_DATA_DIR="/data/qdrant_storage" # Should be owned by n8nuser
12
+ OLLAMA_MODELS_DIR="/data/.ollama" # Should be owned by n8nuser
13
 
14
  echo "Ensuring application data directories exist..."
15
+ mkdir -p "$N8N_DATA_DIR" "$POSTGRES_DATA_DIR" "$QDRANT_DATA_DIR" "$OLLAMA_MODELS_DIR"
16
+ echo "Permissions of data directories in /data (should be owned by $(whoami)):"
17
+ ls -ld "$N8N_DATA_DIR" "$POSTGRES_DATA_DIR" "$QDRANT_DATA_DIR" "$OLLAMA_MODELS_DIR"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  ln -sfn "$N8N_DATA_DIR" /home/n8nuser/.n8n
20
  export OLLAMA_MODELS="$OLLAMA_MODELS_DIR"
 
28
  chmod u+rwx "$POSTGRES_DATA_DIR"
29
 
30
  if [ ! -d "$POSTGRES_DATA_DIR/base" ]; then
31
+ echo "Initializing PostgreSQL database in $POSTGRES_DATA_DIR as user $(whoami)..."
32
+ /usr/lib/postgresql/14/bin/initdb -D "$POSTGRES_DATA_DIR" --username=$(whoami) --no-locale --encoding=UTF8
33
  if [ $? -ne 0 ]; then echo "ERROR: PostgreSQL initdb failed."; ls -ld "$POSTGRES_DATA_DIR"; exit 1; fi
34
 
35
  echo "PostgreSQL Initialized. Ownership/permissions of $POSTGRES_DATA_DIR after initdb:"
 
38
  echo "Temporarily starting PostgreSQL to create database role and database..."
39
  # For pg_ctl, it's good practice to point to the PGDATA explicitly.
40
  # pg_ctl will find postgresql.conf within PGDATA.
41
+ /usr/lib/postgresql/14/bin/pg_ctl -D "$POSTGRES_DATA_DIR" -o "-p $POSTGRES_PORT -c listen_addresses='localhost'" -w start
42
 
43
  PG_ROLE_NAME="${DB_POSTGRESDB_USER:-n8n}"
44
  PG_PASSWORD="${DB_POSTGRESDB_PASSWORD}"
 
47
  if [ -z "$PG_PASSWORD" ]; then echo "ERROR: DB_POSTGRESDB_PASSWORD is not set."; exit 1; fi
48
 
49
  echo "Creating PostgreSQL role '$PG_ROLE_NAME' and database '$PG_DB_NAME'..."
50
+ psql -v ON_ERROR_STOP=1 --username=$(whoami) --port="$POSTGRES_PORT" --host=localhost postgres <<-EOSQL
51
+ CREATE ROLE "$PG_ROLE_NAME" WITH LOGIN PASSWORD '$PG_PASSWORD';
52
+ CREATE DATABASE "$PG_DB_NAME" OWNER "$PG_ROLE_NAME";
53
  EOSQL
 
54
  echo "PostgreSQL role and database created."
55
+ /usr/lib/postgresql/14/bin/pg_ctl -D "$POSTGRES_DATA_DIR" -m fast -w stop
56
  echo "Temporary PostgreSQL server stopped."
57
  else
58
  echo "PostgreSQL database found in $POSTGRES_DATA_DIR."
59
  fi
60
 
61
+ echo "Starting PostgreSQL server for application use (as $(whoami))..."
62
+ # The postgres command will use the postgresql.conf found within $POSTGRES_DATA_DIR
63
+ # We don't need to specify -c config_file if it's inside PGDATA.
64
+ # Just ensure the port is correctly passed if not default.
65
+ /usr/lib/postgresql/14/bin/postgres -D "$POSTGRES_DATA_DIR" -p "$POSTGRES_PORT" &
66
  PG_PID=$!
67
  echo "Waiting for PostgreSQL to start (PID: $PG_PID)..."
68
  max_wait=30
69
  count=0
70
+ until pg_isready -h localhost -p "$POSTGRES_PORT" -U $(whoami) -q || [ $count -eq $max_wait ]; do
71
  echo -n "."
72
  sleep 1
73
  count=$((count+1))
 
95
  QDRANT_STORAGE_PATH_IN_CONFIG="/qdrant/storage"
96
  ln -sfn "$QDRANT_DATA_DIR" "$QDRANT_STORAGE_PATH_IN_CONFIG"
97
 
98
+ echo "Starting Qdrant..."
99
+ /usr/local/bin/qdrant --config-path "$QDRANT_CONFIG_DIR/config.yaml" &
100
  QDRANT_PID=$!
101
  echo "Waiting for Qdrant to start (PID: $QDRANT_PID)..."
102
  until curl -sf http://localhost:6333/readyz > /dev/null; do
 
111
  echo "--- Ollama Setup (running as $(whoami)) ---"
112
  echo "Ollama models will be stored in: $OLLAMA_MODELS_DIR"
113
 
114
+ echo "Starting Ollama server..."
115
+ ollama serve &
116
  OLLAMA_PID=$!
117
  echo "Waiting for Ollama to start (PID: $OLLAMA_PID)..."
118
  until curl -sf http://localhost:11434/api/tags > /dev/null 2>&1 ; do
 
157
  export GENAI_MODELS_N8N_DEFAULT_MODEL="$DEFAULT_MODEL"
158
  export DB_POSTGRESDB_PORT="$POSTGRES_PORT"
159
 
160
+ # --- MOST PERMISSIVE EMBEDDING CONFIGURATION FOR DIAGNOSIS ---
161
+ echo "WARNING: USING HIGHLY PERMISSIVE (INSECURE) EMBEDDING SETTINGS FOR DIAGNOSIS!"
162
+ export N8N_SEC_EMBEDDER_HEADER_MODE="allowAll"
163
+ # The mode "allowAll" should theoretically make n8n send headers that allow embedding from anywhere.
164
+ # This is a simpler way to test than just relying on the regex if there's any doubt.
165
+ # If "allowAll" doesn't work, then N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX=".*" is the next most forceful.
166
+ # We'll also set the regex to ".*" just in case "allowAll" isn't picked up or is deprecated.
167
+ export N8N_SEC_EMBEDDER_HEADER_ALLOW_FROM_REGEX=".*"
168
+ # --- End Embedding Configuration ---
169
 
170
+ export N8N_SEC_ALLOW_ALL_ORIGINS_FOR_WEBHOOKS="true"
171
+ export N8N_RUNNERS_ENABLED="true" # As per n8n deprecation warning
172
+
173
+ N8N_SPACE_URL="https://leon4gr45-n8n.hf.space/"
174
+ export N8N_EDITOR_BASE_URL="$N8N_SPACE_URL"
175
+ export WEBHOOK_URL="$N8N_SPACE_URL"
176
+ echo "N8N URLs set to: $N8N_EDITOR_BASE_URL"
177
 
178
  # Optional: Increase n8n log level for more startup details
179
  # export N8N_LOG_LEVEL="debug"
180
 
181
+ echo "Starting n8n with highly permissive (INSECURE) embedding rules for diagnosis..."
182
+ exec n8n start