summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2015-12-07 17:26:17 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-24 23:06:07 +0000
commit48e4a7941a4c1351076a2edf23274b41b19eab19 (patch)
treefd557cd3b093604c3f87e1f672260232ed8f625b
parent3b65cfe5f6123db169c64023fa9f8dda8a51ff49 (diff)
downloadmorph-48e4a7941a4c1351076a2edf23274b41b19eab19.tar.gz
Add JSON schemas
They will be used for validating the morphologies in a future commit. These were copied from [1], with the following changes: * The field unpetrify-ref can be of type number in addition to type string * Build commands can be of type boolean in addition to type string * minItems were set for some fields of type array [1]: http://git.baserock.org/cgi-bin/cgit.cgi/baserock/baserock/definitions.git/tree/schemas Change-Id: I962188ad5774472f08b10f6dfff8aac7a106ef23
-rw-r--r--morphlib/defaults.py5
-rw-r--r--morphlib/schemas/7/chunk.json-schema116
-rw-r--r--morphlib/schemas/7/cluster.json-schema65
-rw-r--r--morphlib/schemas/7/defaults.json-schema (renamed from morphlib/schemas/defaults.json-schema)0
-rw-r--r--morphlib/schemas/7/stratum.json-schema100
-rw-r--r--morphlib/schemas/7/system.json-schema60
-rw-r--r--morphlib/util.py4
7 files changed, 346 insertions, 4 deletions
diff --git a/morphlib/defaults.py b/morphlib/defaults.py
index 85c8b711..86828baa 100644
--- a/morphlib/defaults.py
+++ b/morphlib/defaults.py
@@ -32,8 +32,9 @@ class Defaults(object):
self._build_systems = {}
self._split_rules = {}
- schema_path = os.path.join(morphlib.util.schemas_directory(),
- 'defaults.json-schema')
+ schema_path = os.path.join(
+ morphlib.util.schemas_directory(definitions_version),
+ 'defaults.json-schema')
with open(schema_path) as f:
self.schema = yaml.load(f)
diff --git a/morphlib/schemas/7/chunk.json-schema b/morphlib/schemas/7/chunk.json-schema
new file mode 100644
index 00000000..25849cd4
--- /dev/null
+++ b/morphlib/schemas/7/chunk.json-schema
@@ -0,0 +1,116 @@
+$schema: http://json-schema.org/draft-04/schema#
+id: http://git.baserock.org/cgi-bin/cgit.cgi/baserock/baserock/definitions.git/tree/schemas/chunk.json-schema
+
+description: |
+ This is a JSON-Schema description of a 'chunk' .morph file, which is part of
+ the Baserock definitions YAML representation format.
+
+ This JSON-Schema file is valid for VERSION 7 of the Baserock definitions
+ YAML serialisation format.
+
+ The Baserock definitions format is the recommended way of representing
+ Baserock definitions on disk. The actual data model is described separately.
+ See https://wiki.baserock.org/definitions for more information.
+
+ This schema is represented as YAML, so that it can be edited more easily.
+ You may need to convert to JSON if using a JSON-Schema tool that expects
+ its input to be an actual string containing data serialised as JSON.
+
+definitions:
+ # Corresponds to CommandSequence in Baserock data model.
+ command-sequence:
+ type: array
+ items: { type: [string, boolean] }
+
+ # Corresponds to DeviceNode in Baserock data model.
+ device-node:
+ type: object
+ required: [type, filename, gid, uid, major, minor, permissions]
+ properties:
+ type: { type: string }
+ filename: { type: string }
+ gid: { type: integer }
+ uid: { type: integer }
+ major: { type: integer }
+ minor: { type: integer }
+ permissions: { type: string }
+
+ # Defines one or more instances of ChunkArtifact from the Baserock data model.
+ split-rules:
+ type: array
+ items:
+ type: object
+
+ required: [artifact, include]
+ additionalProperties: false
+
+ properties:
+ artifact: {type: string}
+ include:
+ type: array
+ items:
+ type: string
+ format: regex
+
+ system-integration-commands:
+ type: object
+ patternProperties:
+ # The property name here should correspond to the name of the chunk's
+ # artifacts, probably the '-bins' artifact if you are using the normal
+ # splitting rules.
+ ^.*$:
+ type: object
+ patternProperties:
+ ^.*$:
+ $ref: "#/definitions/command-sequence"
+
+# Corresponds to Chunk in Baserock data model.
+type: object
+
+additionalProperties: false
+required: [ 'name', 'kind']
+
+properties:
+ name: { type: string }
+ kind: { enum: [ "chunk" ] }
+
+ description: { type: string }
+
+ build-system: { type: string }
+ max-jobs: { type: integer }
+
+ products:
+ $ref: "#/definitions/split-rules"
+
+ pre-configure-commands:
+ $ref: "#/definitions/command-sequence"
+ configure-commands:
+ $ref: "#/definitions/command-sequence"
+ post-configure-commands:
+ $ref: "#/definitions/command-sequence"
+ pre-build-commands:
+ $ref: "#/definitions/command-sequence"
+ build-commands:
+ $ref: "#/definitions/command-sequence"
+ post-build-commands:
+ $ref: "#/definitions/command-sequence"
+ pre-install-commands:
+ $ref: "#/definitions/command-sequence"
+ install-commands:
+ $ref: "#/definitions/command-sequence"
+ post-install-commands:
+ $ref: "#/definitions/command-sequence"
+ pre-strip-commands:
+ $ref: "#/definitions/command-sequence"
+ strip-commands:
+ $ref: "#/definitions/command-sequence"
+ post-strip-commands:
+ $ref: "#/definitions/command-sequence"
+
+ system-integration:
+ $ref: "#/definitions/system-integration-commands"
+
+ devices:
+ type: array
+ items:
+ $ref: "#/definitions/device-node"
diff --git a/morphlib/schemas/7/cluster.json-schema b/morphlib/schemas/7/cluster.json-schema
new file mode 100644
index 00000000..ea000dc8
--- /dev/null
+++ b/morphlib/schemas/7/cluster.json-schema
@@ -0,0 +1,65 @@
+$schema: http://json-schema.org/draft-04/schema#
+id: http://git.baserock.org/cgi-bin/cgit.cgi/baserock/baserock/definitions.git/tree/schemas/cluster.json-schema
+
+description:
+ This is a JSON-Schema description of a 'cluster' .morph file, which is part
+ of the Baserock definitions YAML representation format.
+
+ This JSON-Schema file is valid for VERSION 7 of the Baserock definitions
+ YAML serialisation format.
+
+ The Baserock definitions format is the recommended way of representing
+ Baserock definitions on disk. The actual data model is described separately.
+ See https://wiki.baserock.org/definitions for more information.
+
+ This schema is represented as YAML, so that it can be edited more easily.
+ You may need to convert to JSON if using a JSON-Schema tool that expects
+ its input to be an actual string containing data serialised as JSON.
+
+definitions:
+ # A reference to a System, plus one or more SystemDeployment for that system.
+ system-deployment-set:
+ type: object
+
+ required: [ 'morph', 'deploy' ]
+ additionalProperties: false
+
+ properties:
+ morph: { type: string }
+ deploy-defaults:
+ type: object
+ additionalProperties: true
+ deploy:
+ patternProperties:
+ ^.*$: { $ref: "#/definitions/system-deployment" }
+ subsystems:
+ type: array
+ items: { $ref: "#/definitions/system-deployment-set" }
+
+ # Corresponds to SystemDeployment in Baserock data model.
+ system-deployment:
+ type: object
+
+ required: [ 'type', 'location' ]
+ additionalProperties: true
+
+ properties:
+ type: { type: string }
+ location: { type: string }
+
+
+# Corresponds to Cluster in Baserock data model.
+type: object
+
+#required: [ 'name', 'kind', 'systems' ]
+additionalProperties: false
+
+properties:
+ name: { type: string }
+ kind: { enum: [ "cluster" ] }
+ description: { type: string }
+
+ systems:
+ type: array
+ items: { $ref: "#/definitions/system-deployment-set" }
+ minItems: 1
diff --git a/morphlib/schemas/defaults.json-schema b/morphlib/schemas/7/defaults.json-schema
index 2f713425..2f713425 100644
--- a/morphlib/schemas/defaults.json-schema
+++ b/morphlib/schemas/7/defaults.json-schema
diff --git a/morphlib/schemas/7/stratum.json-schema b/morphlib/schemas/7/stratum.json-schema
new file mode 100644
index 00000000..4d0b886d
--- /dev/null
+++ b/morphlib/schemas/7/stratum.json-schema
@@ -0,0 +1,100 @@
+$schema: http://json-schema.org/draft-04/schema#
+id: http://git.baserock.org/cgi-bin/cgit.cgi/baserock/baserock/definitions.git/tree/schemas/chunk.json-schema
+
+description: |
+ This is a JSON-Schema description of a 'stratum' .morph file, which is part
+ of the Baserock definitions YAML representation format.
+
+ This JSON-Schema file is valid for VERSION 7 of the Baserock definitions
+ YAML serialisation format.
+
+ The Baserock definitions format is the recommended way of representing
+ Baserock definitions on disk. The actual data model is described separately.
+ See https://wiki.baserock.org/definitions for more information.
+
+ This schema is represented as YAML, so that it can be edited more easily.
+ You may need to convert to JSON if using a JSON-Schema tool that expects
+ its input to be an actual string containing data serialised as JSON.
+
+definitions:
+ # Defines one or more instances of StratumArtifact from the Baserock data
+ # model.
+ split-rules:
+ type: array
+ items:
+ type: object
+
+ required: [artifact, include]
+ additionalProperties: false
+
+ properties:
+ artifact: {type: string}
+ include:
+ type: array
+ items:
+ type: string
+ format: regex
+
+ # Corresponds to ChunkReference in Baserock data model.
+ chunk-reference:
+ type: object
+
+ required: [ 'repo', 'ref' ]
+ additionalProperties: false
+
+ properties:
+ name: { type: string }
+ morph: { type: string }
+ repo: { type: string }
+ ref: { type: string }
+ unpetrify-ref: { type: [string, number] }
+ build-mode: { type: string }
+ prefix: { type: string }
+ build-system: { type: string }
+ build-depends:
+ type: array
+ items: { type: string }
+ artifacts:
+ type: object
+ # This defines which chunk artifacts go in which stratum artifact.
+ # E.g. "glibc-nss: build-essential-runtime" specifies the glibc-nss
+ # chunk artifact should go in the build-essential-runtime stratum
+ # artifact.
+ patternProperties:
+ ^.*$: { type: string }
+
+ # This doesn't need any special treatment in the Baserock data model because
+ # it's a link to another stratum definition, without any extra info.
+ stratum-reference:
+ type: object
+
+ required: [ 'morph' ]
+ additionalProperties: false
+
+ properties:
+ morph: { type: string }
+
+
+# Corresponds to Stratum in Baserock data model.
+type: object
+
+required: [ 'name', 'kind', 'chunks' ]
+additionalProperties: false
+
+properties:
+ name: { type: string }
+ kind: { enum: [ "stratum" ] }
+ description: { type: string }
+
+ build-depends:
+ type: array
+ items:
+ $ref: "#/definitions/stratum-reference"
+
+ products:
+ $ref: "#/definitions/split-rules"
+
+ chunks:
+ type: array
+ items: { $ref: "#/definitions/chunk-reference" }
+ minItems: 1
diff --git a/morphlib/schemas/7/system.json-schema b/morphlib/schemas/7/system.json-schema
new file mode 100644
index 00000000..189cc583
--- /dev/null
+++ b/morphlib/schemas/7/system.json-schema
@@ -0,0 +1,60 @@
+$schema: http://json-schema.org/draft-04/schema#
+id: http://git.baserock.org/cgi-bin/cgit.cgi/baserock/baserock/definitions.git/tree/schemas/system.json-schema
+
+description: |
+ This is a JSON-Schema description of a 'system' .morph file, which is part of
+ the Baserock definitions YAML representation format.
+
+ This JSON-Schema file is valid for VERSION 7 of the Baserock definitions
+ YAML serialisation format.
+
+ The Baserock definitions format is the recommended way of representing
+ Baserock definitions on disk. The actual data model is described separately.
+ See https://wiki.baserock.org/definitions for more information.
+
+ This schema is represented as YAML, so that it can be edited more easily.
+ You may need to convert to JSON if using a JSON-Schema tool that expects
+ its input to be an actual string containing data serialised as JSON.
+
+definitions:
+ # In the Baserock data model, this becomes a list of links to StratumArtifact
+ # entities.
+ stratum-reference:
+ type: object
+
+ required: [ 'morph' ]
+ additionalProperties: false
+
+ properties:
+ name: { type: string }
+ morph: { type: string }
+ artifacts:
+ type: array
+ items: { type: string }
+
+
+# Corresponds to System in Baserock data model.
+system:
+type: object
+
+required: [ 'name', 'kind', 'strata' ]
+additionalProperties: false
+
+properties:
+ name: { type: string }
+ kind: { enum: [ "system" ] }
+ description: { type: string }
+
+ # Morph and YBD will only accept certain values for 'arch' based on
+ # hardcoded conditions in those tools.
+ arch: { type: string }
+
+ strata:
+ type: array
+ items:
+ $ref: "#/definitions/stratum-reference"
+ minItems: 1
+
+ configuration-extensions:
+ type: array
+ items: { type: string }
diff --git a/morphlib/util.py b/morphlib/util.py
index ba170952..0c3291c2 100644
--- a/morphlib/util.py
+++ b/morphlib/util.py
@@ -780,7 +780,7 @@ class ProgressBar(object):
sys.stderr.flush()
-def schemas_directory(): # pragma: no cover
+def schemas_directory(version): # pragma: no cover
'''Returns a path to the schemas/ subdirectory of the 'morphlib' module.'''
code_dir = os.path.dirname(morphlib.__file__)
- return os.path.join(code_dir, 'schemas')
+ return os.path.join(code_dir, 'schemas', str(version))