Skip to content

Commit

Permalink
Merge pull request #67 from SaaShup/volume-bind
Browse files Browse the repository at this point in the history
✨ Support mounting host paths in container as binds
  • Loading branch information
linkdd authored Mar 28, 2024
2 parents 997d9a9 + 0f29f2b commit cccd15a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions flows.json
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\t \"host\": msg.config.id,\t \"name\": $replace(msg.result.Name,\"/\",\"\"),\t \"hostname\": msg.result.Config.Hostname,\t \"status\": msg.result.State.Status = \"running\" ? \"running \" & $ceil(($toMillis($now()) - $toMillis(msg.result.State.StartedAt)) / 1000 / 60 / 60 / 24) & \"d\" : \"na\",\t \"state\": msg.result.State.Status,\t \"operation\": \"none\",\t \"image\": {\t \"host\": msg.config.id,\t \"ImageID\": msg.result.Image\t },\t \"ContainerID\": msg.result.Id,\t \"network_settings\": [$each(msg.result.NetworkSettings.Networks, function($v, $k) { { \"network\": { \"host\": msg.config.id, \"name\": $k } } })],\t \"ports\": msg.result.NetworkSettings.Ports ? [$each(msg.result.NetworkSettings.Ports, function($v, $k) { { \"public_port\" : $v[0] = null ? 0 : $v[0].HostPort, \"private_port\": $split($k,\"/\")[0], \"type\": $split($k,\"/\")[1] } })] : [$each(msg.result.Config.ExposedPorts, function($v, $k) { $not($exists($lookup($v,'IP'))) or $lookup($v,'IP') = \"0.0.0.0\" ? { \"public_port\": $v.PublicPort ? $v.PublicPort : \"0\", \"private_port\": $split($k,\"/\")[0], \"type\": $split($k,\"/\")[1] } })],\t \"env\": [$map(msg.result.Config.Env, function($v, $k) { { \"var_name\": $split($v,\"=\")[0], \"value\": $split($v,\"=\")[1] } })],\t \"labels\": [$each(msg.result.Config.Labels, function($v, $k) { { \"key\": $k, \"value\": $v } })],\t \"mounts\": [$map(msg.result.Mounts, function($v, $k) { $v.Type = \"volume\" ? { \"source\": $v.Destination, \"volume\": { \"name\": $v.Name, \"host\": msg.config.id } } })]\t}",
"to": "{\t \"host\": msg.config.id,\t \"name\": $replace(msg.result.Name,\"/\",\"\"),\t \"hostname\": msg.result.Config.Hostname,\t \"status\": msg.result.State.Status = \"running\"\t ? \"running \" & $ceil(($toMillis($now()) - $toMillis(msg.result.State.StartedAt)) / 1000 / 60 / 60 / 24) & \"d\"\t : \"na\",\t \"state\": msg.result.State.Status,\t \"operation\": \"none\",\t \"image\": {\t \"host\": msg.config.id,\t \"ImageID\": msg.result.Image\t },\t \"ContainerID\": msg.result.Id,\t \"network_settings\": [\t $each(\t msg.result.NetworkSettings.Networks,\t function($v, $k) {\t { \"network\": { \"host\": msg.config.id, \"name\": $k } }\t }\t )\t ],\t \"ports\": msg.result.NetworkSettings.Ports\t ? [\t $each(\t msg.result.NetworkSettings.Ports,\t function($v, $k) {\t {\t \"public_port\": $v[0] = null ? 0 : $v[0].HostPort,\t \"private_port\": $split($k,\"/\")[0],\t \"type\": $split($k,\"/\")[1]\t }\t }\t )\t ]\t : [\t $each(\t msg.result.Config.ExposedPorts,\t function($v, $k) {\t $not($exists($lookup($v,'IP'))) or $lookup($v,'IP') = \"0.0.0.0\"\t ? {\t \"public_port\": $v.PublicPort ? $v.PublicPort : \"0\",\t \"private_port\": $split($k,\"/\")[0],\t \"type\": $split($k,\"/\")[1]\t }\t }\t )\t ],\t \"env\": [\t $map(\t msg.result.Config.Env,\t function($v, $k) {\t { \"var_name\": $split($v,\"=\")[0], \"value\": $split($v,\"=\")[1] }\t }\t )\t ],\t \"labels\": [\t $each(\t msg.result.Config.Labels,\t function($v, $k) {\t { \"key\": $k, \"value\": $v }\t }\t )\t ],\t \"mounts\": [\t $map(\t msg.result.Mounts,\t function($v, $k) {\t $v.Type = \"volume\"\t ? {\t \"source\": $v.Destination,\t \"volume\": { \"name\": $v.Name, \"host\": msg.config.id }\t }\t }\t )\t ],\t \"binds\": [\t $map(\t msg.result.Mounts,\t function($v, $k) {\t $v.Type = \"bind\"\t ? {\t \"host_path\": $v.Source,\t \"container_path\": $v.Destination\t }\t }\t )\t ]\t}",
"tot": "jsonata"
}
],
Expand Down Expand Up @@ -3188,7 +3188,7 @@
"t": "set",
"p": "payload",
"pt": "msg",
"to": "[{\t \"id\": msg.input.data.id,\t \"host\": msg.input.data.host.id,\t \"name\": $replace(msg.result.Name,\"/\",\"\"),\t \"hostname\": msg.result.Config.Hostname,\t \"state\": msg.result.State.State,\t \"operation\": \"none\",\t \"status\": msg.result.State.Status = \"running\" ? \"running \" & $ceil(($toMillis($now()) - $toMillis(msg.result.State.StartedAt)) / 1000 / 60 / 60 / 24) & \"d\" : \"na\",\t \"image\": {\t \"host\": msg.input.data.host.id,\t \"ImageID\": msg.result.Image\t },\t \"ContainerID\": msg.result.Id,\t \"network_settings\": [$each(msg.result.NetworkSettings.Networks, function($v, $k) { { \"network\": { \"name\": $k } } })],\t \"ports\": msg.result.NetworkSettings.Ports ? [$each(msg.result.NetworkSettings.Ports, function($v, $k) { { \"public_port\" : $v[0] = null ? 0 : $v[0].HostPort, \"private_port\": $split($k,\"/\")[0], \"type\": $split($k,\"/\")[1] } })] : [$each(msg.result.Config.ExposedPorts, function($v, $k) { $not($exists($lookup($v,'IP'))) or $lookup($v,'IP') = \"0.0.0.0\" ? { \"public_port\": $v.PublicPort ? $v.PublicPort : \"0\", \"private_port\": $split($k,\"/\")[0], \"type\": $split($k,\"/\")[1] } })],\t \"env\": [$map(msg.result.Config.Env, function($v, $k) { { \"var_name\": $split($v,\"=\")[0], \"value\": $split($v,\"=\")[1] } })],\t \"labels\": [$each(msg.result.Config.Labels, function($v, $k) { { \"key\": $k, \"value\": $v } })],\t \"mounts\": [$map(msg.result.Mounts, function($v, $k) { $v.Type = \"volume\" ? { \"source\": $v.Source, \"volume\": { \"name\": $v.Name, \"host\": msg.config.id } } })]\t}]",
"to": "[{\t \"id\": msg.input.data.id,\t \"host\": msg.input.data.host.id,\t \"name\": $replace(msg.result.Name,\"/\",\"\"),\t \"hostname\": msg.result.Config.Hostname,\t \"state\": msg.result.State.State,\t \"operation\": \"none\",\t \"status\": msg.result.State.Status = \"running\"\t ? \"running \" & $ceil(($toMillis($now()) - $toMillis(msg.result.State.StartedAt)) / 1000 / 60 / 60 / 24) & \"d\"\t : \"na\",\t \"image\": {\t \"host\": msg.input.data.host.id,\t \"ImageID\": msg.result.Image\t },\t \"ContainerID\": msg.result.Id,\t \"network_settings\": [\t $each(\t msg.result.NetworkSettings.Networks,\t function($v, $k) {\t { \"network\": { \"name\": $k } }\t }\t )\t ],\t \"ports\": msg.result.NetworkSettings.Ports\t ? [\t $each(\t msg.result.NetworkSettings.Ports,\t function($v, $k) {\t {\t \"public_port\": $v[0] = null ? 0 : $v[0].HostPort,\t \"private_port\": $split($k,\"/\")[0],\t \"type\": $split($k,\"/\")[1]\t }\t }\t )\t ]\t : [\t $each(\t msg.result.Config.ExposedPorts,\t function($v, $k) {\t $not($exists($lookup($v,'IP'))) or $lookup($v,'IP') = \"0.0.0.0\"\t ? {\t \"public_port\": $v.PublicPort ? $v.PublicPort : \"0\",\t \"private_port\": $split($k,\"/\")[0],\t \"type\": $split($k,\"/\")[1]\t }\t }\t )\t ],\t \"env\": [\t $map(\t msg.result.Config.Env,\t function($v, $k) {\t { \"var_name\": $split($v,\"=\")[0], \"value\": $split($v,\"=\")[1] }\t }\t )\t ],\t \"labels\": [\t $each(\t msg.result.Config.Labels,\t function($v, $k) {\t { \"key\": $k, \"value\": $v }\t }\t )\t ],\t \"mounts\": [\t $map(\t msg.result.Mounts,\t function($v, $k) {\t $v.Type = \"volume\"\t ? {\t \"source\": $v.Source,\t \"volume\": { \"name\": $v.Name, \"host\": msg.config.id }\t }\t }\t )\t ],\t \"binds\": [\t $map(\t msg.result.Mounts,\t function($v, $k) {\t $v.Type = \"bind\"\t ? {\t \"host_path\": $v.Source,\t \"container_path\": $v.Destination\t }\t }\t )\t ]\t}]",
"tot": "jsonata"
}
],
Expand Down Expand Up @@ -3902,7 +3902,7 @@
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\t \"Image\": msg.input.data.image.name & \":\" & msg.input.data.image.version,\t \"Hostname\": msg.input.data.hostname,\t \"Env\": [\t $map(\t msg.input.data.env,\t function($k,$v){$k.var_name &\"=\" & $k.value}\t )\t ],\t \"Labels\": $merge(\t $map(\t msg.input.data.labels,\t function($k,$v) {{ $k.key: $k.value }}\t )\t ),\t \"ExposedPorts\": $merge(\t $map(\t msg.input.data.ports,\t function($k,$v){\t {\t $k.private_port & \"/\" & $k.type: {} \t } \t }\t )\t ),\t \"PortBindings\": $merge(\t $map(\t msg.input.data.ports,\t function($k,$v){\t {\t $k.private_port & \"/\" & $k.type: $k.public_port ? [{ \"HostIp\": \"\", \"HostPort\" : $string($k.public_port) }] : [] \t } \t }\t )\t ),\t \"Mounts\": [\t $map(\t msg.input.data.mounts,\t function($k,$v){\t {\t \"Target\": $k.source,\t \"Name\": $k.volume.name,\t \"Type\": \"volume\",\t \"Destination\": $k.source,\t \"RW\": true,\t \"Mode\": \"z\",\t \"Source\": $k.volume.name,\t \"Driver\": $k.volume.driver\t }\t }\t )\t ],\t \"NetworkingConfig\": {\t \"EndpointsConfig\": $merge($map(msg.input.data.network_settings, function($k,$v) { $v = 0 ? { $k.network.name : { \"NetworkID\": $k.network.NetworkID } } }))\t }\t}",
"to": "{\t \"Image\": msg.input.data.image.name & \":\" & msg.input.data.image.version,\t \"Hostname\": msg.input.data.hostname,\t \"Env\": [\t $map(\t msg.input.data.env,\t function($v, $k) {\t $v.var_name &\"=\" & $v.value\t }\t )\t ],\t \"Labels\": $merge(\t $map(\t msg.input.data.labels,\t function($v, $k) {\t { $v.key: $v.value }\t }\t )\t ),\t \"ExposedPorts\": $merge(\t $map(\t msg.input.data.ports,\t function($v, $k) {\t {\t $v.private_port & \"/\" & $v.type: {} \t } \t }\t )\t ),\t \"PortBindings\": $merge(\t $map(\t msg.input.data.ports,\t function($v, $k){\t {\t $v.private_port & \"/\" & $v.type: $v.public_port\t ? [ { \"HostIp\": \"\", \"HostPort\" : $string($v.public_port) }]\t : [] \t } \t }\t )\t ),\t \"Mounts\": [\t $map(\t msg.input.data.mounts,\t function($v, $k) {\t {\t \"Target\": $v.source,\t \"Name\": $v.volume.name,\t \"Type\": \"volume\",\t \"Destination\": $v.source,\t \"RW\": true,\t \"Mode\": \"z\",\t \"Source\": $v.volume.name,\t \"Driver\": $v.volume.driver\t }\t }\t ),\t $map(\t msg.input.data.binds,\t function($v, $k) {\t {\t \"Target\": $v.container_path,\t \"Type\": \"bind\",\t \"Destination\": $v.container_path,\t \"RW\": true,\t \"Mode\": \"z\",\t \"Source\": $v.host_path,\t \"BindOptions\": {\t \"CreateMountpoint\": true\t }\t }\t }\t )\t ],\t \"NetworkingConfig\": {\t \"EndpointsConfig\": $merge(\t $map(\t msg.input.data.network_settings,\t function($v, $k) {\t $k = 0 ? { $v.network.name : { \"NetworkID\": $v.network.NetworkID } }\t }\t )\t )\t }\t}\t",
"tot": "jsonata"
},
{
Expand Down Expand Up @@ -4293,7 +4293,7 @@
"t": "set",
"p": "payload",
"pt": "msg",
"to": "[{\t \"id\": msg.input.data.id,\t \"host\": msg.input.data.host.id,\t \"name\": $replace(msg.result.Name,\"/\",\"\"),\t \"hostname\": msg.result.Config.Hostname,\t \"operation\": \"none\",\t \"state\": msg.result.State.Status,\t \"status\": msg.result.State.Status = \"running\" ? \"running \" & $ceil(($toMillis($now()) - $toMillis(msg.result.State.StartedAt)) / 1000 / 60 / 60 / 24) & \"d\" : \"na\",\t \"image\": {\t \"host\": msg.input.data.host.id,\t \"ImageID\": msg.result.Image\t },\t \"ContainerID\": msg.result.Id,\t \"network_settings\": [$each(msg.result.NetworkSettings.Networks, function($v, $k) { { \"network\": { \"name\": $k } } })],\t \"ports\": msg.result.NetworkSettings.Ports ? [$each(msg.result.NetworkSettings.Ports, function($v, $k) { { \"public_port\" : $v[0] = null ? 0 : $v[0].HostPort, \"private_port\": $split($k,\"/\")[0], \"type\": $split($k,\"/\")[1] } })] : [$each(msg.result.Config.ExposedPorts, function($v, $k) { $not($exists($lookup($v,'IP'))) or $lookup($v,'IP') = \"0.0.0.0\" ? { \"public_port\": $v.PublicPort ? $v.PublicPort : \"0\", \"private_port\": $split($k,\"/\")[0], \"type\": $split($k,\"/\")[1] } })],\t \"env\": [$map(msg.result.Config.Env, function($v, $k) { { \"var_name\": $split($v,\"=\")[0], \"value\": $split($v,\"=\")[1] } })],\t \"labels\": [$each(msg.result.Config.Labels, function($v, $k) { { \"key\": $k, \"value\": $v } })],\t \"mounts\": [$map(msg.result.Mounts, function($v, $k) { $v.Type = \"volume\" ? { \"source\": $v.Source, \"volume\": { \"name\": $v.Name, \"host\": msg.config.id } } })]\t}]",
"to": "[{\t \"id\": msg.input.data.id,\t \"host\": msg.input.data.host.id,\t \"name\": $replace(msg.result.Name,\"/\",\"\"),\t \"hostname\": msg.result.Config.Hostname,\t \"operation\": \"none\",\t \"state\": msg.result.State.Status,\t \"status\": msg.result.State.Status = \"running\"\t ? \"running \" & $ceil(($toMillis($now()) - $toMillis(msg.result.State.StartedAt)) / 1000 / 60 / 60 / 24) & \"d\"\t : \"na\",\t \"image\": {\t \"host\": msg.input.data.host.id,\t \"ImageID\": msg.result.Image\t },\t \"ContainerID\": msg.result.Id,\t \"network_settings\": [\t $each(\t msg.result.NetworkSettings.Networks,\t function($v, $k) {\t { \"network\": { \"name\": $k } }\t }\t )\t ],\t \"ports\": msg.result.NetworkSettings.Ports\t ? [\t $each(\t msg.result.NetworkSettings.Ports,\t function($v, $k) {\t {\t \"public_port\": $v[0] = null ? 0 : $v[0].HostPort,\t \"private_port\": $split($k,\"/\")[0],\t \"type\": $split($k,\"/\")[1]\t }\t }\t )\t ]\t : [\t $each(\t msg.result.Config.ExposedPorts,\t function($v, $k) {\t $not($exists($lookup($v,'IP'))) or $lookup($v,'IP') = \"0.0.0.0\"\t ? {\t \"public_port\": $v.PublicPort ? $v.PublicPort : \"0\",\t \"private_port\": $split($k,\"/\")[0],\t \"type\": $split($k,\"/\")[1]\t }\t }\t )\t ],\t \"env\": [\t $map(\t msg.result.Config.Env,\t function($v, $k) {\t { \"var_name\": $split($v,\"=\")[0], \"value\": $split($v,\"=\")[1] }\t }\t )\t ],\t \"labels\": [\t $each(\t msg.result.Config.Labels,\t function($v, $k) {\t { \"key\": $k, \"value\": $v }\t }\t )\t ],\t \"mounts\": [\t $map(\t msg.result.Mounts,\t function($v, $k) {\t $v.Type = \"volume\"\t ? {\t \"source\": $v.Source,\t \"volume\": { \"name\": $v.Name, \"host\": msg.config.id }\t }\t }\t )\t ],\t \"binds\": [\t $map(\t msg.result.Mounts,\t function($v, $k) {\t $v.Type = \"bind\"\t ? {\t \"host_path\": $v.Source,\t \"container_path\": $v.Destination\t }\t }\t )\t ]\t}]",
"tot": "jsonata"
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "netbox-docker-agent",
"version": "0.13.7",
"version": "0.14.0",
"description": "Saashup agent for netbox manager",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit cccd15a

Please sign in to comment.