From e21e6f3cd9f96b3f7aa161a6cc14e46d789318eb Mon Sep 17 00:00:00 2001 From: Josh Curl Date: Tue, 11 Oct 2016 13:27:44 -0700 Subject: [PATCH] Modify libcompose schema to support Rancher Compose specific fields --- generate.go | 3 + scripts/build | 1 + scripts/config_schema_v1.json | 205 ++++++++++++ scripts/config_schema_v2.0.json | 305 ++++++++++++++++++ scripts/inline_schema.go | 37 +++ scripts/schema_template | 5 + .../docker/libcompose/config/schema.go | 38 ++- 7 files changed, 592 insertions(+), 2 deletions(-) create mode 100644 generate.go create mode 100644 scripts/config_schema_v1.json create mode 100644 scripts/config_schema_v2.0.json create mode 100644 scripts/inline_schema.go create mode 100644 scripts/schema_template diff --git a/generate.go b/generate.go new file mode 100644 index 000000000..8458a69ab --- /dev/null +++ b/generate.go @@ -0,0 +1,3 @@ +package main + +//go:generate go run scripts/inline_schema.go diff --git a/scripts/build b/scripts/build index 9b45840b3..848ae73c4 100755 --- a/scripts/build +++ b/scripts/build @@ -11,6 +11,7 @@ OS_ARCH_ARG[linux]="amd64 arm" OS_ARCH_ARG[windows]="386 amd64" OS_ARCH_ARG[darwin]="amd64" +go generate go build -ldflags="-w -s -X main.VERSION=$VERSION" -o bin/rancher if [ -n "$CROSS" ]; then diff --git a/scripts/config_schema_v1.json b/scripts/config_schema_v1.json new file mode 100644 index 000000000..5c91b15ea --- /dev/null +++ b/scripts/config_schema_v1.json @@ -0,0 +1,205 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "config_schema_v1.json", + + "type": "object", + + "patternProperties": { + "^[a-zA-Z0-9._-]+$": { + "$ref": "#/definitions/service" + } + }, + + "additionalProperties": false, + + "definitions": { + "service": { + "id": "#/definitions/service", + "type": "object", + + "properties": { + "build": {"type": "string"}, + "cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "certs": {"$ref": "#/definitions/list_of_strings"}, + "cgroup_parent": {"type": "string"}, + "command": { + "oneOf": [ + {"type": "string"}, + {"type": "array", "items": {"type": "string"}} + ] + }, + "container_name": {"type": "string"}, + "cpu_shares": {"type": ["number", "string"]}, + "cpu_quota": {"type": ["number", "string"]}, + "cpuset": {"type": "string"}, + "device_read_iops": {"$ref": "#/definitions/list_or_dict"}, + "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "device_write_iops": {"$ref": "#/definitions/list_or_dict"}, + "default_cert": {"type": "string"}, + "disks": {"type": "array"}, + "dns": {"$ref": "#/definitions/string_or_list"}, + "dns_search": {"$ref": "#/definitions/string_or_list"}, + "dockerfile": {"type": "string"}, + "domainname": {"type": "string"}, + "entrypoint": { + "oneOf": [ + {"type": "string"}, + {"type": "array", "items": {"type": "string"}} + ] + }, + "env_file": {"$ref": "#/definitions/string_or_list"}, + "environment": {"$ref": "#/definitions/list_or_dict"}, + + "expose": { + "type": "array", + "items": { + "type": ["string", "number"], + "format": "expose" + }, + "uniqueItems": true + }, + + "extends": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "object", + + "properties": { + "service": {"type": "string"}, + "file": {"type": "string"} + }, + "required": ["service"], + "additionalProperties": false + } + ] + }, + + "extra_hosts": {"$ref": "#/definitions/list_or_dict"}, + "external_ips": {"$ref": "#/definitions/list_of_strings"}, + "external_links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "health_check": {"type": "object"}, + "hostname": {"type": "string"}, + "image": {"type": "string"}, + "ipc": {"type": "string"}, + "labels": {"$ref": "#/definitions/list_or_dict"}, + "links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "load_balancer_config": {"type": "object"}, + "log_driver": {"type": "string"}, + "log_opt": {"type": "object"}, + "mac_address": {"type": "string"}, + "memory": {"type": ["number", "string"]}, + "mem_limit": {"type": ["number", "string"]}, + "memswap_limit": {"type": ["number", "string"]}, + "mem_swappiness": {"type": "integer"}, + "metadata": {"type": "object"}, + "net": {"type": "string"}, + "pid": {"type": ["string", "null"]}, + + "ports": { + "type": "array", + "items": { + "type": ["string", "number"], + "format": "ports" + }, + "uniqueItems": true + }, + + "privileged": {"type": "boolean"}, + "read_only": {"type": "boolean"}, + "restart": {"type": "string"}, + "retain_ip": {"type": "boolean"}, + "scale": {"type": ["number", "string"]}, + "scale_policy": {"type": "object"}, + "security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "shm_size": {"type": ["number", "string"]}, + "stdin_open": {"type": "boolean"}, + "stop_signal": {"type": "string"}, + "tty": {"type": "boolean"}, + "type": {"type": "string"}, + "update_strategy": {"type": "object"}, + "ulimits": { + "type": "object", + "patternProperties": { + "^[a-z]+$": { + "oneOf": [ + {"type": "integer"}, + { + "type":"object", + "properties": { + "hard": {"type": "integer"}, + "soft": {"type": "integer"} + }, + "required": ["soft", "hard"], + "additionalProperties": false + } + ] + } + } + }, + "user": {"type": "string"}, + "userdata": {"type": "string"}, + "vcpu": {"type": ["number", "string"]}, + "volumes": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "volume_driver": {"type": "string"}, + "volumes_from": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "working_dir": {"type": "string"} + }, + + "dependencies": { + "memswap_limit": ["mem_limit"] + }, + "additionalProperties": false + }, + + "string_or_list": { + "oneOf": [ + {"type": "string"}, + {"$ref": "#/definitions/list_of_strings"} + ] + }, + + "list_of_strings": { + "type": "array", + "items": {"type": "string"}, + "uniqueItems": true + }, + + "list_or_dict": { + "oneOf": [ + { + "type": "object", + "patternProperties": { + ".+": { + "type": ["string", "number", "null", "boolean"] + } + }, + "additionalProperties": false + }, + {"type": "array", "items": {"type": "string"}, "uniqueItems": true} + ] + }, + + "constraints": { + "service": { + "id": "#/definitions/constraints/service", + "anyOf": [ + { + "required": ["build"], + "not": {"required": ["image"]} + }, + { + "required": ["image"], + "not": {"anyOf": [ + {"required": ["build"]}, + {"required": ["dockerfile"]} + ]} + } + ] + } + } + } +} diff --git a/scripts/config_schema_v2.0.json b/scripts/config_schema_v2.0.json new file mode 100644 index 000000000..07a1996b6 --- /dev/null +++ b/scripts/config_schema_v2.0.json @@ -0,0 +1,305 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "config_schema_v2.0.json", + "type": "object", + + "patternProperties": { + "^[a-zA-Z0-9._-]+$": { + "$ref": "#/definitions/service" + } + }, + + "additionalProperties": false, + + "definitions": { + + "service": { + "id": "#/definitions/service", + "type": "object", + + "properties": { + "build": { + "oneOf": [ + {"type": "string"}, + { + "type": "object", + "properties": { + "context": {"type": "string"}, + "dockerfile": {"type": "string"}, + "args": {"$ref": "#/definitions/list_or_dict"} + }, + "additionalProperties": false + } + ] + }, + "cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "certs": {"$ref": "#/definitions/list_of_strings"}, + "cgroup_parent": {"type": "string"}, + "command": { + "oneOf": [ + {"type": "string"}, + {"type": "array", "items": {"type": "string"}} + ] + }, + "container_name": {"type": "string"}, + "cpu_shares": {"type": ["number", "string"]}, + "cpu_quota": {"type": ["number", "string"]}, + "cpuset": {"type": "string"}, + "default_cert": {"type": "string"}, + "depends_on": {"$ref": "#/definitions/list_of_strings"}, + "device_read_iops": {"$ref": "#/definitions/list_or_dict"}, + "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "device_write_iops": {"$ref": "#/definitions/list_or_dict"}, + "disks": {"type": "array"}, + "dns": {"$ref": "#/definitions/string_or_list"}, + "dns_search": {"$ref": "#/definitions/string_or_list"}, + "domainname": {"type": "string"}, + "entrypoint": { + "oneOf": [ + {"type": "string"}, + {"type": "array", "items": {"type": "string"}} + ] + }, + "env_file": {"$ref": "#/definitions/string_or_list"}, + "environment": {"$ref": "#/definitions/list_or_dict"}, + + "expose": { + "type": "array", + "items": { + "type": ["string", "number"], + "format": "expose" + }, + "uniqueItems": true + }, + + "extends": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "object", + + "properties": { + "service": {"type": "string"}, + "file": {"type": "string"} + }, + "required": ["service"], + "additionalProperties": false + } + ] + }, + + "external_ips": {"$ref": "#/definitions/list_of_strings"}, + "external_links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "extra_hosts": {"$ref": "#/definitions/list_or_dict"}, + "health_check": {"type": "object"}, + "hostname": {"type": "string"}, + "image": {"type": "string"}, + "ipc": {"type": "string"}, + "labels": {"$ref": "#/definitions/list_or_dict"}, + "links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "load_balancer_config": {"type": "object"}, + + "logging": { + "type": "object", + + "properties": { + "driver": {"type": "string"}, + "options": {"type": "object"} + }, + "additionalProperties": false + }, + + "mac_address": {"type": "string"}, + "memory": {"type": ["number", "string"]}, + "mem_limit": {"type": ["number", "string"]}, + "memswap_limit": {"type": ["number", "string"]}, + "mem_swappiness": {"type": "integer"}, + "metadata": {"type": "object"}, + "network_mode": {"type": "string"}, + + "networks": { + "oneOf": [ + {"$ref": "#/definitions/list_of_strings"}, + { + "type": "object", + "patternProperties": { + "^[a-zA-Z0-9._-]+$": { + "oneOf": [ + { + "type": "object", + "properties": { + "aliases": {"$ref": "#/definitions/list_of_strings"}, + "ipv4_address": {"type": "string"}, + "ipv6_address": {"type": "string"} + }, + "additionalProperties": false + }, + {"type": "null"} + ] + } + }, + "additionalProperties": false + } + ] + }, + "oom_score_adj": {"type": "integer", "minimum": -1000, "maximum": 1000}, + "pid": {"type": ["string", "null"]}, + + "ports": { + "type": "array", + "items": { + "type": ["string", "number"], + "format": "ports" + }, + "uniqueItems": true + }, + + "privileged": {"type": "boolean"}, + "read_only": {"type": "boolean"}, + "restart": {"type": "string"}, + "retain_ip": {"type": "boolean"}, + "scale": {"type": "number"}, + "scale_policy": {"type": "object"}, + "security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "shm_size": {"type": ["number", "string"]}, + "stdin_open": {"type": "boolean"}, + "stop_signal": {"type": "string"}, + "tmpfs": {"$ref": "#/definitions/string_or_list"}, + "tty": {"type": "boolean"}, + "type": {"type": "string"}, + "update_strategy": {"type": "object"}, + "ulimits": { + "type": "object", + "patternProperties": { + "^[a-z]+$": { + "oneOf": [ + {"type": "integer"}, + { + "type":"object", + "properties": { + "hard": {"type": "integer"}, + "soft": {"type": "integer"} + }, + "required": ["soft", "hard"], + "additionalProperties": false + } + ] + } + } + }, + "user": {"type": "string"}, + "userdata": {"type": "string"}, + "vcpu": {"type": ["number", "string"]}, + "volumes": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "volume_driver": {"type": "string"}, + "volumes_from": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "working_dir": {"type": "string"} + }, + + "dependencies": { + "memswap_limit": ["mem_limit"] + }, + "additionalProperties": false + }, + + "network": { + "id": "#/definitions/network", + "type": "object", + "properties": { + "driver": {"type": "string"}, + "driver_opts": { + "type": "object", + "patternProperties": { + "^.+$": {"type": ["string", "number"]} + } + }, + "ipam": { + "type": "object", + "properties": { + "driver": {"type": "string"}, + "config": { + "type": "array" + } + }, + "additionalProperties": false + }, + "external": { + "type": ["boolean", "object"], + "properties": { + "name": {"type": "string"} + }, + "additionalProperties": false + }, + "internal": {"type": "boolean"} + }, + "additionalProperties": false + }, + + "volume": { + "id": "#/definitions/volume", + "type": ["object", "null"], + "properties": { + "driver": {"type": "string"}, + "driver_opts": { + "type": "object", + "patternProperties": { + "^.+$": {"type": ["string", "number"]} + } + }, + "external": { + "type": ["boolean", "object"], + "properties": { + "name": {"type": "string"} + } + } + }, + "additionalProperties": false + }, + + "string_or_list": { + "oneOf": [ + {"type": "string"}, + {"$ref": "#/definitions/list_of_strings"} + ] + }, + + "list_of_strings": { + "type": "array", + "items": {"type": "string"}, + "uniqueItems": true + }, + + "list_or_dict": { + "oneOf": [ + { + "type": "object", + "patternProperties": { + ".+": { + "type": ["string", "number", "null", "boolean"] + } + }, + "additionalProperties": false + }, + {"type": "array", "items": {"type": "string"}, "uniqueItems": true} + ] + }, + + "constraints": { + "service": { + "id": "#/definitions/constraints/service", + "anyOf": [ + {"required": ["build"]}, + {"required": ["image"]} + ], + "properties": { + "build": { + "required": ["context"] + } + } + } + } + } +} diff --git a/scripts/inline_schema.go b/scripts/inline_schema.go new file mode 100644 index 000000000..510f1fee3 --- /dev/null +++ b/scripts/inline_schema.go @@ -0,0 +1,37 @@ +package main + +import ( + "io/ioutil" + "os" + "text/template" +) + +func main() { + t, err := template.New("schema_template").ParseFiles("./scripts/schema_template") + if err != nil { + panic(err) + } + + schemaV1, err := ioutil.ReadFile("./scripts/config_schema_v1.json") + if err != nil { + panic(err) + } + schemaV2, err := ioutil.ReadFile("./scripts/config_schema_v2.0.json") + if err != nil { + panic(err) + } + + inlinedFile, err := os.Create("vendor/github.com/docker/libcompose/config/schema.go") + if err != nil { + panic(err) + } + + err = t.Execute(inlinedFile, map[string]string{ + "schemaV1": string(schemaV1), + "schemaV2": string(schemaV2), + }) + + if err != nil { + panic(err) + } +} diff --git a/scripts/schema_template b/scripts/schema_template new file mode 100644 index 000000000..6d7141022 --- /dev/null +++ b/scripts/schema_template @@ -0,0 +1,5 @@ +package config + +var schemaDataV1 = `{{.schemaV1}}` + +var servicesSchemaDataV2 = `{{.schemaV2}}` diff --git a/vendor/github.com/docker/libcompose/config/schema.go b/vendor/github.com/docker/libcompose/config/schema.go index bf8891293..cb993b1c6 100644 --- a/vendor/github.com/docker/libcompose/config/schema.go +++ b/vendor/github.com/docker/libcompose/config/schema.go @@ -23,6 +23,7 @@ var schemaDataV1 = `{ "build": {"type": "string"}, "cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "certs": {"$ref": "#/definitions/list_of_strings"}, "cgroup_parent": {"type": "string"}, "command": { "oneOf": [ @@ -34,7 +35,11 @@ var schemaDataV1 = `{ "cpu_shares": {"type": ["number", "string"]}, "cpu_quota": {"type": ["number", "string"]}, "cpuset": {"type": "string"}, + "device_read_iops": {"$ref": "#/definitions/list_or_dict"}, "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "device_write_iops": {"$ref": "#/definitions/list_or_dict"}, + "default_cert": {"type": "string"}, + "disks": {"type": "array"}, "dns": {"$ref": "#/definitions/string_or_list"}, "dns_search": {"$ref": "#/definitions/string_or_list"}, "dockerfile": {"type": "string"}, @@ -76,18 +81,23 @@ var schemaDataV1 = `{ }, "extra_hosts": {"$ref": "#/definitions/list_or_dict"}, + "external_ips": {"$ref": "#/definitions/list_of_strings"}, "external_links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "health_check": {"type": "object"}, "hostname": {"type": "string"}, "image": {"type": "string"}, "ipc": {"type": "string"}, "labels": {"$ref": "#/definitions/list_or_dict"}, "links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "load_balancer_config": {"type": "object"}, "log_driver": {"type": "string"}, "log_opt": {"type": "object"}, "mac_address": {"type": "string"}, + "memory": {"type": ["number", "string"]}, "mem_limit": {"type": ["number", "string"]}, "memswap_limit": {"type": ["number", "string"]}, "mem_swappiness": {"type": "integer"}, + "metadata": {"type": "object"}, "net": {"type": "string"}, "pid": {"type": ["string", "null"]}, @@ -103,11 +113,16 @@ var schemaDataV1 = `{ "privileged": {"type": "boolean"}, "read_only": {"type": "boolean"}, "restart": {"type": "string"}, + "retain_ip": {"type": "boolean"}, + "scale": {"type": ["number", "string"]}, + "scale_policy": {"type": "object"}, "security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "shm_size": {"type": ["number", "string"]}, "stdin_open": {"type": "boolean"}, "stop_signal": {"type": "string"}, "tty": {"type": "boolean"}, + "type": {"type": "string"}, + "update_strategy": {"type": "object"}, "ulimits": { "type": "object", "patternProperties": { @@ -128,6 +143,8 @@ var schemaDataV1 = `{ } }, "user": {"type": "string"}, + "userdata": {"type": "string"}, + "vcpu": {"type": ["number", "string"]}, "volumes": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "volume_driver": {"type": "string"}, "volumes_from": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, @@ -159,7 +176,7 @@ var schemaDataV1 = `{ "type": "object", "patternProperties": { ".+": { - "type": ["string", "number", "null"] + "type": ["string", "number", "null", "boolean"] } }, "additionalProperties": false @@ -226,6 +243,7 @@ var servicesSchemaDataV2 = `{ }, "cap_add": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "certs": {"$ref": "#/definitions/list_of_strings"}, "cgroup_parent": {"type": "string"}, "command": { "oneOf": [ @@ -237,8 +255,12 @@ var servicesSchemaDataV2 = `{ "cpu_shares": {"type": ["number", "string"]}, "cpu_quota": {"type": ["number", "string"]}, "cpuset": {"type": "string"}, + "default_cert": {"type": "string"}, "depends_on": {"$ref": "#/definitions/list_of_strings"}, + "device_read_iops": {"$ref": "#/definitions/list_or_dict"}, "devices": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "device_write_iops": {"$ref": "#/definitions/list_or_dict"}, + "disks": {"type": "array"}, "dns": {"$ref": "#/definitions/string_or_list"}, "dns_search": {"$ref": "#/definitions/string_or_list"}, "domainname": {"type": "string"}, @@ -278,13 +300,16 @@ var servicesSchemaDataV2 = `{ ] }, + "external_ips": {"$ref": "#/definitions/list_of_strings"}, "external_links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "extra_hosts": {"$ref": "#/definitions/list_or_dict"}, + "health_check": {"type": "object"}, "hostname": {"type": "string"}, "image": {"type": "string"}, "ipc": {"type": "string"}, "labels": {"$ref": "#/definitions/list_or_dict"}, "links": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, + "load_balancer_config": {"type": "object"}, "logging": { "type": "object", @@ -297,9 +322,11 @@ var servicesSchemaDataV2 = `{ }, "mac_address": {"type": "string"}, + "memory": {"type": ["number", "string"]}, "mem_limit": {"type": ["number", "string"]}, "memswap_limit": {"type": ["number", "string"]}, "mem_swappiness": {"type": "integer"}, + "metadata": {"type": "object"}, "network_mode": {"type": "string"}, "networks": { @@ -342,12 +369,17 @@ var servicesSchemaDataV2 = `{ "privileged": {"type": "boolean"}, "read_only": {"type": "boolean"}, "restart": {"type": "string"}, + "retain_ip": {"type": "boolean"}, + "scale": {"type": "number"}, + "scale_policy": {"type": "object"}, "security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "shm_size": {"type": ["number", "string"]}, "stdin_open": {"type": "boolean"}, "stop_signal": {"type": "string"}, "tmpfs": {"$ref": "#/definitions/string_or_list"}, "tty": {"type": "boolean"}, + "type": {"type": "string"}, + "update_strategy": {"type": "object"}, "ulimits": { "type": "object", "patternProperties": { @@ -368,6 +400,8 @@ var servicesSchemaDataV2 = `{ } }, "user": {"type": "string"}, + "userdata": {"type": "string"}, + "vcpu": {"type": ["number", "string"]}, "volumes": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "volume_driver": {"type": "string"}, "volumes_from": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, @@ -453,7 +487,7 @@ var servicesSchemaDataV2 = `{ "type": "object", "patternProperties": { ".+": { - "type": ["string", "number", "null"] + "type": ["string", "number", "null", "boolean"] } }, "additionalProperties": false