Skip to content

Commit 018cf23

Browse files
ImTotemclaude
andcommitted
refactor(infra): remove credential auto-setup from init_n8n.sh
Postgres and Google Sheets credentials are set up manually in n8n UI. Remove setup_pg_credential function and SA file mount. Keep GOOGLE_SHEETS_ID env for workflow $env expression. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 546f201 commit 018cf23

2 files changed

Lines changed: 5 additions & 50 deletions

File tree

infra/docker/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ services:
4040
volumes:
4141
- n8n-data:/home/node/.n8n
4242
- ../../workflows:/workflows:ro
43-
- ../../${GOOGLE_SERVICE_ACCOUNT_FILE}:/credentials/sa.json:ro
4443
networks:
4544
- bcsd
4645

infra/scripts/init_n8n.sh

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# n8n workflow import + owner setup + Postgres credential
4+
# n8n workflow import + owner setup
55
# Idempotent: skips if already configured
6-
# Google Sheets credential must be set up manually in n8n UI
6+
# Credentials (Postgres, Google Sheets) must be set up manually in n8n UI
77

88
COMPOSE="sudo docker compose -p bcsd-app --env-file .env -f infra/docker/docker-compose.yml"
99
MAX_RETRIES=15
@@ -28,17 +28,6 @@ workflow_exists() {
2828
[ "$count" -gt 0 ]
2929
}
3030

31-
import_workflow() {
32-
local file="$1"
33-
local name="$2"
34-
if workflow_exists "$name"; then
35-
echo " Workflow '$name' already exists — skipping"
36-
return 0
37-
fi
38-
echo " Importing '$name'..."
39-
$COMPOSE exec -T n8n n8n import:workflow --input="$file" 2>&1 || true
40-
}
41-
4231
delete_workflow() {
4332
local name="$1"
4433
if ! workflow_exists "$name"; then
@@ -76,36 +65,6 @@ print('setup' if d.get('userManagement',{}).get('showSetupOnFirstLoad') else 'do
7665
echo " Owner created: ${N8N_AUTH_USER}@bcsdlab.com"
7766
}
7867

79-
setup_pg_credential() {
80-
local existing
81-
existing=$($COMPOSE exec -T n8n n8n list:credential 2>&1 | grep -c "BCSD PostgreSQL" || true)
82-
if [ "$existing" -gt 0 ]; then
83-
echo " Postgres credential already exists — skipping"
84-
return 0
85-
fi
86-
echo " Creating Postgres credential from .env..."
87-
set -a; source .env; set +a
88-
local cred_json
89-
cred_json=$(python3 -c "
90-
import json, sys, uuid
91-
cred = [{
92-
'id': str(uuid.uuid4()),
93-
'name': 'BCSD PostgreSQL',
94-
'type': 'postgres',
95-
'data': {
96-
'host': '${POSTGRES_HOST:-postgres}',
97-
'port': ${POSTGRES_PORT:-5432},
98-
'database': '${POSTGRES_DB}',
99-
'user': '${POSTGRES_USER}',
100-
'password': '${POSTGRES_PASSWORD}',
101-
'ssl': 'disable'
102-
}
103-
}]
104-
json.dump(cred, sys.stdout)
105-
")
106-
echo "$cred_json" | $COMPOSE exec -T n8n n8n import:credentials --input=/dev/stdin
107-
}
108-
10968
echo "=== n8n Init ==="
11069

11170
echo "1. Starting n8n..."
@@ -121,17 +80,14 @@ fi
12180
echo "3. Setting up owner account..."
12281
setup_owner
12382

124-
echo "4. Setting up Postgres credential..."
125-
setup_pg_credential
126-
127-
echo "5. Replacing workflows..."
83+
echo "4. Replacing workflows..."
12884
delete_workflow "Link Auto-Expiration (hourly)"
12985
delete_workflow "Link Auto-Expiration (1min)"
13086
delete_workflow "PG → Sheets Sync (5min)"
13187

132-
echo "6. Importing workflows..."
88+
echo "5. Importing workflows..."
13389
$COMPOSE exec -T n8n n8n import:workflow --input="/workflows/pg_sheets_sync.json" 2>&1
13490
$COMPOSE exec -T n8n n8n import:workflow --input="/workflows/link_auto_expire.json" 2>&1
13591

13692
echo "=== n8n Init complete ==="
137-
echo "NOTE: Set up Google Sheets credential in n8n UI if first deploy"
93+
echo "NOTE: Set up Postgres + Google Sheets credentials in n8n UI if first deploy"

0 commit comments

Comments
 (0)