Skip to content

Commit

Permalink
Enhancement: support dot-notated field properties in docker labels (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
icyleaf authored Oct 18, 2023
1 parent cbad95b commit 8ea2ccf
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 15 deletions.
17 changes: 17 additions & 0 deletions docs/configs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@ labels:
- homepage.widget.fields=["field1","field2"] # optional
```

You can add specify fields for e.g. the [CustomAPI](/widgets/services/customapi) widget by using array-style dot notation:

```yaml
labels:
- homepage.group=Media
- homepage.name=Emby
- homepage.icon=emby.png
- homepage.href=http://emby.home/
- homepage.description=Media server
- homepage.widget.type=customapi
- homepage.widget.url=http://argus.service/api/v1/service/summary/emby
- homepage.widget.field[0].label=Deployed Version
- homepage.widget.field[0].field.status=deployed_version
- homepage.widget.field[1].label=Latest Version
- homepage.widget.field[1].field.status=latest_version
```

## Docker Swarm

Docker swarm is supported and Docker services are specified with the same `server` and `container` notation. To enable swarm support you will need to include a `swarm` setting in your docker.yaml, e.g.
Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"react-i18next": "^11.18.6",
"react-icons": "^4.4.0",
"recharts": "^2.7.2",
"shvl": "^3.0.0",
"swr": "^1.3.0",
"systeminformation": "^5.17.12",
"tough-cookie": "^4.1.2",
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/utils/config/service-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import path from "path";

import yaml from "js-yaml";
import Docker from "dockerode";
import * as shvl from "shvl";
import { CustomObjectsApi, NetworkingV1Api, ApiextensionsV1Api } from "@kubernetes/client-node";

import createLogger from "utils/logger";
import checkAndCopyConfig, { CONF_DIR, substituteEnvironmentVars } from "utils/config/config";
import getDockerArguments from "utils/config/docker";
import getKubeConfig from "utils/config/kubernetes";
import * as shvl from "utils/config/shvl";

const logger = createLogger("service-helpers");

Expand Down
70 changes: 70 additions & 0 deletions src/utils/config/shvl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* eslint-disable */

/*
Code primarely based on shvl repository: https://github.com/robinvdvleuten/shvl
MIT License
Copyright (c) Robin van der Vleuten <robin@webstronauts.co>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

export function get(object, path, def) {
return (
// Split the path into keys and reduce the object to the target value
object = path.split(/[.[\]]+/).reduce(function (obj, p) {
// Check each nested object to see if the key exists
return obj && obj[p] !== undefined ? obj[p] : undefined;
}, object)
) === undefined
// If the final value is undefined, return the default value
? def
: object; // Otherwise, return the value found
}

export function set(obj, path, val) {
// Split the path into keys and filter out any empty strings
const keys = path.split(/[.[\]]+/).filter(Boolean);

// Pop the last key to set the value later
const lastKey = keys.pop();

// Prevent setting dangerous keys like __proto__
if (/^(__proto__|constructor|prototype)$/.test(lastKey)) return obj;

// Reduce the object to the nested object where we want to set the value
keys.reduce((acc, key, i) => {
// Again, block dangerous keys
if (/^(__proto__|constructor|prototype)$/.test(key)) return {};

// Check if next key is an array index
const isIndex = /^\d+$/.test(keys[i + 1]);

// If current key doesn't exist, initialise it as an array or object
acc[key] = Array.isArray(acc[key])
? acc[key]
: (isIndex ? [] : acc[key] || {});

// Return nested object for next iteration
return acc[key];
}, obj)[lastKey] = val; // Finally set the value

return obj;
}

0 comments on commit 8ea2ccf

Please sign in to comment.