8000 refactor: template internal data structure by buchdag · Pull Request #2405 · nginx-proxy/nginx-proxy · GitHub
[go: up one dir, main page]

Skip to content

refactor: template internal data structure #2405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 4, 2024
Merged

Conversation

buchdag
Copy link
Member
@buchdag buchdag commented Feb 24, 2024

This PR refactors the template internals to facilitate #1504

It centralise vhosts and vpaths values precomputation in a single range loop and remove some duplicated code.

The data structure stored for now in $globals.vhosts look like this :
{
  "foo.bar.com": {
    "cert": "",
    "cert_ok": false,
    "default": false,
    "hsts": "max-age=31536000",
    "http2_enabled": true,
    "http3_enabled": false,
    "https_method": "redirect",
    "paths": {
      "/": {
        "containers": [{}],
        "dest": "",
        "network_tag": "external",
        "proto": "http",
        "upstream": "foo.bar.com"
      }
    },
    "server_tokens": "",
    "ssl_policy": "",
    "vhost_root": "/var/www/public"
},{
  "multipath.bar.com": {
    "cert": "",
    "cert_ok": false,
    "default": false,
    "hsts": "max-age=31536000",
    "http2_enabled": true,
    "http3_enabled": false,
    "https_method": "redirect",
    "paths": {
      "/": {
        "containers": [{}],
        "dest": "",
        "network_tag": "external",
        "proto": "http",
        "upstream": "multipath.bar.com-somesha"
      },
      "/anotherpath": {
        "containers": [{}],
        "dest": "",
        "network_tag": "external",
        "proto": "http",
        "upstream": "multipath.bar.com-anothersha"
      }
    },
    "server_tokens": "",
    "ssl_policy": "",
    "vhost_root": "/var/www/public"
  }
}
Prior to this PR, it looked like this:
{
  "foo.bar.com": {
    "cert": "",
    "cert_ok": false,
    "containers": [{}],
    "default": false,
    "http3": false,
    "https_method": "redirect",
},{
  "multipath.bar.com": {
    "cert": "",
    "cert_ok": false,
    "containers": [{}],
    "default": false,
    "http3": false,
    "https_method": "redirect",
  }
}

At this point containers contains the list of containers objects (as generated by docker-gen) corresponding to each host / path combinations.

They look like this:
{
  "ID": "68aafce89930f680cb3714f4c1f4348058eb646abf5f69e84065fa7464437fa2",
  "Created": "2024-02-24T20:40:11.669487339Z",
  "Addresses": [
    {
      "IP": "172.17.0.3",
      "IP6LinkLocal": "",
      "IP6Global": "",
      "Port": "80",
      "HostPort": "",
      "Proto": "tcp",
      "HostIP": ""
    }
  ],
  "Networks": [
    {
      "IP": "172.17.0.3",
      "Name": "bridge",
      "Gateway": "172.17.0.1",
      "EndpointID": "20fdad73206d1b67ec068597c892515f3ec6af1f731d966e45a0db8c8ad50ba6",
      "IPv6Gateway": "",
      "GlobalIPv6Address": "",
      "MacAddress": "02:42:ac:11:00:03",
      "GlobalIPv6PrefixLen": 0,
      "IPPrefixLen": 16,
      "Internal": false
    }
  ],
  "Gateway": "172.17.0.1",
  "Name": "wonderful_ardinghelli",
  "Hostname": "68aafce89930",
  "NetworkMode": "default",
  "Image": {
    "Registry": "",
    "Repository": "nginx",
    "Tag": ""
  },
  "Env": {
    "NGINX_VERSION": "1.25.4",
    "NJS_VERSION": "0.8.3",
    "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
    "PKG_RELEASE": "1~bookworm",
    "VIRTUAL_HOST": "foo.bar.com"
  },
  "Volumes": {},
  "Node": {
    "ID": "",
    "Name": "",
    "Address": {
      "IP": "",
      "IP6LinkLocal": "",
      "IP6Global": "",
      "Port": "",
      "HostPort": "",
      "Proto": "",
      "HostIP": ""
    }
  },
  "Labels": {
    "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
  },
  "IP": "172.17.0.3",
  "IP6LinkLocal": "",
  "IP6Global": "",
  "Mounts": null,
  "State": {
    "Running": true,
    "Health": {
      "Status": ""
    }
  }
}

ping @pini-gh

@buchdag buchdag added the scope/multiport Issue or PR related to multi port proxying label Feb 24, 2024
@pini-gh
Copy link
Contributor
pini-gh commented Feb 26, 2024

Looks good. I'll need some time to try to rebase my fork on top of it.

Co-authored-by: pini-gh <pini@debian.org>
Co-authored-by: Niek <100143256+SchoNie@users.noreply.github.com>
@buchdag buchdag requested review from SchoNie and pini-gh February 27, 2024 12:37
@buchdag
Copy link
Member Author
buchdag commented Mar 2, 2024

Thanks for the approval @SchoNie

@pini-gh is it okay with you if I merge this now ?

@pini-gh
Copy link
Contributor
pini-gh commented Mar 4, 2024

Yes, please go ahead. Thanks!

@buchdag buchdag merged commit 4b38bf2 into main Mar 4, 2024
@buchdag buchdag deleted the refactor-template-2 branch March 4, 2024 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope/multiport Issue or PR related to multi port proxying
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0