CoolFace
Apppublic

hbstarjason/n8n

sourceHugging Facemitupdated 9mo agoView on Hugging Face
0likes
App README

N8n Free

This repository provides a template for deploying a free, self-updating instance of n8n on Hugging Face Spaces, using Supabase as the database backend.

The setup includes automated GitHub Actions to:

  • —Keep the Hugging Face Space and Supabase project alive.
  • —Check for new n8n versions daily and automatically update the deployment.

Deployment Guide

Follow these steps to deploy your own free n8n instance.

1. Fork the Repository

Start by forking this repository to your own GitHub account.

2. Create a Supabase Project

  1. 1.Go to Supabase and create a new project.
  2. 2.Once the project is created, navigate to the SQL Editor.
  3. 3.Run the following SQL query to create a keep-alive table. This is used by the keep-alive workflow to ensure your Supabase instance doesn't get paused due to inactivity.
sql
    CREATE TABLE "keep-alive" (
      id BIGINT generated BY DEFAULT AS IDENTITY,
      name text NULL,
      created_at timestamptz DEFAULT now(),
      CONSTRAINT "keep-alive_pkey" PRIMARY KEY (id)
    );
    INSERT INTO "keep-alive"(name) VALUES ('ping');
  1. 1.Navigate to Project Settings > API and find your Project URL and annon public legacy API key. You will need these in the next step.
  1. 1.To ensure a secure connection to your database, you should configure SSL. In your Supabase project, go to Project Settings > Database. Scroll down to SSL Configuration and enable it.

3. Create a Hugging Face Space

  1. 1.Go to Hugging Face Spaces and create a new Space.
  2. 2.Select Docker as the Space SDK and choose a free hardware option.
  3. 3.Choose the forked repository from your GitHub account to deploy from.
  4. 4.After the Space is created, go to the Settings tab and add the following secrets and variables:
SecretDescription
DB_POSTGRESDB_PASSWORDThe supabase database password.
DB_POSTGRESDB_USERThe supabase database user.
N8N_ENCRYPTION_KEYAn n8n encryption key.
DB_POSTGRESDB_SSL_CAThe supabase database SSL cert.
DB_POSTGRESDB_HOSTThe supabase database host.
DB_POSTGRESDB_PORTThe supabase database port.
DB_POSTGRESDB_DATABASESet to postgres.
VariableDescription
GENERIC_TIMEZONEThe n8n generic timezone
TZThe n8n timezone
DB_TYPESet to postgres
DB_POSTGRESDB_SCHEMASet to public
N8N_PORTSet to 7860
N8N_PROTOCOLSet to https
N8N_EDITOR_BASE_URLSet to https://<username>-<space>.hf.space
WEBHOOK_URLSet to https://<username>-<space>.hf.space
N8N_HOSTSet to <username>-<space>.hf.space
N8N_ENFORCE_SETTINGS_FILE_PERMISSIONSSet to true
N8N_PUSH_BACKENDSet to websocket
EXECUTIONS_DATA_SAVE_ON_PROGRESSSet to false
N8N_DATABASE_SSL_REJECT_UNAUTHORIZEDSet to true
N8N_PROXY_HOPSSet to 1
EXECUTIONS_DATA_SAVE_ON_ERRORSet to all
EXECUTIONS_DATA_SAVE_ON_SUCCESSSet to none
EXECUTIONS_DATA_SAVE_MANUAL_EXECUTIONSSet to false
EXECUTIONS_DATA_PRUNESet to true
EXECUTIONS_DATA_MAX_AGESet to 168

4. Configure GitHub Repository Secrets

To allow the GitHub Actions to update your Hugging Face Space, you need to add your Hugging Face API token to your forked repository's secrets.

  1. 1.Create a Hugging Face token with write permissions at huggingface.co/settings/tokens.
  2. 2.In your forked GitHub repository, go to Settings > Secrets and variables > Actions.
  3. 3.Create a new secret named HF_TOKEN and paste your Hugging Face token.

5. Health Checks

You can configure a crontab to run the healthcheck-rebuild.sh to perform a health check of the n8n instance. It will try to make a commit to make it rebuild the n8n instance. You shoule pass the environment variables HF_REPO, N8N_HOST, TG_TOKEN(optional) to the script.

How It Works

This project uses GitHub Actions to automate maintenance and updates.

You can import the workflow Auto keep n8n alive and updates on n8n-free repo into n8n to make it keep alive and update itself.

Automatic n8n Updates

The .github/workflows/update-n8n.yml can triggered manually. After the n8n deploy, you can create a workeflow to trigger the github workeflow automatically.

  1. 1.Checks for new n8n versions: It fetches the latest version tag from the official n8n GitHub repository.
  2. 2.Compares versions: It compares the latest version with the version currently specified in the Dockerfile.
  3. 3.Updates and Pushes: If a new version is found, the workflow:
  4. 4.Updates the Dockerfile with the new version tag.
  5. 5.Commits the change to your repository.
  6. 6.Pushes the updated Dockerfile to your Hugging Face Space, triggering a rebuild and updating your n8n instance.

You can also trigger this workflow manually from the Actions tab in your GitHub repository.

Keep-Alive Services

To prevent the free tiers of Hugging Face Spaces and Supabase from being paused due to inactivity.

  • —Hugging Face Keep-Alive (`huggingface-keep-alive.yml`): This workflow sends a simple curl request to your Hugging Face Space URL to simulate traffic.
  • —Supabase Keep-Alive (`supabase-keep-alive.yml`): This workflow sends a curl request to the keep-alive table in your Supabase database, ensuring the database remains active.

Configuring Keep-Alive Actions

To make the keep-alive workflows functional, you need to:

  1. 1.Update the Hugging Face Keep-Alive URL:
  2. 2.Create a new variable named HF_SPACE_URL and paste your actual Hugging Face Space URL.
  1. 1.Add Supabase Secrets to GitHub:
  2. 2.In your forked GitHub repository, go to Settings > Secrets and variables > Actions.
  3. 3.Create a new secret named SUPABASE_URL and paste your Supabase Project URL.
  4. 4.Create another new secret named SUPABASE_KEY and paste your Supabase anon public API key.