skip to Main Content

I am trying to implement n8n with a JPS manifest, but I have the problem that Jelastic does not detect the DB_POSTGRESDB_HOST environment variable and I need to pass the ip of the postgres node to that variable with ${nodes.sqldb[0].address } It only works when I have manually implemented and added that variable and its value from the graphical interface but I have not been able to pass that variable to it from the JPS, not even by writing a random IP to see if it detects it.
Does anybody know what is it due to?
Thank you so much.

type: install
id: n8n-workflow
version: 1.0
name: n8n Workflow Automation
homepage: https://n8n.io/
logo: https://asset.brandfetch.io/idO6_6uqJ9/id-H5HD3pX.png?updated=1655217178680
globals:
  db_user: n8n-${fn.random(1000)}
  db_pswd: ${fn.password}
  encryption_key: n8n${fn.password}
targetRegions:
  type: [ vz.*, pcs.* ]
categories:
  - apps/automation
  - apps/popular

onBeforeInit: |
  import org.apache.commons.httpclient.HttpClient;
  import org.apache.commons.httpclient.methods.GetMethod;

  var client = new HttpClient(),
      getMethod,
      response,
      status,
      resp,
      url;
  
  url = "https://registry.hub.docker.com/v2/repositories/n8nio/n8n/tags";
  getMethod = new GetMethod(url);
  status = client.executeMethod(getMethod);
  resp = getMethod.getResponseBodyAsString();
  resp = JSON.parse(resp);
  tags = resp.results;

  var ver = {};
  var def = "latest";
  var tag;

  for (var i = 0, n = tags.length; i < n; i++) {
      tag = tags[i].name;
      if (tag) {
          ver[tag] = tag;
          def = tag;
      }
  }

  return {
      result: 0,
      settings: {
          fields: [{
              name: "version",
              caption: "n8n Version",
              type: "list",
              values: ver,
              "default": def
          }]
      }
  };

ssl: true

nodes:
- nodeType: nginx
  displayName: Load Balancer
  cloudlets: 16
  nodeGroup: bl
- image: n8nio/n8n:${settings.version}
  displayName: n8n
  cloudlets: 16
  nodeGroup: cp
  links: sqldb:db
  startServiceOnCreation: true
  env:
    N8N_BASIC_AUTH_ACTIVE: true
    N8N_BASIC_AUTH_USER: ${globals.db_user}
    N8N_BASIC_AUTH_PASSWORD: ${globals.db_pswd}
    WEBHOOK_TUNNEL_URL: ${env.url}
    N8N_ENCRYPTION_KEY: ${globals.encryption_key}
    DB_TYPE: postgresdb
    DB_POSTGRESDB_DATABASE: n8n
    DB_POSTGRESDB_HOST: ${nodes.sqldb[0].address}
    DB_POSTGRESDB_PORT: 5432
    DB_POSTGRESDB_USER: ${globals.db_user}
    DB_POSTGRESDB_PASSWORD: ${globals.db_pswd}
- image: postgres:16.2
  cloudlets: 16
  nodeGroup: sqldb
  displayName: PostgreSQL DB
  env:
    POSTGRES_USER: ${globals.db_user}
    POSTGRES_PASSWORD: ${globals.db_pswd}
    POSTGRES_DB: n8n

onInstall:
  - if ('${env.protocol}' == 'https'):
      cmd[bl]: |-
        CONF_FILE="/etc/nginx/nginx-jelastic.conf"
        sed -i ':a;$!{N;ba};s/\(location \/ {\)/\1\n\n\t\t\t\t\t\tif ($http_x_forwarded_proto = http) {\n\t\t\t\t\t\t\t\treturn 302 https:\/\/$host$request_uri;\n\t\t\t\t\t\t\t\terror_page  500 502 503 504 = @rescue;\n\t\t\t\t\t\t}\n/1' "$CONF_FILE"
        sed -i -r 's/(:80)$ common;/:5678$ common;/' "$CONF_FILE"
        sed -i -r 's/(server[[:space:]]+[0-9]+.[0-9]+.[0-9]+.[0-9]+)(;)/1:56782/g' "$CONF_FILE"
        sed -i -r 's/(server[[:space:]]+([0-9]+.[0-9]+.[0-9]+.[0-9]+))[[:space:]]*;/1:5678;/' "$CONF_FILE"
        service nginx restart
      user: root
      

success: |-
  n8n Workflow Automation is ready to use. Please open [${env.url}](${env.url}) to configure your workflows.
  
  **Username:** ${globals.db_user}
  **Password:** ${globals.db_pswd}

I tried with these options but the problem is that although the statement obtains the IP, it is not assigned to the environment variable.


DB_POSTGRESDB_HOST: ${nodes.sqldb[0].address}
DB_POSTGRESDB_HOST: ${nodes.sqldb.first.address}
DB_POSTGRESDB_HOST: ${nodes.sqldb.master.address}

The problem is that when the IP is assigned to the variable, the Postgres node has not been created, therefore it does not have an IP, how can I pass that IP to it later?

2

Answers


  1. Chosen as BEST ANSWER

    The problem is that when the IP is assigned to the variable, the Postgres node has not been created, therefore it does not have an IP, how can I pass that IP to it later?


  2. I suspect that ${nodes.sqldb[0].address} is not working because it may not be populated at the time (i.e. you can access that after all nodes are provisioned, but if you’re trying to set this up from the outset, the sqldb node may not yet be provisioned at the moment that the environment variables for the n8n node are being set).

    As an alternative, I can suggest trying:

    DB_POSTGRESDB_HOST: sqldb
    

    This approach uses the DNS hostnames for specific layers to form the connection via DNS instead of by an explicit IP.

    As an aside, are you publishing the resulting JPS in a public repo when it’s completed? It makes sense to iterate these packages together instead of everyone creating them individually.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search