|
| 1 | +# n8n |
| 2 | + |
| 3 | +[](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-n8n-template%26template_owner%3DDefangSamples) |
| 4 | + |
| 5 | +This sample shows how to get a [n8n](https://n8n.io/) app up using PostgreSQL as a database and running with Defang. We based it in part on the [original sample](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgres) from the n8n team, but we have adapted it to be consistent with the way our other samples are configured. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +1. Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 10 | +2. (Optional) If you are using [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) authenticate with your cloud provider account |
| 11 | +3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/) |
| 12 | + |
| 13 | +## Development |
| 14 | + |
| 15 | +To run the application locally for development, use the development compose file: |
| 16 | + |
| 17 | +```bash |
| 18 | +docker compose -f compose.dev.yaml up |
| 19 | +``` |
| 20 | + |
| 21 | +This will: |
| 22 | + |
| 23 | +- Start PostgreSQL with volume persistence for local development |
| 24 | +- Expose PostgreSQL on port 5432 for direct access if needed |
| 25 | +- Start n8n on port 5678 with volume persistence |
| 26 | + |
| 27 | +You can access n8n at `http://localhost:5678` once the containers are running. |
| 28 | + |
| 29 | +## Configuration |
| 30 | + |
| 31 | +For this sample, you will need to provide the following [configuration](https://docs.defang.io/docs/concepts/configuration). Note that if you are using the 1-click deploy option, you can set these values as secrets in your GitHub repository and the action will automatically deploy them for you. |
| 32 | + |
| 33 | +### `POSTGRES_PASSWORD` |
| 34 | + |
| 35 | +The password for your Postgres database. You need to set this before deploying for the first time. |
| 36 | + |
| 37 | +*You can easily set this to a random string using `defang config set POSTGRES_PASSWORD --random`* |
| 38 | + |
| 39 | +### `N8N_ENCRYPTION_KEY` |
| 40 | + |
| 41 | +The encryption key for your n8n instance. This is used to encrypt sensitive data in the database. |
| 42 | + |
| 43 | +*You can easily set this to a random string using `defang config set N8N_ENCRYPTION_KEY --random`* |
| 44 | + |
| 45 | +### `DB_POSTGRESDB_SSL_ENABLED` |
| 46 | + |
| 47 | +Set to `true` to enable SSL. Set to `false` to disable SSL. |
| 48 | + |
| 49 | +### `DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED` |
| 50 | + |
| 51 | +Set to `true` to reject unauthorized certificates. Set to `false` to accept unauthorized certificates. Counterintuitive, but leave this as **true** to **disable SSL** (required for local dev and playground). |
| 52 | + |
| 53 | + |
| 54 | +## Deployment |
| 55 | + |
| 56 | +> [!NOTE] |
| 57 | +> Download [Defang CLI](https://github.com/DefangLabs/defang) |
| 58 | +
|
| 59 | +### Defang Playground |
| 60 | + |
| 61 | +Deploy your application to the Defang Playground by opening up your terminal and typing: |
| 62 | + |
| 63 | +```bash |
| 64 | +defang compose up |
| 65 | +``` |
| 66 | + |
| 67 | +### BYOC |
| 68 | + |
| 69 | +If you want to deploy to your own cloud account, you can [use Defang BYOC](https://docs.defang.io/docs/tutorials/deploy-to-your-cloud). |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +Title: n8n |
| 74 | + |
| 75 | +Short Description: A n8n app running on Defang. |
| 76 | + |
| 77 | +Tags: n8n, PostgreSQL, Docker |
| 78 | + |
| 79 | +Languages: Docker, Shell |
0 commit comments