n8n Automated Workflow Deployment
Status: Complete
Version: v4
Purpose: Automated n8n workflow import during Docker deployment
Overview
This document describes the automated n8n workflow deployment system implemented for NudgeCampaign v4. Workflows are now automatically imported when the Docker containers start, eliminating manual import steps.
Architecture
Components
Workflow Files (
/n8n-workflows/)campaign-processor.json- Main campaign sending workflowwelcome-series.json- Welcome email automation
Import Scripts (
/scripts/)import-n8n-workflows.sh- Core import logicdocker-entrypoint.sh- Docker container entrypointimport-via-api.sh- Manual import option
Docker Integration
- Modified
Dockerfile.devto include scripts and workflows - Entrypoint script runs import automatically
- Modified
How It Works
Automatic Import (Docker)
When you run docker-compose up, the following happens:
Container Startup
- Docker builds the image with workflows and scripts included
- Entrypoint script (
docker-entrypoint.sh) is executed
Background Import Process
- Script waits 30 seconds for n8n to fully initialize
- Connects to n8n API using API key authentication
- Imports each workflow JSON file
- Creates database credentials
- Activates workflows
Verification
- Check n8n UI at http://localhost:5678
- Login: admin / password
- Workflows should appear in the workflow list
API Key Configuration
IMPORTANT: n8n requires an API key for programmatic access. You must:
First-time Setup (Manual):
- Access n8n UI at http://localhost:5678
- Login with admin/password
- Navigate to Settings β API
- Generate an API key
- Save it to
.envfile asN8N_API_KEY
Example API Key (for reference):
N8N_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIwZTVkZTM5Ni04Mzg3LTQyYWQtYmZmMi0wZDExYWE5MTNmNzEiLCJpc3MiOiJuOG4iLCJhdWQiOiJwdWJsaWMtYXBpIiwiaWF0IjoxNzU0MjMwMTQ2fQ.PcuqTYftCXV2bD9wN76Ho9vAtLP4Wv_19a8Rew_tvrYAutomated Import will then use this key for all API operations
Manual Import (Host Machine)
If automatic import fails or you need to re-import:
cd nudgecampaign-mvp-v4
./scripts/import-via-api.sh
This script:
- Connects to running n8n instance
- Imports workflows from
n8n-workflows/directory - Sets up database credentials
- Activates all workflows
Features
Smart Import Logic
- Duplicate Prevention: Checks if workflows already exist before importing
- Retry Logic: Waits up to 150 seconds for n8n to be ready
- Error Handling: Continues even if some workflows fail
- Credential Setup: Automatically creates PostgreSQL credentials
Workflow Preparation
Before import, the script:
- Removes existing workflow IDs
- Removes version IDs
- Removes metadata
- Ensures clean import
Database Credentials
Automatically creates "NudgeCampaign DB" credential:
- Host:
supabase-db(Docker) orlocalhost(manual) - Port: 5432 (Docker) or 54322 (manual)
- Database: postgres
- User: postgres
- Password: postgres
Deployment Commands
Full Stack Deployment
# Start all services with automatic workflow import
docker-compose up -d
# View import logs
docker-compose logs app | grep "n8n"
# Verify workflows are imported
curl -u admin:password http://localhost:5678/api/v1/workflows
Rebuild After Workflow Changes
# Rebuild container to include new workflows
docker-compose build app
# Restart with new workflows
docker-compose up -d
Manual Workflow Management
# Import workflows manually
./scripts/import-via-api.sh
# Check n8n status
curl -u admin:password http://localhost:5678/api/v1/workflows
# Access n8n UI
open http://localhost:5678
Troubleshooting
Workflows Not Appearing
Check Import Logs
docker-compose logs app | grep "workflow"Verify n8n is Running
docker-compose ps n8nManual Import
./scripts/import-via-api.sh
Import Fails
n8n Not Ready
- The script waits 30 seconds by default
- Increase wait time in
docker-entrypoint.shif needed
Authentication Issues
- Verify credentials in docker-compose.yml
- Default: admin / password
Network Issues
- Ensure containers are on same network
- Check
nudge-network-v4in docker-compose.yml
Database Connection Issues
Wrong Credentials
- Check PostgreSQL is running:
docker-compose ps supabase-db - Verify connection from n8n container
- Check PostgreSQL is running:
Manual Credential Setup
- Open n8n UI
- Go to Credentials
- Add PostgreSQL credential manually
Adding New Workflows
Create Workflow JSON
# Export from n8n UI or create manually cp your-workflow.json n8n-workflows/Rebuild Container
docker-compose build app docker-compose up -dOr Import Manually
./scripts/import-via-api.sh
Security Notes
- Basic auth credentials are hardcoded for development
- Change credentials for production deployment
- Use environment variables for sensitive data
- Consider using n8n's built-in user management
Benefits
- Zero Manual Steps: Workflows import automatically on deployment
- Idempotent: Safe to run multiple times
- Error Recovery: Continues even if some imports fail
- Complete Setup: Includes credential configuration
- Flexible: Works with Docker or standalone
Next Steps
For production deployment:
- Move credentials to environment variables
- Add workflow versioning
- Implement backup/restore functionality
- Add monitoring for workflow health
- Create CI/CD pipeline for workflow updates