Last active
November 30, 2015 23:40
-
-
Save marcoceppi/ad318d081e3b30857819 to your computer and use it in GitHub Desktop.
Given https://gist.github.com/marcoceppi/ca36655cb917b16d0681 when charm build was run on ubucon it would produce a few artifacts. The first being a .layer.schema file which contains the namespaced schema for each layer's defines (if provided). Then layer.yaml would be the computed merge of all layer.yamls with each layer overwriting the previou…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
basic: | |
type: object | |
properties: | |
packages: | |
type: array | |
description: apt-packages to install | |
django: | |
type: object | |
properties: | |
install-path: | |
type: string | |
default: "/opt" | |
description: server install path | |
code: | |
type: string | |
default: "yarg" | |
description: source of django application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
includes: ['layer:basic', 'layer:django'] | |
options: | |
basic: | |
packages: | |
- python-dev | |
- obama | |
django: | |
install-path: "/srv" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
import jsonschema | |
with open('layer.yaml') as f: | |
layer = yaml.safe_load(f.read()) | |
with open('.layer.schema') as f: | |
schema = yaml.safe_load(f.read()) | |
options = layer.get('options', {}) | |
jsonschema.validate(options, schema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PyYAML==3.11 | |
argparse==1.2.1 | |
functools32==3.2.3-2 | |
jsonschema==2.5.1 | |
wsgiref==0.1.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given https://gist.github.com/marcoceppi/ca36655cb917b16d0681 when
charm build
was run on ubucon it would produce a few artifacts. The first being a.layer.schema
file which contains the namespaced schema for each layer'sdefines
(if provided).Then
layer.yaml
would be the computed merge of all layer.yaml files from each layer, with each layer overwriting the previous key (or merging, where applicable). Finally schema validation would be performed against the final build to let the user know if the options are all valid.Ideally reactive would provide a tool to get the option values as a command to avoid needless parsing of layer.yaml by the user.
Alternatively, instead of stacking everything in layer.yaml an options.yaml file could be created (or .options.yaml to keep safe namespacing) where the options data would be held.
Finally,
default
key is ignored in jsonschema module. The reasoning makes sense but we'll need to make a clever parser to set defaults for values not defined by an author. All the more reason to have a reactive helper for this.