n8n CI/CD Reusable Workflow
This reusable workflow provides CI/CD capabilities for n8n deployments to DigitalOcean. It leverages our Dagger modules to provide a consistent and reliable deployment process.
Features
- 🔄 Automated CI/CD pipeline for n8n
- 🌊 DigitalOcean App Platform deployment
- 🔐 Secure secrets management
- ⚙️ Configurable environment variables
- 🎯 Region-specific deployment
- 🏷️ Custom app naming
Prerequisites
- GitHub repository with n8n configuration
- DigitalOcean account and API token
- GitHub Actions enabled in your repository
Usage
Basic Example
Create .github/workflows/n8n-deploy.yml
in your repository:
name: Deploy n8n
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
deploy-n8n:
uses: felipepimentel/daggerverse/.github/workflows/reusable-n8n-ci-cd.yml@main
secrets:
digitalocean_token: $
Advanced Example
name: Deploy n8n with Custom Configuration
on:
push:
branches: [main, staging]
paths:
- 'n8n/**'
- '.github/workflows/**'
pull_request:
branches: [main, staging]
paths:
- 'n8n/**'
- '.github/workflows/**'
jobs:
deploy-n8n:
uses: felipepimentel/daggerverse/.github/workflows/reusable-n8n-ci-cd.yml@main
with:
dagger_version: "0.15.3"
region: "fra1"
app_name: "n8n-production"
env_vars: |
{
"N8N_BASIC_AUTH_ACTIVE": "true",
"N8N_BASIC_AUTH_USER": "admin",
"N8N_PROTOCOL": "https",
"N8N_HOST": "workflow.example.com",
"N8N_PORT": "5678",
"N8N_ENCRYPTION_KEY": "$",
"WEBHOOK_TUNNEL_URL": "https://workflow.example.com/"
}
secrets:
digitalocean_token: $
Inputs
Name | Description | Required | Default | Example Values |
---|---|---|---|---|
dagger_version | Version of Dagger to use | No | 0.15.3 | 0.15.3 , 0.15.0 |
region | DigitalOcean region for deployment | No | nyc | nyc , fra1 , sgp1 |
app_name | Name of the n8n application | No | n8n | n8n-prod , n8n-staging |
env_vars | JSON string of environment variables | No | Basic auth config | See environment variables section |
Secrets
Name | Description | Required | How to Obtain |
---|---|---|---|
digitalocean_token | DigitalOcean API token | Yes | Create in DigitalOcean |
Environment Variables
Required Variables
{
"N8N_BASIC_AUTH_ACTIVE": "true",
"N8N_BASIC_AUTH_USER": "admin"
}
Recommended Variables
{
"N8N_PROTOCOL": "https",
"N8N_HOST": "your-domain.com",
"N8N_PORT": "5678",
"N8N_ENCRYPTION_KEY": "your-secure-key",
"WEBHOOK_TUNNEL_URL": "https://your-domain.com/",
"N8N_EMAIL_MODE": "smtp",
"N8N_SMTP_HOST": "smtp.example.com",
"N8N_SMTP_PORT": "587",
"N8N_SMTP_USER": "your-smtp-user",
"N8N_SMTP_PASS": "your-smtp-password"
}
Workflow Details
CI Process
The CI job performs the following steps:
- Code checkout
- Dagger setup with specified version
- Runs tests and validations
- Checks n8n configuration
- Validates environment variables
CD Process
The CD job (runs only on main branch) performs:
- Code checkout
- Dagger setup
- DigitalOcean authentication
- App deployment configuration
- Environment variables setup
- Application deployment
- Health check verification
Best Practices
- Environment Variables
- Store sensitive data in GitHub Secrets
- Use descriptive names for variables
- Document all custom variables
- Security
- Rotate DigitalOcean tokens regularly
- Use HTTPS for production deployments
- Enable basic authentication
- Set strong encryption keys
- Deployment
- Use different app names for staging/production
- Set appropriate resource limits
- Configure automatic backups
- Monitor deployment logs
Troubleshooting
Common Issues
- Authentication Failures
Error: Unable to authenticate with DigitalOcean
- Verify token permissions
- Check token expiration
- Ensure token is properly set in secrets
- Environment Variables
Error: Invalid environment variables format
- Validate JSON syntax
- Check for missing quotes
- Ensure all values are strings
- Region Issues
Error: Invalid region specified
- Use valid DigitalOcean region codes
- Check region availability
- Verify resource availability in region
Debug Steps
- Check workflow run logs
- Verify environment variables
- Validate DigitalOcean configuration
- Test n8n configuration locally
- Review deployment status in DigitalOcean dashboard
Related Resources
Support
For issues and feature requests:
- Open an issue in the repository
- Provide workflow run logs
- Include error messages
- Describe expected vs actual behavior