Skip to content

Conversation

@KevyVo
Copy link
Contributor

@KevyVo KevyVo commented Sep 23, 2025

By popular demand, n8n is added to the list of samples. Since we do not support volumes right now, all the volumes in the compose.dev.yaml will be used for only local development.

Here are some resources I used while developing this:

Samples Checklist

✅ All good!

@KevyVo KevyVo self-assigned this Sep 23, 2025
@KevyVo KevyVo had a problem deploying to deploy-changed-samples September 23, 2025 05:19 — with GitHub Actions Failure
@KevyVo KevyVo marked this pull request as draft September 23, 2025 05:20
file: compose.dev.yaml
service: postgres

n8n:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KevyVo you referenced the external storage docs in the PR description, but I don't see it used here.

I'd recommend adding those env vars in here and then documenting any additional steps. Tigris Data is a free option we can point people to that offers s3-compatible storage.


[![1-click-deploy](https://raw.githubusercontent.com/DefangLabs/defang-assets/main/Logos/Buttons/SVG/deploy-with-defang.svg)](ASK RAPH)

This sample shows how to get a [n8n](https://n8n.io/) app up using PostgreSQL as a database and running with Defang. The original sample can be found [here](https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgres). The official n8n guide for setting up with PostgreSQL [here](https://docs.n8n.io/hosting/installation/server-setups/docker-compose/) does not work with Defang. To use the version compatible with Defang, please refer to this sample instead.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we say it's not compatible with Defang, I think we should highlight why/what isn't compatible.


## Development

**IMPORTANT:** But before you do that change the default users and passwords in the [`.env`](.env) file!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One awkward thing is that any .env file we put here will be loaded when we run defang compose up because the docker SDK will pick it up. Config vals should override them but I believe they won't be marked as missing if the .env file exists. I'd recommend hard-coding in the development compose file for that reason.

@lionello
Copy link
Member

I personally prefer if compose.yaml is for local/dev and compose.prod.yaml extends that one.

@raphaeltm
Copy link
Collaborator

I personally prefer if compose.yaml is for local/dev and compose.prod.yaml extends that one.

We had so many conversations about this and I used to push that idea, but we collectively agreed a long time ago that that was exactly what we wanted to avoid because it means passing an extra -f flag to get things deployed properly with Defang. That's why we structured every other sample with compose.yaml to cloud, and compose.dev.yaml for local dev.

@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples September 25, 2025 08:48 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples September 30, 2025 00:54 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples September 30, 2025 09:36 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples October 4, 2025 11:05 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples October 6, 2025 08:18 — with GitHub Actions Failure
@KevyVo KevyVo marked this pull request as ready for review October 6, 2025 08:25
@raphaeltm
Copy link
Collaborator

raphaeltm commented Oct 6, 2025 via email

@KevyVo KevyVo had a problem deploying to deploy-changed-samples October 6, 2025 08:28 — with GitHub Actions Failure
@KevyVo
Copy link
Contributor Author

KevyVo commented Oct 6, 2025

Hey Kevin, Thanks for the mention. For the env vars in deploy.yaml, you can put them in the env section of the n8n service. For 1-click deploy, I'll help set that up once the PR is merged. Best, Raphaël Raphaël Titsworth-Morin (he/him) Co-Founder | Éphémère Creative Ltd ephemerecreative.ca Let's build something good together.

On Mon, Oct 6, 2025 at 10:25 AM @.*** wrote: By popular require, n8n https://n8n.io/ is added to the list of samples. Since we do not support volumes right now, all the volumes in the compose.dev.yaml will be used for only local development. Only two small items I help from @raphaeltm https://github.com/raphaeltm is to setup 1click deploy and set the env var in the deploy.yaml. I am unsure which environment to put it in. Here are some resources I used while developing this: - https://github.com/n8n-io/n8n-hosting/tree/main/docker-compose/withPostgres - https://docs.n8n.io/hosting/configuration/environment-variables/ - https://docs.n8n.io/hosting/installation/server-setups/docker-compose/ - https://community.n8n.io/t/error-while-deploying-n8n-docker/77926 - https://community.n8n.io/t/how-to-change-localhost-5678-from-webhook-url/27033/8 Samples Checklist ✅ All good! ------------------------------ You can view, comment on, or merge this pull request online at: #474 Commit Summary - 0f0ce0c <0f0ce0c> Added n8n to samples - 1695094 <1695094> Working n8n with Oauth - 2d4a465 <2d4a465> update reason for volumes - b75f139 <b75f139> Managed Postgres - ffe0977 <ffe0977> n8n Public DNS - eb14aa0 <eb14aa0> fix gcp setup deployment File Changes (6 files https://github.com/DefangLabs/samples/pull/474/files) - A samples/n8n/.github/workflows/deploy.yaml https://github.com/DefangLabs/samples/pull/474/files#diff-3c5ddcabafecc6bf328a15063126c1c85f63143c97c67023d5fd425c83c27ea3 (28) - A samples/n8n/README.md https://github.com/DefangLabs/samples/pull/474/files#diff-9468dc59215e010047102e5611169576d935d96c5c64d9d0dddaf9d8b3f09a33 (94) - A samples/n8n/compose.dev.yaml https://github.com/DefangLabs/samples/pull/474/files#diff-b26b523e92e4d6b3f3c579cfd78fc2e974bbb63738241dc8be6a466c96f37bff (40) - A samples/n8n/compose.yaml https://github.com/DefangLabs/samples/pull/474/files#diff-c9e4bfd0cd96adb39bea69969645d51d6df017e1e9ccf4bf568eb42e3a2e40cd (64) - A samples/n8n/init-data.sh https://github.com/DefangLabs/samples/pull/474/files#diff-85c9cc6fa36ed5d05515650d7654d8bcb8554442fff1a29809245b4b77e1efea (47) - A samples/n8n/setup.Dockerfile https://github.com/DefangLabs/samples/pull/474/files#diff-80d0039114745e4d309f54ac715b7432358cfc71db63417028df03db274b15a0 (5) Patch Links: - https://github.com/DefangLabs/samples/pull/474.patch - https://github.com/DefangLabs/samples/pull/474.diff — Reply to this email directly, view it on GitHub <#474>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG6MLZYLEDFUOSEPKJRW2D3WIRQFAVCNFSM6AAAAACHHLUEC6VHI2DSMVQWIX3LMV43ASLTON2WKOZTGQ2DGNZSGE4TCMQ . You are receiving this because you were mentioned.Message ID: @.***>

Are saying to hardcode the value to the compose.yaml to the n8n section env var like this:

n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=defang_user
      - DB_POSTGRESDB_PASSWORD=defang12345
      - N8N_HOST=n8n
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://n8n
      - DB_POSTGRESDB_SSL_ENABLED=true
      - DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED=false
    ports:
      - 5678:5678
    links:
      - postgres
    depends_on:
      setup:
        condition: service_completed_successfully
      postgres:
        condition: service_healthy

@raphaeltm
Copy link
Collaborator

raphaeltm commented Oct 6, 2025 via email

@KevyVo
Copy link
Contributor Author

KevyVo commented Oct 6, 2025

Here are some issues I ran into over the last couple of days, along with how I resolved them:

  1. Slow startup for managed Postgres
    The managed Postgres instance takes a while to come online. I think it would be a better experience if we extend the retry period to up to 10 minutes and include a message in the script letting users know that the first initialization can take some time and to be patient. It’s much better than having the process fail and requiring another up. In my experience deploying this about 30 times over the past week, I’ve never had to wait more than 5 minutes on AWS or GCP.

  2. GCP setup container environment variables
    The GCP setup container kept failing because environment variables in the setup service aren’t populated unless we use the JavaScript-style ${} syntax. I had to inspect each Cloud Run service’s container environment to figure this out. I’m not sure if this is a bug or expected behavior — on AWS, we don’t need ${}, and the variables fill in fine. This only seems to affect GCP.

  3. Init script re-deployment handling
    I updated the init script to handle cases after the initial deployment. Once Postgres has been set up and the users are created, rerunning the script causes Postgres to error out since the users already exist. I added logic to handle that gracefully.

  4. Public DNS can be automatically refer with the compose now: added public fqdn url to compose defang#1496

@KevyVo
Copy link
Contributor Author

KevyVo commented Oct 6, 2025

Remaining issues:

  1. AWS redeploy issue
    The initial deployment on AWS works perfectly with no problems. However, when running defang up a second time to redeploy, the n8n app crashes after deployment. A full defang down followed by defang up is required for it to deploy successfully again. I’ve checked the logs but haven’t yet determined the cause.

  2. GCP delayed startup
    On GCP, the deployment completes successfully without any errors. However, once it’s finished, the deployed URL doesn’t load immediately. Interestingly, the app keeps trying to restart itself, and after about 30 minutes, it finally comes online and remains stable. I currently have a GCP n8n instance that’s been running for two days without issues. I’m still not sure why there’s such a long delay initially.

I think I need help resolving the last two, I gave it my all. I am quite stump now.

@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples October 6, 2025 18:00 — with GitHub Actions Failure
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples October 6, 2025 18:06 — with GitHub Actions Failure
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples October 6, 2025 18:41 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples October 6, 2025 21:48 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples October 6, 2025 23:16 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples October 6, 2025 23:21 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples October 6, 2025 23:47 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples October 7, 2025 00:10 — with GitHub Actions Failure
@KevyVo KevyVo had a problem deploying to deploy-changed-samples October 7, 2025 00:16 — with GitHub Actions Error
@KevyVo KevyVo temporarily deployed to deploy-changed-samples October 7, 2025 00:19 — with GitHub Actions Inactive
@raphaeltm raphaeltm temporarily deployed to deploy-changed-samples October 7, 2025 09:32 — with GitHub Actions Inactive
Comment on lines +110 to +111
TEST_DB_POSTGRESDB_SSL_ENABLED: ${{ secrets.TEST_DB_POSTGRESDB_SSL_ENABLED }}
TEST_DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED: ${{ secrets.TEST_DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these config? @KevyVo @raphaeltm

@lionello lionello merged commit 4725410 into main Oct 7, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants