Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json schema for image manifest and manifest list #18

Merged
merged 3 commits into from
Apr 14, 2016
Merged
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
15 changes: 15 additions & 0 deletions schema/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

default: help

help:
@echo "Usage: make <target>"
@echo
@echo " * 'fmt' - format the json with indentation"
@echo " * 'validate' - build the validation tool"

fmt:
for i in *.json ; do jq --indent 2 -M . "$${i}" > xx && cat xx > "$${i}" && rm xx ; done

validate: validate.go
go build ./validate.go

99 changes: 99 additions & 0 deletions schema/defs-image.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"description": "Definitions particular to OpenContainer Image Specification",
"definitions": {
"mediaType": {
"id": "https://opencontainers.org/schema/image/mediaType",
"type": "string",
"pattern": "^[a-z]+/[0-9a-zA-Z.+]+$"
},
"digest": {
"description": "the cryptographic checksum digest of the object, in the pattern '<hash>:<hexadecimal digest>'",
"type": "string",
"pattern": "^[a-z0-9]+:[a-fA-F0-9]+$"
},
"blobObject": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually called a "Descriptor".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is that defined?

On Fri, Apr 15, 2016 at 1:07 PM Stephen Day notifications@github.com
wrote:

In schema/defs-image.json
#18 (comment)
:

@@ -0,0 +1,99 @@
+{

  • "description": "Definitions particular to OpenContainer Image Specification",
  • "definitions": {
  • "mediaType": {
  •  "id": "https://opencontainers.org/schema/image/mediaType",
    
  •  "type": "string",
    
  •  "pattern": "^[a-z]+/[0-9a-zA-Z.+]+$"
    
  • },
  • "digest": {
  •  "description": "the cryptographic checksum digest of the object, in the pattern '<hash>:<hexadecimal digest>'",
    
  •  "type": "string",
    
  •  "pattern": "^[a-z0-9]+:[a-fA-F0-9]+$"
    
  • },
  • "blobObject": {

This is actually called a "Descriptor".


You are receiving this because you modified the open/close state.

Reply to this email directly or view it on GitHub
/~https://github.com/opencontainers/image-spec/pull/18/files/64b5003c9985ba8714201f1ecc01460770ab5828#r59933563

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what we have called it from the start. The godoc is here. I am not sure how it never made into this specification.

Other types with further fields, such as the manifest descriptor, are extensions to the descriptor type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah fine. A name of a struct. Feel free to open a PR to include this in the
spec. I can update it here.

On Fri, Apr 15, 2016 at 1:27 PM Stephen Day notifications@github.com
wrote:

In schema/defs-image.json
#18 (comment)
:

@@ -0,0 +1,99 @@
+{

  • "description": "Definitions particular to OpenContainer Image Specification",
  • "definitions": {
  • "mediaType": {
  •  "id": "https://opencontainers.org/schema/image/mediaType",
    
  •  "type": "string",
    
  •  "pattern": "^[a-z]+/[0-9a-zA-Z.+]+$"
    
  • },
  • "digest": {
  •  "description": "the cryptographic checksum digest of the object, in the pattern '<hash>:<hexadecimal digest>'",
    
  •  "type": "string",
    
  •  "pattern": "^[a-z0-9]+:[a-fA-F0-9]+$"
    
  • },
  • "blobObject": {

This is what we have called it from the start. The godoc is here
https://godoc.org/github.com/docker/distribution#Descriptor. I am not
sure how it never made into this specification.

Other types with further fields, such as the manifest descriptor, are
extensions to the descriptor type.


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
/~https://github.com/opencontainers/image-spec/pull/18/files/64b5003c9985ba8714201f1ecc01460770ab5828#r59936055

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I'll do that. Just reviewing old notifications.

"id": "https://opencontainers.org/schema/image/blobObject",
"type": "object",
"required": [
"mediaType",
"size",
"digest"
],
"properties": {
"mediaType": {
"description": "the mediatype of the referenced object",
"$ref": "#definitions/mediaType"
},
"size": {
"description": "the size in bytes of the referenced object",
"type": "integer"
},
"digest": {
"$ref": "#definitions/digest"
}
}
},
"manifestObject": {
"id": "https://opencontainers.org/schema/image/manifestObject",
"type": "object",
"required": [
"mediaType",
"size",
"digest",
"platform"
],
"properties": {
"mediaType": {
"description": "the mediatype of the referenced object",
"$ref": "#definitions/mediaType"
},
"size": {
"description": "the size in bytes of the referenced object",
"type": "integer"
},
"digest": {
"$ref": "#definitions/digest"
},
"platform": {
"id": "https://opencontainers.org/schema/image/platform",
"type": "object",
"required": [
"architecture",
"os"
],
"properties": {
"architecture": {
"id": "https://opencontainers.org/schema/image/platform/architecture",
"type": "string"
},
"os": {
"id": "https://opencontainers.org/schema/image/platform/os",
"type": "string"
},
"os.version": {
"id": "https://opencontainers.org/schema/image/platform/os.version",
"type": "string"
},
"os.features": {
"id": "https://opencontainers.org/schema/image/platform/os.features",
"type": "array",
"items": {
"type": "string"
}
},
"variant": {
"type": "string"
},
"features": {
"type": "array",
"items": {
"type": "string"
},
"additionalProperties": false
}
}
}
}
}
}
}
160 changes: 160 additions & 0 deletions schema/defs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"description": "Definitions used throughout the OpenContainer Specification",
"definitions": {
"int8": {
"type": "integer",
"minimum": -128,
"maximum": 127
},
"int16": {
"type": "integer",
"minimum": -32768,
"maximum": 32767
},
"int32": {
"type": "integer",
"minimum": -2147483648,
"maximum": 2147483647
},
"int64": {
"type": "integer",
"minimum": -9223372036854776000,
"maximum": 9223372036854776000
},
"uint8": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"uint16": {
"type": "integer",
"minimum": 0,
"maximum": 65535
},
"uint32": {
"type": "integer",
"minimum": 0,
"maximum": 4294967295
},
"uint64": {
"type": "integer",
"minimum": 0,
"maximum": 18446744073709552000
},
"uint16Pointer": {
"oneOf": [
{
"$ref": "#/definitions/uint16"
},
{
"type": "null"
}
]
},
"uint64Pointer": {
"oneOf": [
{
"$ref": "#/definitions/uint64"
},
{
"type": "null"
}
]
},
"stringPointer": {
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"mapStringString": {
"type": "object",
"patternProperties": {
".{1,}": {
"type": "string"
}
}
},
"UID": {
"$ref": "#/definitions/uint32"
},
"GID": {
"$ref": "#/definitions/uint32"
},
"ArrayOfGIDs": {
"type": "array",
"items": {
"$ref": "#/definitions/GID"
}
},
"ArrayOfStrings": {
"type": "array",
"items": {
"type": "string"
}
},
"FilePath": {
"type": "string"
},
"Env": {
"$ref": "#/definitions/ArrayOfStrings"
},
"Hook": {
"properties": {
"path": {
"$ref": "#/definitions/FilePath"
},
"args": {
"$ref": "#/definitions/ArrayOfStrings"
},
"env": {
"$ref": "#/definitions/Env"
}
}
},
"ArrayOfHooks": {
"type": "array",
"items": {
"$ref": "#/definitions/Hook"
}
},
"IDMapping": {
"properties": {
"hostID": {
"$ref": "#/definitions/uint32"
},
"containerID": {
"$ref": "#/definitions/uint32"
},
"size": {
"$ref": "#/definitions/uint32"
}
}
},
"Mount": {
"properties": {
"source": {
"$ref": "#/definitions/FilePath"
},
"destination": {
"$ref": "#/definitions/FilePath"
},
"options": {
"$ref": "#/definitions/ArrayOfStrings"
},
"type": {
"type": "string"
}
},
"required": [
"destination",
"source",
"type"
]
}
}
}
43 changes: 43 additions & 0 deletions schema/image-manifest-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"description": "OpenContainer Image Manifest Specification",
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "https://opencontainers.org/schema/image/manifest",
"type": "object",
"properties": {
"schemaVersion": {
"description": "This field specifies the image manifest schema version as an integer",
"id": "https://opencontainers.org/schema/image/manifest/schemaVersion",
"type": "integer"
},
"mediaType": {
"id": "https://opencontainers.org/schema/image/manifest/mediaType",
"$ref": "defs-image.json#/definitions/mediaType"
},
"config": {
"$ref": "defs-image.json#/definitions/blobObject"
},
"layers": {
"type": "array",
"items": {
"$ref": "defs-image.json#/definitions/blobObject"
}
},
"annotations": {
"id": "https://opencontainers.org/schema/image/manifest/annotations",
"oneOf": [
{
"$ref": "defs.json#/definitions/mapStringString"
},
{
"type": "null"
}
]
}
},
"required": [
"schemaVersion",
"mediaType",
"config",
"layers"
]
}
45 changes: 45 additions & 0 deletions schema/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"fmt"
"os"
"path/filepath"

"github.com/xeipuuv/gojsonschema"
)

func main() {
if len(os.Args[1:]) != 2 {
fmt.Printf("ERROR: usage is: %s <schema.json> <config.json>", os.Args[0])
os.Exit(1)
}

schemaPath, err := filepath.Abs(os.Args[1])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
documentPath, err := filepath.Abs(os.Args[2])
if err != nil {
fmt.Println(err)
os.Exit(1)
}

schemaLoader := gojsonschema.NewReferenceLoader("file://" + schemaPath)
documentLoader := gojsonschema.NewReferenceLoader("file://" + documentPath)

result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
panic(err.Error())
}

if result.Valid() {
fmt.Printf("The document is valid\n")
} else {
fmt.Printf("The document is not valid. see errors :\n")
for _, desc := range result.Errors() {
fmt.Printf("- %s\n", desc)
}
os.Exit(1)
}
}