mirror of
https://github.com/kossakovsky/n8n-install.git
synced 2026-03-07 14:23:08 +00:00
feat(n8n): add make import command for workflow imports
This commit is contained in:
@@ -39,6 +39,7 @@ This is **n8n-install**, a Docker Compose-based installer that provides a compre
|
||||
- `scripts/apply_update.sh`: Applies updates after git sync
|
||||
- `scripts/docker_cleanup.sh`: Removes unused Docker resources (used by `make clean`)
|
||||
- `scripts/download_top_workflows.sh`: Downloads community n8n workflows
|
||||
- `scripts/import_workflows.sh`: Imports workflows from `n8n/backup/workflows/` into n8n (used by `make import`)
|
||||
|
||||
**Project Name**: All docker-compose commands use `-p localai` (defined in Makefile as `PROJECT_NAME := localai`).
|
||||
|
||||
@@ -75,6 +76,7 @@ make monitor # Live CPU/memory monitoring (docker stats)
|
||||
make restart # Restart all services
|
||||
make show-restarts # Show restart count per container
|
||||
make doctor # Run system diagnostics (DNS, SSL, containers, disk, memory)
|
||||
make import # Import n8n workflows from backup
|
||||
|
||||
make switch-beta # Switch to develop branch and update
|
||||
make switch-stable # Switch to main branch and update
|
||||
|
||||
6
Makefile
6
Makefile
@@ -1,4 +1,4 @@
|
||||
.PHONY: help install update update-preview clean clean-all logs status monitor restart show-restarts doctor switch-beta switch-stable
|
||||
.PHONY: help install update update-preview clean clean-all logs status monitor restart show-restarts doctor switch-beta switch-stable import
|
||||
|
||||
PROJECT_NAME := localai
|
||||
|
||||
@@ -18,6 +18,7 @@ help:
|
||||
@echo " make restart Restart all services"
|
||||
@echo " make show-restarts Show restart count per container"
|
||||
@echo " make doctor Run system diagnostics"
|
||||
@echo " make import Import n8n workflows from backup"
|
||||
@echo ""
|
||||
@echo " make switch-beta Switch to beta (develop branch)"
|
||||
@echo " make switch-stable Switch to stable (main branch)"
|
||||
@@ -75,3 +76,6 @@ switch-stable:
|
||||
git restore docker-compose.yml
|
||||
git checkout main
|
||||
sudo bash ./scripts/update.sh
|
||||
|
||||
import:
|
||||
docker compose -p $(PROJECT_NAME) run --rm -e FORCE_IMPORT=true n8n-import
|
||||
|
||||
@@ -312,6 +312,7 @@ The project includes a Makefile for simplified command execution:
|
||||
| `make monitor` | Live CPU/memory monitoring |
|
||||
| `make restart` | Restart all services |
|
||||
| `make show-restarts` | Show restart count per container |
|
||||
| `make import` | Import n8n workflows from backup |
|
||||
|
||||
### Diagnostics
|
||||
|
||||
|
||||
@@ -177,10 +177,10 @@ services:
|
||||
<<: *service-n8n-env
|
||||
RUN_N8N_IMPORT: ${RUN_N8N_IMPORT:-false}
|
||||
entrypoint: /bin/sh
|
||||
command: /scripts/n8n_import_script.sh
|
||||
command: /scripts/import_workflows.sh
|
||||
volumes:
|
||||
- ./n8n/backup:/backup
|
||||
- ./n8n/n8n_import_script.sh:/scripts/n8n_import_script.sh:ro
|
||||
- ./scripts/import_workflows.sh:/scripts/import_workflows.sh:ro
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Exit immediately if RUN_N8N_IMPORT is not set to true
|
||||
if [ "$RUN_N8N_IMPORT" != "true" ]; then
|
||||
echo 'Skipping n8n import based on RUN_N8N_IMPORT environment variable.'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
echo 'Importing credentials...'
|
||||
find /backup/credentials -maxdepth 1 -type f -not -name '.gitkeep' -print -exec sh -c '
|
||||
echo "Attempting to import credential file: $1";
|
||||
n8n import:credentials --input="$1" || echo "Error importing credential file: $1"
|
||||
' sh {} \;
|
||||
|
||||
echo 'Importing workflows...'
|
||||
find /backup/workflows -maxdepth 1 -type f -not -name '.gitkeep' -print -exec sh -c '
|
||||
echo "Attempting to import workflow file: $1";
|
||||
n8n import:workflow --input="$1" || echo "Error importing workflow file: $1"
|
||||
' sh {} \;
|
||||
|
||||
echo 'Import process finished.'
|
||||
62
scripts/import_workflows.sh
Normal file
62
scripts/import_workflows.sh
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/bin/sh
|
||||
# Import n8n workflows and credentials from backup directory
|
||||
# This script runs inside the n8n-import container
|
||||
|
||||
# Exit if neither import flag is set
|
||||
if [ "$RUN_N8N_IMPORT" != "true" ] && [ "$FORCE_IMPORT" != "true" ]; then
|
||||
echo 'Skipping n8n import based on environment variables.'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
# Import credentials first
|
||||
echo 'Importing credentials...'
|
||||
CRED_FILES=$(find /backup/credentials -maxdepth 1 -type f -not -name '.gitkeep' 2>/dev/null || true)
|
||||
if [ -n "$CRED_FILES" ]; then
|
||||
CRED_COUNT=$(echo "$CRED_FILES" | wc -l | tr -d ' ')
|
||||
CURRENT=0
|
||||
echo "$CRED_FILES" | while IFS= read -r file; do
|
||||
CURRENT=$((CURRENT + 1))
|
||||
filename=$(basename "$file")
|
||||
echo "[$CURRENT/$CRED_COUNT] Importing credential: $filename"
|
||||
n8n import:credentials --input="$file" 2>/dev/null || echo " Error importing: $filename"
|
||||
done
|
||||
fi
|
||||
|
||||
# Import workflows
|
||||
echo ''
|
||||
echo 'Importing workflows...'
|
||||
WORKFLOW_FILES=$(find /backup/workflows -maxdepth 1 -type f -not -name '.gitkeep' 2>/dev/null || true)
|
||||
if [ -z "$WORKFLOW_FILES" ]; then
|
||||
echo 'No workflows found to import.'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TOTAL=$(echo "$WORKFLOW_FILES" | wc -l | tr -d ' ')
|
||||
echo "Found $TOTAL workflows to import"
|
||||
echo ''
|
||||
|
||||
# Use a counter file since pipes create subshells
|
||||
COUNTER_FILE=$(mktemp)
|
||||
echo "0" > "$COUNTER_FILE"
|
||||
|
||||
echo "$WORKFLOW_FILES" | while IFS= read -r file; do
|
||||
CURRENT=$(cat "$COUNTER_FILE")
|
||||
CURRENT=$((CURRENT + 1))
|
||||
echo "$CURRENT" > "$COUNTER_FILE"
|
||||
|
||||
filename=$(basename "$file")
|
||||
printf "[%3d/%d] %s" "$CURRENT" "$TOTAL" "$filename"
|
||||
|
||||
if n8n import:workflow --input="$file" >/dev/null 2>&1; then
|
||||
echo " OK"
|
||||
else
|
||||
echo " FAILED"
|
||||
fi
|
||||
done
|
||||
|
||||
rm -f "$COUNTER_FILE"
|
||||
|
||||
echo ''
|
||||
echo 'Import complete!'
|
||||
@@ -418,6 +418,7 @@
|
||||
{ cmd: 'make show-restarts', desc: 'Show restart count per container' },
|
||||
{ cmd: 'make doctor', desc: 'Run system diagnostics' },
|
||||
{ cmd: 'make update', desc: 'Update system and services' },
|
||||
{ cmd: 'make import', desc: 'Import n8n workflows from backup' },
|
||||
{ cmd: 'make clean', desc: 'Remove unused Docker resources' }
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user