Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion compose/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
import jsonschema
import os
import yaml
import six
import sys


DOCKER_CONFIG_KEYS = [
Expand Down Expand Up @@ -51,9 +54,25 @@
}


def validate_schema(config_data):
config_source_dir = os.path.dirname(os.path.abspath(__file__))
schema_file = os.path.join(config_source_dir, "schema.json")

with open(schema_file) as schema_fh:
schema = json.load(schema_fh)

try:
jsonschema.validate(config_data, schema)
except jsonschema.exceptions.ValidationError as e:
exctype, value = sys.exc_info()[:2]
raise Exception("Validation failed, reason: (%s)" % e.message)


def load(filename):
working_dir = os.path.dirname(filename)
return from_dictionary(load_yaml(filename), working_dir=working_dir, filename=filename)
config_data = load_yaml(filename)
validate_schema(config_data)
return from_dictionary(config_data, working_dir=working_dir, filename=filename)


def from_dictionary(dictionary, working_dir=None, filename=None):
Expand Down
1 change: 1 addition & 0 deletions compose/empty_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
137 changes: 137 additions & 0 deletions compose/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",

"type": "object",

"patternProperties": {
"^[a-zA-Z0-9]+$": {
"$ref": "#/definitions/service"
}
},

"additionalProperties": false,

"definitions": {
"service": {
"type": "object",
"properties": {
"build": { "type": "string" },

"image": { "type": "string" },

"command": { "$ref": "#/definitions/string_or_stringlist" },

"links": {
"$ref": "#/definitions/stringlist"
},

"external_links": {
"$ref": "#/definitions/stringlist"
},

"expose": {
"$ref": "#/definitions/stringlist"
},

"volumes": {
"$ref": "#/definitions/stringlist"
},

"volumes_from": {
"$ref": "#/definitions/stringlist"
},

"net": {
"type": "string"
},

"cap_add": {
"$ref": "#/definitions/stringlist"
},

"drop": {
"$ref": "#/definitions/stringlist"
},

"working_dir": { "type": "string" },

"entrypoint": { "type": "string" },

"user": { "type": "string" },

"hostname": { "type": "string" },

"domainname": { "type": "string" },

"mem_limit": { "type": "string" },

"privileged": { "type": "string" },

"restart": { "type": "string" },

"stdin_open": { "type": "string" },

"tty": { "type": "string" },

"cpu_shares": { "type": "string" },

"build": { "type": "string" },

"image": { "type": "string" },

"ports": {
"$ref": "#/definitions/stringlist"
},

"environment": {
"$ref": "#/definitions/dict_or_list"
},

"env_file": { "$ref": "#/definitions/string_or_stringlist" },

"dns": { "$ref": "#/definitions/string_or_stringlist" },

"dns_search": { "$ref": "#/definitions/string_or_stringlist" },

"extends": {
"type": "object",
"properties": {
"file": { "type": "string" },
"service": { "type": "string" }
},
"required": [ "file", "service" ]
}
},

"additionalProperties": false
},

"string_or_stringlist": {
"oneOf": [
{ "type": "string" },
{
"type": "array",
"items": {"type": "string"},
"uniqueItems": true
}
]
},

"stringlist": {
"type": "array",
"items": {"type": "string"},
"uniqueItems": true
},

"dict_or_list": {
"oneOf": [
{ "type": "object" },
{
"type": "array",
"items": {"type": "string"},
"uniqueItems": true
}
]
}
}
}
Empty file.
16 changes: 16 additions & 0 deletions compose/testconfig/issue117_118.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mongodb:
image: dockerfile/mongodb
ports:
- 27017:27017
- 27018:27018
volumes: /data/db:/data/db

web:
image: foo:dev
links:
- mongodb
ports:
- 3000:3000
volumes:
- ../../:/home/foo/
command: bin/webapp
11 changes: 11 additions & 0 deletions compose/testconfig/issue127.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
image: stackbrew/ubuntu
ports:
- 3306:3306
- 6379:6379
links:
- mysql
- redis
mysql:
image: orchardup/mysql
redis:
image: orchardup/redis
2 changes: 2 additions & 0 deletions compose/testconfig/top_level_not_dict.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- mysql
- redis
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ requests==2.2.1
six==1.7.3
texttable==0.8.2
websocket-client==0.11.0
jsonschema==2.4.0