Skip to content

Commit

Permalink
Merge pull request #1 from supercontainers/add-ci
Browse files Browse the repository at this point in the history
ci: add schema validation and drafts
  • Loading branch information
vsoch authored Jan 22, 2024
2 parents ec45363 + f45f064 commit 6764db8
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jsonschema
50 changes: 50 additions & 0 deletions .github/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3

import sys
import os
import re
import json
import jsonschema

here = os.path.abspath(__file__)
root = os.path.dirname(os.path.dirname(here))

schema_file = os.path.join(root, "definition-schema.json")

def recursive_find(base, pattern="compspec.json"):
"""
Find all compspec.json below a root
"""
for root, _, filenames in os.walk(base):
for filename in filenames:
fullpath = os.path.join(root, filename)
if re.search(pattern, fullpath):
yield fullpath


def read_json(filename):
with open(filename, "r") as fd:
content = json.loads(fd.read())
return content


def main(root):
"""
Validate the format of WIP prototype specs.
"""
root = os.path.abspath(root)
if not os.path.exists(root):
sys.exit(f"{root} does not exist.")
specs = recursive_find(root)

schema = read_json(schema_file)
for spec_file in specs:
print(f"⭐️ Validating spec {spec_file}")
spec = read_json(spec_file)
jsonschema.validate(spec, schema=schema)


if __name__ == "__main__":
if len(sys.argv) > 1:
root = sys.argv[1]
main(root)
18 changes: 18 additions & 0 deletions .github/workflows/check-compspecs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: check compatibility specs

on:
workflow_dispatch:
pull_request: []

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Run Validation
run: |
sudo apt-get update && sudo apt-get install -y python3 python3-pip python3-setuptools wget
sudo pip3 install -r .github/requirements.txt
python3 .github/validate.py .
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a prototype repository for compatibility specifications that are being w

## JSON Schema Specifications

- [schema.json]schema.json) is used to validate the format of a json defining compatibiilty.
- [schema.json](schema.json) is used to validate the format of a json defining compatibiilty.
- [definition-schema.json](definition-schema.json) is to validate the format of the keys for each namespace (in the subdirectories here)

Both of the above are based on [Proposal C](https://github.com/opencontainers/wg-image-compatibility/pull/8) of the Image Compatibility working group, and everything is subject to change. This repository is for prototyping only.
Expand Down
14 changes: 14 additions & 0 deletions archspec/compspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compatibilities": {
"version": "0.0.0",
"io.archspec.cpu": {
"annotations": [
"family",
"model",
"target",
"vendor"
]
}
}
}

28 changes: 28 additions & 0 deletions definition-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Schema for the definitions of the known labels",
"type": "object",
"additionalProperties": false,
"properties": {
"compatibilities": {
"type": "object",
"properties": {
"version": {
"$comment": "Version of the metadata namespace",
"type": "string"
},
"patternProperties": {
"([\\w]*)": {
"annotations": {
"$comment": "Acceptable keys for a given namespace.",
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
}
}
33 changes: 33 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Schema for the definitions of the known labels",
"type": "object",
"additionalProperties": false,
"properties": {
"compatibilities": {
"type": "object",
"properties": {
"version": {
"$comment": "Version of the metadata namespace",
"type": "string"
},
"patternProperties": {
"([\\w]*)": {
"annotations": {
"$comment": "Key value pairs for a given namespace.",
"type": "array",
"items": {
"type": "object",
"patternProperties": {
"\\w[\\w-]*": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
34 changes: 34 additions & 0 deletions supercontainers/compspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compatibilities": {
"version": "0.0.0",
"org.supercontainers.mpi": {
"annotations": [
"implementation",
"portability.optimization",
"porability.mode"
]
},
"org.supercontainers.hardware.gpu": {
"annotations": [
"driver.version",
"cuda.version",
"architecture"
]
},
"org.supercontainers.communication": {
"annotations": [
"framework"
]
},
"org.supercontainers.openmpi": {
"annotations": [
"version"
]
},
"org.supercontainers.libfabric": {
"annotations": [
"abi.version"
]
}
}
}

0 comments on commit 6764db8

Please sign in to comment.