N8N 未使用 Jelastic JPS 检测环境变量中的 ip

问题描述 投票:0回答:1

我正在尝试使用 JPS 清单实现 n8n,但我遇到的问题是 Jelastic 未检测到 DB_POSTGRESDB_HOST 环境变量,并且我需要使用 ${nodes.sqldb[0] 将 postgres 节点的 ip 传递给该变量。它仅在我从图形界面手动实现并添加该变量及其值时有效,但我无法从 JPS 将该变量传递给它,甚至无法通过编写随机 IP 来查看它是否检测到它。 有谁知道这是什么原因吗? 非常感谢。

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:5678\2/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}

我尝试了这些选项,但问题是虽然该语句获取了IP,但它没有分配给环境变量。


DB_POSTGRESDB_HOST: ${nodes.sqldb[0].address}
DB_POSTGRESDB_HOST: ${nodes.sqldb.first.address}
DB_POSTGRESDB_HOST: ${nodes.sqldb.master.address}
jelastic n8n virtuozzo
1个回答
0
投票

我怀疑

${nodes.sqldb[0].address}
不起作用,因为当时它可能尚未填充(即,您可以在配置所有节点后访问它,但如果您尝试从一开始就进行设置,则 sqldb 节点可能不会但在设置
n8n
节点的环境变量时进行配置)。

作为替代方案,我可以建议尝试:

DB_POSTGRESDB_HOST: sqldb

此方法使用 特定层的 DNS 主机名 通过 DNS 而不是通过显式 IP 形成连接。

顺便说一句,您是否在完成后将生成的 JPS 发布在公共存储库中?将这些包一起迭代而不是每个人单独创建它们是有意义的。

© www.soinside.com 2019 - 2024. All rights reserved.