Skip to content

n8io/n8n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐳 Docker Compose Homelab

A complete n8n automation platform with Caddy reverse proxy, automated refresh capabilities, and cross-platform support for macOS and Ubuntu.

πŸš€ Quick Start

1. Initial Setup

# Generate secure credentials and configure domain
./scripts/generate-secrets.sh

# Start the n8n platform
docker compose up -d

2. Refresh Services (OS-Aware)

# Automatically detects your OS and refreshes services
./scripts/refresh.sh

3. Setup Cron Job (OS-Aware)

# Set up daily refresh at 2 AM
./scripts/cron/install.sh daily

# Set up weekly refresh on Sunday at 3 AM
./scripts/cron/install.sh weekly

# Set up monthly refresh on 1st at 4 AM
./scripts/cron/install.sh monthly

# Custom schedule (every 6 hours)
./scripts/cron/install.sh custom "0 */6 * * *"

# Remove cron job
./scripts/cron/install.sh remove

# Check status
./scripts/cron/install.sh status

4. Check Cron Job Status (OS-Aware)

# Quick status check
./scripts/cron/check.sh

# Detailed analysis
./scripts/cron/check.sh detailed

# Show help
./scripts/cron/check.sh help

πŸ“ Project Structure

homelab/
β”œβ”€β”€ docker-compose.yml            # Docker Compose configuration (n8n + Caddy + PostgreSQL)
β”œβ”€β”€ .env                          # Environment variables (generated by generate-secrets.sh)
β”œβ”€β”€ scripts/                      # All scripts organized by type
β”‚   β”œβ”€β”€ refresh.sh                # 🎯 Main OS-aware refresh script
β”‚   β”œβ”€β”€ generate-secrets.sh       # πŸ” Cross-platform security & setup script
β”‚   └── cron/                     # Cron job management scripts
β”‚       β”œβ”€β”€ install.sh            # 🎯 Install/setup cron jobs
β”‚       β”œβ”€β”€ check.sh              # πŸ” Check cron job status
β”‚       └── test-env.sh           # πŸ§ͺ Test cron environment
β”œβ”€β”€ docs/                         # Documentation
β”‚   β”œβ”€β”€ ubuntu-setup-guide.md
β”‚   └── crontab-example.txt
└── logs/                         # Log files (auto-created)
    β”œβ”€β”€ refresh-YYYYMMDD.log
    └── cron-test-YYYYMMDD-HHMMSS.log

🎯 Main Scripts

refresh.sh - Universal Refresh Script

  • βœ… OS-Aware: Automatically detects macOS vs Ubuntu/Linux
  • βœ… Idempotent: Safe to run multiple times
  • βœ… Comprehensive: Graceful shutdown, image pull, restart, health checks
  • βœ… Logging: Detailed logs with emojis and timestamps
  • βœ… Locking: Prevents concurrent runs
  • βœ… Resource Monitoring: Disk space and memory checks

cron/install.sh - Universal Cron Setup Script

  • βœ… OS-Aware: Adapts to macOS and Ubuntu environments
  • βœ… Idempotent: Safe to run multiple times, removes old jobs
  • βœ… Flexible: Daily, weekly, monthly, or custom schedules
  • βœ… Prerequisites Check: Validates Docker access and permissions
  • βœ… Environment Testing: Tests cron environment compatibility

cron/check.sh - Universal Cron Check Script

  • βœ… OS-Aware: Automatically detects macOS vs Ubuntu/Linux
  • βœ… Comprehensive: Quick status and detailed analysis modes
  • βœ… Validation: Checks cron format, script paths, permissions
  • βœ… Monitoring: Shows last execution time and cron service status
  • βœ… Troubleshooting: Identifies common issues and provides solutions

cron/test-env.sh - Cron Environment Test Script

  • βœ… OS-Aware: Automatically detects macOS vs Ubuntu/Linux
  • βœ… Comprehensive Testing: Validates Docker access, permissions, and environment
  • βœ… Detailed Logging: Creates timestamped logs for troubleshooting
  • βœ… Cron Simulation: Tests minimal cron environment compatibility
  • βœ… System Validation: Checks disk space, memory, and system requirements

generate-secrets.sh - Cross-Platform Security & Setup Script

  • βœ… Cross-Platform: Works on macOS, Ubuntu/Debian, and CentOS/RHEL
  • βœ… Idempotent: Safe to run multiple times without side effects
  • βœ… Dependency Checking: Validates required tools and provides install instructions
  • βœ… Secure Generation: Creates strong encryption keys and passwords
  • βœ… Domain Configuration: Interactive domain setup with automatic TLS configuration
  • βœ… Caddy Integration: Configures Caddy reverse proxy with appropriate TLS settings
  • βœ… Backup Protection: Creates timestamped backups before regeneration
  • βœ… Platform-Specific: Provides OS-specific installation instructions

πŸ–₯️ OS Support

macOS (Docker Desktop)

  • βœ… Automatic Docker Desktop detection
  • βœ… User socket permissions (/Users/username/.docker/run/docker.sock)
  • βœ… No special group requirements
  • βœ… Homebrew PATH support
  • βœ… Cross-platform script support

Ubuntu/Linux (Docker Engine)

  • βœ… System Docker daemon support
  • βœ… Docker group membership checks
  • βœ… System socket permissions (/var/run/docker.sock)
  • βœ… Systemctl daemon status checks
  • βœ… Environment variables for headless operation
  • βœ… Cross-platform script support

Universal Script Features

  • βœ… OS-Aware: All scripts automatically detect macOS vs Ubuntu/Linux
  • βœ… No Platform-Specific Scripts: Single scripts work on both platforms
  • βœ… Automatic Configuration: Platform-specific settings applied automatically
  • βœ… Dependency Checking: Validates required tools with platform-specific instructions
  • βœ… Fallback Support: Works even without optional dependencies

🎯 Platform Overview

This homelab setup provides a complete n8n automation platform with:

  • n8n: Workflow automation platform with web UI
  • Caddy: Modern reverse proxy with automatic HTTPS
  • PostgreSQL: Reliable database backend
  • Cross-Platform: Works on macOS and Ubuntu/Linux
  • Security: Built-in authentication and TLS encryption
  • Automation: Automated refresh and monitoring scripts

Access Points

  • n8n Web UI: https://your-domain.com (or https://n8n.localhost for localhost)
  • Direct Access: http://localhost:5678 (bypasses reverse proxy)

πŸ”§ Features

Refresh Script Features

  • πŸ›‘ Graceful Shutdown: 30-second timeout for clean container stops
  • πŸ“₯ Image Updates: Pulls latest versions of all images
  • πŸš€ Service Restart: Starts services in detached mode
  • πŸ” Health Verification: Waits for services to become healthy
  • πŸ“Š Status Reporting: Shows container status and system resources
  • 🧹 Log Rotation: Automatically cleans up old log files
  • πŸ”’ Process Locking: Prevents multiple instances running

Cron Setup Features

  • πŸ“… Multiple Schedules: Daily, weekly, monthly, custom
  • πŸ”„ Idempotent: Removes old jobs before adding new ones
  • πŸ§ͺ Environment Testing: Validates cron environment
  • πŸ“‹ Status Checking: Shows current cron configuration
  • πŸ›‘οΈ Prerequisites: Validates Docker access and permissions

πŸ“‹ Usage Examples

Basic Usage

# Initial setup (first time only)
./scripts/generate-secrets.sh

# Start the platform
docker compose up -d

# Refresh services now
./scripts/refresh.sh

# Set up daily refresh at 2 AM
./scripts/cron/install.sh daily

# Check if cron job is installed
./scripts/cron/check.sh

# Check what's scheduled
./scripts/cron/install.sh status

Advanced Usage

# Custom schedule (every 6 hours)
./scripts/cron/install.sh custom "0 */6 * * *"

# Weekly on Monday at 3 AM
./scripts/cron/install.sh weekly 1

# Monthly on 15th at 4 AM
./scripts/cron/install.sh monthly 15

# Test cron environment
./scripts/cron/install.sh test

# Remove cron job
./scripts/cron/install.sh remove

# Detailed cron job analysis
./scripts/cron/check.sh detailed

Monitoring

# Watch logs in real-time
tail -f logs/refresh-$(date +%Y%m%d).log

# Check service status
docker compose ps

# Check service logs
docker compose logs -f

🚨 Troubleshooting

Permission Issues

# Ubuntu: Add user to docker group
sudo usermod -aG docker $USER
newgrp docker

# Test Docker access
docker ps

Cron Issues

# Test cron environment
./scripts/cron/install.sh test

# Check cron logs
sudo journalctl -u cron  # Ubuntu
log show --predicate 'process == "cron"' --last 1h  # macOS

Service Issues

# Check service status
docker compose ps

# View service logs
docker compose logs -f

# Restart specific service
docker compose restart service-name

# Check Caddy configuration
docker compose logs caddy

# Test n8n health endpoint
curl -k https://n8n.localhost/healthz

Common Issues

TLS Certificate Issues

# For localhost development, ensure CADDY_TLS=internal in .env
# For production domains, ensure CADDY_TLS is empty in .env
grep CADDY_TLS .env

# Regenerate credentials if needed
./scripts/generate-secrets.sh --force

n8n Access Issues

# Check if n8n is running
docker compose ps n8n

# Check n8n logs
docker compose logs n8n

# Test direct access (bypasses reverse proxy)
curl http://localhost:5678/healthz

Database Connection Issues

# Check PostgreSQL status
docker compose ps postgres

# Check database logs
docker compose logs postgres

# Test database connection
docker compose exec postgres pg_isready -U n8n_user -d n8n

πŸ“Š Logs

Logs are automatically created in the logs/ directory:

  • refresh-YYYYMMDD.log - Daily refresh logs
  • cron-test-YYYYMMDD-HHMMSS.log - Environment test logs

Log files are automatically rotated after 7 days.

πŸ”’ Security

Platform Security

  • βœ… n8n Basic Auth: Username/password authentication enabled by default
  • βœ… TLS Encryption: Automatic HTTPS with Let's Encrypt (production) or internal certificates (localhost)
  • βœ… Secure Cookies: Session management with secure cookie settings
  • βœ… Database Security: SCRAM-SHA-256 authentication for PostgreSQL
  • βœ… Container Security: Non-root users and no-new-privileges security options

Script Security

  • βœ… Process locking prevents concurrent runs
  • βœ… Graceful shutdown with timeout
  • βœ… Health verification before completion
  • βœ… Resource monitoring and warnings
  • βœ… Comprehensive error handling
  • βœ… Secure credential generation with strong passwords

🀝 Contributing

  1. Test on both macOS and Ubuntu
  2. Ensure scripts are idempotent
  3. Add appropriate error handling
  4. Update documentation
  5. Test cron environment compatibility

πŸ“„ License

This project is part of your homelab setup. Use and modify as needed.

About

A self hosted, n8n for localhost

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages