Skip to content

Instantly share code, notes, and snippets.

@marcoceppi
Last active November 30, 2015 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoceppi/ad318d081e3b30857819 to your computer and use it in GitHub Desktop.
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…
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
includes: ['layer:basic', 'layer:django']
options:
basic:
packages:
- python-dev
- obama
django:
install-path: "/srv"
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)
PyYAML==3.11
argparse==1.2.1
functools32==3.2.3-2
jsonschema==2.5.1
wsgiref==0.1.2
@marcoceppi
Copy link
Author

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.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment