I’m setting up n8n with a JPS manifest in Jelastic. I can’t get the DB_POSTGRESDB_HOST environment variable to work right. I need to put the Postgres node’s IP in there using ${nodes.sqldb[0].address}. It only works when I add the variable manually through the GUI after setup. I’ve tried different ways to set it in the JPS file:
DB_POSTGRESDB_HOST: ${nodes.sqldb[0].address}
DB_POSTGRESDB_HOST: ${nodes.sqldb.first.address}
DB_POSTGRESDB_HOST: ${nodes.sqldb.master.address}
But none of these work. I think the problem is that when the JPS tries to set the variable, the Postgres node isn’t created yet, so there’s no IP to use. How can I set this IP after the database is ready? Any ideas on how to fix this? Thanks for any help!
I’ve encountered similar issues when deploying applications with dynamic database configurations. One approach that worked for me was using a post-deploy script or hook in the JPS manifest. This script can run after all nodes are created and configured.
You could try adding a section like this to your JPS:
onAfterScaleOut[sqldb]:
- setGlobals:
DB_HOST: ${nodes.sqldb.first.address}
- cmd[cp]: |-
sed -i 's|DB_POSTGRESDB_HOST=.*|DB_POSTGRESDB_HOST=${globals.DB_HOST}|g' /path/to/n8n/config
user: root
This should update the n8n configuration file with the correct database IP after the SQL node is fully provisioned. Make sure to adjust the file path as needed.
If that doesn’t work, another option is to use Jelastic’s API to update the environment variable post-deployment. You’d need to create a separate script that runs after everything else and makes an API call to set the variable.
Hope this helps point you in the right direction!
Having dealt with similar deployment challenges, I’d suggest leveraging Jelastic’s native environment variables. Instead of hardcoding the database IP, use the JELASTIC_SQLDB environment variable. This variable is automatically populated with the internal address of your database node.
Modify your n8n configuration to use:
DB_POSTGRESDB_HOST=${JELASTIC_SQLDB}
This approach eliminates the need for post-deployment scripts or manual intervention. It’s more resilient to changes in your environment topology and simplifies your JPS manifest.
If you need to stick with your current setup, consider implementing a startup script for your n8n node that retrieves the database IP dynamically and updates the configuration accordingly. This would ensure the correct IP is always used, even if the database node is replaced or scaled.
hey there, i’ve run into this before too. what worked for me was using a custom script that runs after everything’s set up. you could add something like this to ur JPS:
onAfterDeploy:
- executeScript:
type: js
script: |
var dbIp = jelastic.env.control.GetNodeGroups('${env.name}').nodes.sqldb[0].address;
jelastic.env.control.SetNodeGroupEnvVars('${env.name}', 'cp', {'DB_POSTGRESDB_HOST': dbIp});
this should grab the IP and set it for ya. good luck!