Skip to content

Latest commit

Β 

History

History
380 lines (256 loc) Β· 12.6 KB

File metadata and controls

380 lines (256 loc) Β· 12.6 KB

n8n Auto-Deploy to Fly.io

Automated deployment system that monitors Docker Hub for new stable n8n releases and automatically deploys them to Fly.io using GitHub Actions.

Overview

This repository contains a GitHub Actions workflow that:

  • Checks Docker Hub daily for new stable n8n versions
  • Compares the latest version with your currently deployed version
  • Automatically deploys updates when a new stable version is available
  • Preserves your existing configuration and data during updates

Setup

Prerequisites

  • A Fly.io account with an existing n8n application deployed
  • A GitHub repository with this workflow
  • Fly.io CLI access token

Configuration Steps

πŸ”‘ Step 1: Get Your Fly.io API Token

The workflow needs a Fly.io API token to authenticate and deploy updates.

Option A: Create a Deploy Token (Recommended)

# Install flyctl if you haven't already
# See: https://fly.io/docs/hands-on/install-flyctl/

# Authenticate with Fly.io
flyctl auth login

# Create a new deploy token (more secure, limited permissions)
flyctl tokens create deploy

Option B: Use Your Personal Token

# Get your personal access token
flyctl auth token

πŸ’‘ Tip: The deploy token is more secure as it has limited permissions.

After running the command, you'll see output like:

FlyV1 fm2_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

πŸ“‹ Copy this token - you'll need it in the next step!


πŸ” Step 2: Add Token to GitHub Secrets

Now let's securely store the token in your GitHub repository:

  1. Navigate to your repository on GitHub

    • Go to https://github.com/YOUR_USERNAME/YOUR_REPO
  2. Open Settings

    • Click the βš™οΈ Settings tab at the top of your repository
  3. Go to Secrets

    • In the left sidebar, click Secrets and variables β†’ Actions
  4. Create New Secret

    • Click the green New repository secret button
  5. Configure the Secret

    Name:  FLY_API_TOKEN
    Value: [Paste your token from Step 1]
    

    ⚠️ Important: The name must be exactly FLY_API_TOKEN (case-sensitive)

  6. Save

    • Click Add secret

βœ… Done! Your token is now securely stored and will be masked in all logs.


βœ… Step 3: Verify fly.toml Configuration

Make sure your fly.toml file has your app name configured:

app = 'n8n-run'  # ← Your Fly.io app name
primary_region = 'ams'

[build]
  image = 'n8nio/n8n'
# ... rest of your config

The workflow will automatically read your app name from this file.

πŸ’‘ Find your app name: Run flyctl apps list to see all your Fly.io apps


πŸŽ‰ Step 4: You're All Set!

The workflow is now configured and will run automatically. No additional setup needed!

What happens next:

  • ⏰ The workflow runs daily at 2:00 AM UTC to check for updates
  • πŸ” It compares the latest n8n version with your deployed version
  • πŸš€ If a new stable version is found, it automatically deploys
  • πŸ“Š You can view all activity in the Actions tab

Want to test it now? See the Manual Trigger section below.

Workflow Triggers

Automatic (Scheduled)

The workflow runs automatically daily at 2:00 AM UTC to check for new versions.

To modify the schedule, edit .github/workflows/deploy-n8n.yml:

on:
  schedule:
    - cron: "0 2 * * *" # Change this to your preferred schedule

Cron syntax examples:

  • 0 2 * * * - Daily at 2:00 AM UTC
  • 0 */6 * * * - Every 6 hours
  • 0 0 * * 0 - Weekly on Sunday at midnight

Manual

You can manually trigger the workflow at any time:

  1. 🏠 Go to your GitHub repository

    • Navigate to https://github.com/YOUR_USERNAME/YOUR_REPO
  2. 🎬 Open the Actions tab

    • Click the Actions tab at the top
  3. πŸ“‹ Select the workflow

    • In the left sidebar, click Deploy n8n to Fly.io
  4. ▢️ Run the workflow

    • Click the Run workflow dropdown button (top right)
    • Select the branch (usually main)
    • Click the green Run workflow button
  5. πŸ‘€ Watch it run

    • The workflow will appear in the list below
    • Click on it to see real-time logs

⚑ Quick tip: This is useful for testing your setup or forcing an immediate update check!

How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ• Scheduled Trigger (Daily at 2 AM UTC)                   β”‚
β”‚     or Manual Trigger                                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ” Step 1: Check Docker Hub                                β”‚
β”‚  β€’ Query Docker Hub API for n8n tags                        β”‚
β”‚  β€’ Filter out pre-releases (beta, alpha, rc)                β”‚
β”‚  β€’ Find latest stable version (e.g., 1.23.4)                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ“Š Step 2: Compare Versions                                β”‚
β”‚  β€’ Get current version from Fly.io                          β”‚
β”‚  β€’ Compare using semantic versioning                        β”‚
β”‚  β€’ Decide: Update needed?                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                       β”‚
         β–Ό                       β–Ό
    βœ… Up to date          πŸ†• New version
         β”‚                       β”‚
         β–Ό                       β–Ό
    Skip deploy           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚                β”‚  πŸš€ Step 3: Deploy              β”‚
         β”‚                β”‚  β€’ Deploy new Docker image      β”‚
         β”‚                β”‚  β€’ Preserve fly.toml config     β”‚
         β”‚                β”‚  β€’ Keep data volume intact      β”‚
         β”‚                β”‚  β€’ Run health checks            β”‚
         β”‚                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                           β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
                     β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸ“ Step 4: Report Results                                  β”‚
β”‚  β€’ Log version information                                  β”‚
β”‚  β€’ Create workflow summary                                  β”‚
β”‚  β€’ Show success/failure status                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Detailed Steps

  1. πŸ” Version Detection: Queries Docker Hub API for the latest stable n8n version

    • Filters out pre-release versions (beta, alpha, rc)
    • Uses semantic versioning to identify the latest stable release
  2. πŸ“Š Version Comparison: Checks your currently deployed version on Fly.io

    • Compares using semantic versioning rules
    • Determines if an update is needed
  3. πŸš€ Deployment: If a new version is available

    • Deploys the new Docker image to Fly.io
    • Preserves your existing fly.toml configuration
    • Maintains your data volume (no data loss)
    • Verifies deployment health after completion
  4. πŸ“ Reporting: Logs all actions and creates a workflow summary

    • βœ… Success: Reports the deployed version
    • ⏭️ No update: Confirms you're already up to date
    • ❌ Failure: Provides detailed error information

πŸ“Š Monitoring

View Workflow Runs

  1. 🏠 Go to your GitHub repository
  2. 🎬 Navigate to Actions tab
  3. πŸ“‹ Click on "Deploy n8n to Fly.io" workflow
  4. πŸ‘€ View individual workflow runs and their logs

Workflow Summary

Each workflow run provides a summary showing:

Status Icon Description
βœ… Success πŸš€ New version deployed successfully
⏭️ Skipped βœ“ Already running latest version
❌ Failed ⚠️ Deployment encountered an error

Example Summary:

πŸ“¦ Current Version: 1.22.5
πŸ†• Latest Version:  1.23.4
πŸš€ Action: Deployed new version
βœ… Status: Success

Troubleshooting

Workflow Fails with "FLY_API_TOKEN secret is not configured"

Problem: The Fly.io API token is missing or not properly configured.

Solution:

  1. Verify the secret is named exactly FLY_API_TOKEN (case-sensitive)
  2. Ensure the token has deployment permissions
  3. Try regenerating the token: flyctl tokens create deploy
  4. Re-add the token to GitHub Secrets

Workflow Fails with "Authentication failed"

Problem: The API token is invalid or has expired.

Solution:

  1. Generate a new token: flyctl tokens create deploy
  2. Update the FLY_API_TOKEN secret in GitHub with the new token
  3. Re-run the workflow

Workflow Fails with "Could not determine latest stable version"

Problem: Unable to query Docker Hub or parse version information.

Solution:

  1. Check if Docker Hub is accessible: https://hub.docker.com/r/n8nio/n8n/tags
  2. Review the workflow logs for specific error messages
  3. The workflow will automatically retry on the next scheduled run

Deployment Succeeds but Health Check Fails

Problem: The deployment completed but the application is not responding correctly.

Solution:

  1. Check your Fly.io dashboard: https://fly.io/dashboard
  2. View application logs: flyctl logs
  3. Check application status: flyctl status
  4. Fly.io's automatic rollback should restore the previous version
  5. Review your fly.toml configuration for any issues

No Deployment Triggered When Expected

Problem: A new version is available but the workflow didn't deploy it.

Solution:

  1. Check the workflow logs to see the version comparison
  2. Verify the new version is a stable release (not beta/alpha/rc)
  3. Manually trigger the workflow to force a check
  4. Review the version detection logic in the logs

Workflow Doesn't Run on Schedule

Problem: The scheduled workflow is not executing.

Solution:

  1. Ensure the workflow file is in the default branch (usually main or master)
  2. Check that the repository is not archived or disabled
  3. Verify the cron syntax is correct
  4. Note: GitHub Actions may delay scheduled workflows during high load periods

Configuration Preservation

The workflow is designed to preserve your existing configuration:

  • fly.toml: All settings remain unchanged
  • Data Volume: Your n8n workflows and data are preserved
  • Environment Variables: All environment variables are maintained
  • Only the Docker image version is updated

Security

  • API tokens are stored securely in GitHub Secrets
  • Tokens are automatically masked in workflow logs
  • The workflow uses minimal required permissions
  • Concurrency control prevents simultaneous deployments

Manual Deployment

If you need to deploy a specific version manually:

# Deploy a specific version
flyctl deploy --image n8nio/n8n:1.23.4

# Or deploy the latest version
flyctl deploy --image n8nio/n8n:latest

Support

License

This workflow configuration is provided as-is for use with your n8n deployment.