Skip to content

Instantly share code, notes, and snippets.

@ravensorb
Last active February 16, 2021 13:29
Show Gist options
  • Save ravensorb/5513ccc1b488832204498300fb868467 to your computer and use it in GitHub Desktop.
Save ravensorb/5513ccc1b488832204498300fb868467 to your computer and use it in GitHub Desktop.
json schema file for a container
{
"enabled": true,
"name": "",
"registry": "{{docker-registry-base-url}}",
"imageName": "",
"tag": "",
"build": {
"enabled": false,
"generate": false,
"context": ".",
"dockerfile": "Dockerfile.{{serviceName}}",
"args": [
{ "name": "EXTRAS_UPGRADE_SYSTEM_PACKAGES", "value": "1", "comment": "Update all system packages " },
{ "name": "EXTRAS_ENABLE_PYTHON2", "value": "0", "comment": "Install and enable python2" },
{ "name": "EXTRAS_ENABLE_PYTHON3", "value": "1", "comment": "Install and enable python3" },
{ "name": "EXTRAS_ENABLE_7ZIP", "value": "1", "comment": "Install and enable 7-zip" },
{ "name": "EXTRAS_ENABLE_CRON", "value": "0", "comment": "Install and enable crond" },
{ "name": "EXTRAS_ENABLE_ENVSUBST", "value": "1", "comment": "Install and enable an enhanced version of envsubst" },
{ "name": "EXTRAS_ENABLE_CRUDINI", "value": "1", "comment": "Install and enable crudini" },
{ "name": "EXTRAS_ENABLE_FFMPEG", "value": "0", "comment": "Install and enable ffmpeg" },
{ "name": "EXTRAS_ENABLE_SMA", "value": "0", "comment": "Install and enable sma" }
],
"environment": [
],
"volumes": [
"/config",
"/data"
],
"copycmd": [
{ "host": "{{path-service-setup-build-scripts}}", "container": "/opt/setup/build/scripts/" },
{ "host": "{{path-service-setup-build-config}}", "container": "/opt/setup/build/config/" },
{ "host": "{{path-service-setup-init-scripts}}", "container": "/opt/setup/init/scripts/" },
{ "host": "{{path-service-setup-init-config}}", "container": "/opt/setup/init/config/" },
{ "host": "{{path-service-setup-app-scripts}}", "container": "/opt/setup/app/scripts/" },
{ "host": "{{path-service-setup-app-config}}", "container": "/opt/setup/app/config/" }
],
"command": [
],
"runcmd": [
"/opt/setup/build/scripts/00-setup.sh"
]
},
"environment": [
{ "name": "UMASK_SET", "value": "022", "comment": "Set the default umask value for the container" }
],
"volumes": [
{ "host": "{{path-service-base-data}}", "container": "/config:rw" }
],
"networks": [
{ "name": "data" }
],
"traefik": {
"enabled": true,
"network": "{{primaryNetwork}}",
"routers": [
{
"name": "{{serviceName}}",
"priority": 0,
"entryPoint": "websecure",
"tls": {
"enabled": true,
"comment": ""
},
"rule": {
"type": "host" , "comment": ""
},
"middleware": [
],
"service": {
"name": "{{serviceName}}",
"port": 80,
"schema": "http",
"comment": ""
},
"comment": ""
}
]
},
"logging": {
"driver": "json-file",
"options": {
"maxsize": "100m",
"maxfiles": "10"
}
},
"templates": [
"env.service",
"dockerfile.service"
],
"comment": ""
}
{
"registry": "{{docker-registry-base-url}}",
"imageName": "linuxserver/qbittorrent",
"tag": "",
"hubUrl": "",
"watchTower": "false",
"build": {
"enabled": true,
"from": "linuxserver/qbittorrent",
"context": ".",
"dockerfile": "Dockerfile.{{serviceName}}",
"environment": [
{ "name": "EXTRAS_UPGRADE_SYSTEM_PACKAGES", "value": "1" },
{ "name": "EXTRAS_ENABLE_PYTHON2", "value": "0" },
{ "name": "EXTRAS_ENABLE_PYTHON3", "value": "1" },
{ "name": "EXTRAS_ENABLE_7ZIP", "value": "1" },
{ "name": "EXTRAS_ENABLE_ENVSUBST", "value": "1" },
{ "name": "EXTRAS_ENABLE_CRUDINI", "value": "1" },
{ "name": "EXTRAS_ENABLE_FFMPEG", "value": "1" },
{ "name": "EXTRAS_ENABLE_SMA", "value": "1" }
]
},
"volumes": [
{ "host": "{{path-service-base-data}}", "container": "/config:rw" },
{ "host": "{{path-scripts-media-sma-config}}", "container": "/config/sma:rw" },
{ "host": "{{path-media-downloads-inprogress}}", "container": "/mnt/downloads/inprogress:rw" },
{ "host": "{{path-media-downloads-complete}}", "container": "/mnt/downloads/completed:rw" }
],
"environment": [
{ "name": "UMASK_SET", "value": "022" },
{ "name": "WEBUI_PORT_INTERNAL_HTTP", "ref": "qbittorrent-port-internal-http", "value": "8080" },
{ "name": "QBITTORRENT_URL_EXTERNAL", "ref": "qbittorrent-url-external", "value": "https://{{qbittorrent-host-external}}", "format": "expanded" },
{ "name": "QBITTORRENT_URL_INTERNAL", "ref": "qbittorrent-url-internal", "value": "http://{{qbittorrent-host-internal}}:{{qbittorrent-port-internal-http}}", "format": "expanded" },
{ "name": "QBITTORRENT_HOST_EXTERNAL", "ref": "qbittorrent-host-external", "value": "{{hostname}}" },
{ "name": "QBITTORRENT_HOST_INTERNAL", "ref": "qbittorrent-host-internal", "value": "{{servicename}}", "format": "expanded" },
{ "name": "QBITTORRENT_USERNAME", "ref": "qbittorrent-username", "value": "" },
{ "name": "QBITTORRENT_PASSWORD", "ref": "qbittorrent-password", "value": "" },
{ "name": "QBITTORRENT_PORT_INCOMMING_TCP", "value": "6881" },
{ "name": "QBITTORRENT_PORT_INCOMMING_UDP", "value": "6881" },
{ "name": "QBITTORRENT_NOTIFICATION_EMAILTO", "ref": "mail-address-notification" },
{ "name": "QBITTORRENT_NOTIFICATION_EMAILFROM", "ref": "mail-smtp-fromemail" },
{ "name": "QBITTORRENT_NOTIFICATION_ENABLED", "value": "false" },
{ "name": "QBITTORRENT_NOTIFICATION_SMTP_AUTHENABLED", "ref": "mail-smtp-authenabled", "value": "false" },
{ "name": "QBITTORRENT_NOTIFICATION_SMTP_SSLENABLED", "ref": "mail-smtp-sslenabled", "value": "false" },
{ "name": "QBITTORRENT_NOTIFICATION_SMTP_SERVER", "ref": "mail-smtp-host" },
{ "name": "QBITTORRENT_NOTIFICATION_SMTP_USERNAME", "ref": "mail-smtp-username" },
{ "name": "QBITTORRENT_NOTIFICATION_SMTP_PASSWORD", "ref": "mail-smtp-password" },
{ "name": "EXTRAS_ENABLE_SMA", "value": "1" }
],
"networks": [
{ "name": "media", "mode": "external" }
],
"traefik": {
"enabled": true,
"network": "{{primaryNetwork}}",
"routers": [
{
"type": "http",
"name": "{{serviceName}}-http",
"entryPoint": "websecure",
"tls": {
"enabled": "true"
},
"rule": { "type": "Host" },
"middleware": [
],
"service": {
"name": "{{serviceName}}-http",
"port": "${WEBUI_PORT_INTERNAL_HTTP}",
"scheme": "http"
}
},
{
"type": "tcp",
"name": "{{serviceName}}-torrentIn6881tcp",
"rule": { "type": "Host" },
"entryPoint": "torrentIn6881tcp",
"middleware": [
],
"service": {
"name": "{{serviceName}}-torrentIn6881tcp",
"port": "${QBITTORRENT_PORT_INCOMMING_TCP}"
}
},
{
"type": "udp",
"name": "{{serviceName}}-torrentIn6881udp",
"entryPoint": "torrentIn6881udp",
"service": {
"name": "{{serviceName}}-torrentIn6881udp",
"port": "${QBITTORRENT_PORT_INCOMMING_UDP}"
}
}
]
}
}
#!/bin/python3
import json
import copy
from jsonmerge import Merger
def _loadJsonFile(jsonFile):
with open(jsonFile,) as fFile:
result = json.load(fFile)
return result
schemaContainer = _loadJsonFile('schema.container.json')
baseContainerJson = _loadJsonFile('container.base.json')
containerJson1 = _loadJsonFile('container1.json')
mergerObj = Merger(schemaContainer)
#print("Before Merge: {}".format(json.dumps(containerJson1)))
print("Before Merge")
print("Priority is {} in traefik.routers[0]".format("FOUND" if "priority" in containerJson1["traefik"]["routers"][0] else "NOT FOUND"))
print("Priority is {} in traefik.routers[1]".format("FOUND" if "priority" in containerJson1["traefik"]["routers"][1] else "NOT FOUND"))
result1 = mergerObj.merge(copy.deepcopy(baseContainerJson), containerJson1) # Deep copy is required otherwise baseContainJson is updated
#print("After Merge: {}".format(json.dumps(result1)))
print("After Merge")
print("Priority is {} in traefik.routers[0]".format("FOUND" if "priority" in result1["traefik"]["routers"][0] else "NOT FOUND"))
print("Priority is {} in traefik.routers[1]".format("FOUND" if "priority" in result1["traefik"]["routers"][1] else "NOT FOUND"))
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://eye-catcher.com/docker-app-base-schema.json",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"name",
"imageName",
"network"
],
"definitions": {
"uniquevariablearray": {
"$id": "#/definitions/uniquevariablearray",
"type": "array",
"default": [],
"mergeStrategy": "arrayMergeById",
"mergeOptions": { "idRef": "name" },
"additionalItems": true,
"items": {
"$ref": "#/definitions/variableitem"
}
},
"variableitem": {
"$id": "#/definitions/variableitem",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"name"
],
"properties": {
"name": {
"$id": "#/definitions/variableitem/properties/name",
"type": "string",
"default": ""
},
"value": {
"$id": "#/definitions/variableitem/properties/value",
"type": "string",
"default": ""
},
"ref": {
"$id": "#/definitions/variableitem/properties/ref",
"type": "string",
"default": ""
},
"type": {
"$id": "#/definitions/variableitem/properties/type",
"type": "string",
"default": ""
},
"format": {
"$id": "#/definitions/variableitem/properties/format",
"type": "string",
"default": ""
},
"comment": {
"$id": "#/definitions/variableitem/properties/comment",
"type": "string",
"default": ""
}
},
"additionalProperties": true
},
"uniquehostcontainerarray": {
"$id": "#/definitions/uniquehostcontainerarray",
"type": "array",
"default": [],
"mergeStrategy": "arrayMergeById",
"mergeOptions": { "idRef": "name" },
"additionalItems": true,
"items": {
"$ref": "#/definitions/hostcontaineritem"
}
},
"hostcontaineritem": {
"$id": "#/definitions/hostcontaineritem",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"host",
"container"
],
"properties": {
"host": {
"$id": "#/definitions/hostcontaineritem/properties/host",
"type": "string",
"default": ""
},
"container": {
"$id": "#/definitions/hostcontaineritem/properties/container",
"type": "string",
"default": ""
},
"comment": {
"$id": "#/definitions/hostcontaineritem/properties/comment",
"type": "string",
"default": ""
}
},
"additionalProperties": true
},
"uniquestringarray": {
"$id": "#/definitions/uniquestringarray",
"type": "array",
"default": [],
"mergeStrategy": "append",
"mergeOptions": { "uniqueItems": true },
"additionalItems": true,
"items": {
"type": "string",
"default": ""
}
},
"traefik": {
"$id": "#/definitions/traefik",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"enabled",
"network",
"routers"
],
"properties": {
"enabled": {
"$id": "#/definitions/traefik/properties/enabled",
"type": "boolean",
"default": false
},
"network": {
"$id": "#/definitions/traefik/properties/network",
"type": "string",
"default": ""
},
"routers": {
"$id": "#/definitions/traefik/properties/routers",
"type": "array",
"default": [],
"mergeStrategy": "arrayMergeById",
"mergeOptions": { "idRef": "name" },
"additionalItems": true,
"items": {
"$ref": "#/definitions/traefikrouteritem"
}
}
},
"additionalProperties": true
},
"traefikrouteritem":{
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"name",
"entryPoint",
"priority",
"tls",
"rule",
"service"
],
"properties": {
"name": {
"$id": "#/definitions/traefikrouteritem/properties/name",
"type": "string",
"default": ""
},
"priority": {
"$id": "#/definitions/traefikrouteritem/properties/priority",
"type": "integer",
"default": 0
},
"entryPoint": {
"$id": "#/definitions/traefikrouteritem/properties/entryPoint",
"type": "string",
"default": ""
},
"tls": {
"$id": "#/definitions/traefikrouteritem/properties/tls",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"enabled"
],
"properties": {
"enabled": {
"$id": "#/definitions/traefikrouteritem/properties/tls/properties/enabled",
"type": "boolean",
"default": false
},
"comment": {
"$id": "#/definitions/traefikrouteritem/properties/tls/properties/comment",
"type": "string",
"default": ""
},
"certresolver": {
"$id": "#/definitions/traefikrouteritem/properties/tls/properties/certresolver",
"type": "string",
"default": ""
},
"domains": {
"$id": "#/definitions/traefikrouteritem/properties/tls/properties/domains",
"type": "array",
"default": [],
"mergeStrategy": "arrayMergeById",
"mergeOptions": { "idRef": "name" },
"additionalItems": true,
"items": {
"$ref": "#/definitions/traefikrouterdomainitem"
}
}
},
"additionalProperties": true
},
"rule": {
"$id": "#/definitions/traefikrouteritem/properties/rule",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"type"
],
"properties": {
"type": {
"$id": "#/definitions/traefikrouteritem/properties/rule/properties/type",
"type": "string",
"default": "Host"
},
"comment": {
"$id": "#/definitions/traefikrouteritem/properties/rule/properties/comment",
"type": "string",
"default": ""
}
},
"additionalProperties": true
},
"middleware": {
"$id": "#/definitions/traefikrouteritem/properties/middleware",
"type": "array",
"default": [],
"mergeStrategy": "arrayMergeById",
"mergeOptions": { "idRef": "name" },
"additionalItems": true,
"items": {
"$ref": "#/definitions/traefikroutermiddlewareitem"
}
},
"service": {
"$id": "#/definitions/traefikrouteritem/properties/service",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"name",
"port",
"schema"
],
"properties": {
"name": {
"$id": "#/definitions/traefikrouteritem/properties/service/properties/name",
"type": "string",
"default": "{{servic}}"
},
"port": {
"$id": "#/definitions/traefikrouteritem/properties/service/properties/port",
"type": "integer",
"default": 90
},
"schema": {
"$id": "#/definitions/traefikrouteritem/properties/service/properties/schema",
"type": "string",
"default": "https"
},
"comment": {
"$id": "#/definitions/traefikrouteritem/properties/service/properties/comment",
"type": "string",
"default": ""
}
},
"additionalProperties": true
},
"comment": {
"$id": "#/definitions/traefikrouteritem/properties/comment",
"type": "string",
"default": ""
}
},
"additionalProperties": true
},
"traefikrouterdomainitem":{
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"name",
"alternatives"
],
"properties": {
"name": {
"$id": "#/definitions/traefikrouterdomainitem//properties/name",
"type": "string",
"default": ""
},
"alternatives": {
"$ref": "#/definitions/uniquestringarray"
}
},
"additionalProperties": true
},
"traefikroutermiddlewareitem": {
"$id": "#/definitions/traefikroutermiddlewareitem",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"name",
"type"
],
"properties": {
"name": {
"$id": "#/definitions/traefikroutermiddlewareitem/properties/name",
"type": "string",
"default": ""
},
"type": {
"$id": "#/definitions/traefikroutermiddlewareitem/properties/type",
"type": "string",
"default": ""
},
"comment": {
"$id": "#/definitions/traefikroutermiddlewareitem/properties/comment",
"type": "string",
"default": ""
}
},
"additionalProperties": true
}
},
"properties": {
"enabled": {
"$id": "#/properties/enabled",
"type": "boolean",
"default": false
},
"name": {
"$id": "#/properties/name",
"type": "string",
"default": ""
},
"registry": {
"$id": "#/properties/registry",
"type": "string",
"default": ""
},
"imageName": {
"$id": "#/properties/imageName",
"type": "string",
"default": ""
},
"tag": {
"$id": "#/properties/tag",
"type": "string",
"default": ""
},
"restart": {
"$id": "#/properties/restart",
"type": "string",
"default": "always"
},
"watchtower": {
"$id": "#/properties/watchtower",
"type": "boolean",
"default": false
},
"build": {
"$id": "#/properties/build",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"enabled",
"generate",
"context",
"dockerfile"
],
"properties": {
"enabled": {
"$id": "#/properties/build/properties/enabled",
"type": "boolean",
"default": false
},
"generate": {
"$id": "#/properties/build/properties/generate",
"type": "boolean",
"default": false
},
"context": {
"$id": "#/properties/build/properties/context",
"type": "string",
"default": ""
},
"dockerfile": {
"$id": "#/properties/build/properties/dockerfile",
"type": "string",
"default": ""
},
"args": {
"$ref": "#/definitions/uniquevariablearray"
},
"environment": {
"$ref": "#/definitions/uniquevariablearray"
},
"volumes": {
"$ref": "#/definitions/uniquestringarray"
},
"copycmd": {
"$id": "#/properties/build/properties/copycmd",
"type": "array",
"default": [],
"mergeStrategy": "append",
"additionalItems": true,
"items": {
"$id": "#/properties/build/properties/copycmd/items",
"anyOf": [
{
"$ref": "#/definitions/hostcontaineritem"
}
]
}
},
"commands": {
"$id": "#/properties/build/properties/commands",
"type": "array",
"default": [],
"mergeStrategy": "append",
"additionalItems": true,
"items": {
"$id": "#/properties/build/properties/commands/items",
"anyOf": [
{
"$id": "#/properties/build/properties/commands/items/anyOf/0",
"type": "string",
"default": ""
}
]
}
},
"runcmd": {
"$id": "#/properties/build/properties/runcmd",
"type": "array",
"default": [],
"mergeStrategy": "append",
"additionalItems": true,
"items": {
"$id": "#/properties/build/properties/runcmd/items",
"anyOf": [
{
"$id": "#/properties/build/properties/runcmd/items/anyOf/0",
"type": "string",
"default": ""
}
]
}
}
},
"additionalProperties": true
},
"environment": {
"$ref": "#/definitions/uniquevariablearray"
},
"volumes": {
"$ref": "#/definitions/uniquehostcontainerarray"
},
"hostNames": {
"$id": "#/properties/hostNames",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
],
"properties": {
"host": {
"$ref": "#/definitions/uniquevariablearray"
},
"container": {
"$ref": "#/definitions/uniquevariablearray"
}
}
},
"networks": {
"$id": "#/properties/networks",
"type": "array",
"default": [],
"mergeStrategy": "arrayMergeById",
"mergeOptions": { "idRef": "name" },
"additionalItems": true,
"items": {
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"name"
],
"properties": {
"name": {
"$id": "#/definitions/networkitem/properties/name",
"type": "string",
"default": ""
},
"mode": {
"$id": "#/definitions/networkitem/properties/mode",
"type": "string",
"default": ""
},
"comment": {
"$id": "#/definitions/networkitem/properties/comment",
"type": "string",
"default": ""
}
},
"additionalProperties": true
}
},
"ports": {
"$ref": "#/definitions/uniquehostcontainerarray"
},
"labels": {
"$ref": "#/definitions/uniquevariablearray"
},
"traefik": {
"$ref": "#/definitions/traefik"
},
"logging": {
"$id": "#/properties/logging",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"driver",
"options"
],
"properties": {
"driver": {
"$id": "#/properties/logging/properties/driver",
"type": "string",
"default": ""
},
"options": {
"$id": "#/properties/logging/properties/options",
"type": "object",
"default": {},
"mergeStrategy": "objectMerge",
"required": [
"maxsize",
"maxfiles"
],
"properties": {
"maxsize": {
"$id": "#/properties/logging/properties/options/properties/maxsize",
"type": "string",
"default": ""
},
"maxfiles": {
"$id": "#/properties/logging/properties/options/properties/maxfiles",
"type": "string",
"default": ""
}
},
"additionalProperties": true
}
},
"additionalProperties": true
},
"templates": {
"$ref": "#/definitions/uniquestringarray"
},
"comment": {
"$id": "#/properties/comment",
"type": "string",
"default": ""
}
},
"additionalProperties": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment