From 16f0fee92fe3c4c976d0c41176205152d3bb43af Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Thu, 16 Jun 2016 10:09:45 +0200 Subject: [PATCH 1/2] specs-go: add version types Signed-off-by: Antonio Murdaca --- specs-go/version.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 specs-go/version.go diff --git a/specs-go/version.go b/specs-go/version.go new file mode 100644 index 000000000..9827861b1 --- /dev/null +++ b/specs-go/version.go @@ -0,0 +1,18 @@ +package specs + +import "fmt" + +const ( + // VersionMajor is for an API incompatible changes + VersionMajor = 0 + // VersionMinor is for functionality in a backwards-compatible manner + VersionMinor = 3 + // VersionPatch is for backwards-compatible bug fixes + VersionPatch = 0 + + // VersionDev indicates development branch. Releases will be empty string. + VersionDev = "-dev" +) + +// Version is the specification version that the package types support. +var Version = fmt.Sprintf("%d.%d.%d%s", VersionMajor, VersionMinor, VersionPatch, VersionDev) From 4267a18d918c4d87bb7423b9f1d6ae72b9ea9e76 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Thu, 16 Jun 2016 11:04:44 +0200 Subject: [PATCH 2/2] specs-go: add v1 types Signed-off-by: Antonio Murdaca --- specs-go/descriptor.go | 27 ++++++++++ specs-go/v1/config.go | 99 ++++++++++++++++++++++++++++++++++++ specs-go/v1/manifest.go | 32 ++++++++++++ specs-go/v1/manifest_list.go | 62 ++++++++++++++++++++++ specs-go/v1/mediatype.go | 32 ++++++++++++ specs-go/version.go | 14 +++++ specs-go/versioned.go | 26 ++++++++++ 7 files changed, 292 insertions(+) create mode 100644 specs-go/descriptor.go create mode 100644 specs-go/v1/config.go create mode 100644 specs-go/v1/manifest.go create mode 100644 specs-go/v1/manifest_list.go create mode 100644 specs-go/v1/mediatype.go create mode 100644 specs-go/versioned.go diff --git a/specs-go/descriptor.go b/specs-go/descriptor.go new file mode 100644 index 000000000..34c4037b5 --- /dev/null +++ b/specs-go/descriptor.go @@ -0,0 +1,27 @@ +// Copyright 2016 The Linux Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package specs + +// Descriptor describes the disposition of targeted content. +type Descriptor struct { + // MediaType contains the MIME type of the referenced object. + MediaType string `json:"mediaType"` + + // Digests is the digest of the targeted content. + Digest string `json:"digest"` + + // Size specifies the size in bytes of the blob + Size int64 `json:"size"` +} diff --git a/specs-go/v1/config.go b/specs-go/v1/config.go new file mode 100644 index 000000000..552404de8 --- /dev/null +++ b/specs-go/v1/config.go @@ -0,0 +1,99 @@ +// Copyright 2016 The Linux Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1 + +// ImageConfig defines the execution parameters which should be used as a base when running a container using an image. +type ImageConfig struct { + // User defines the username or UID which the process in the container should run as. + User string `json:"User"` + + // Memory defines the memory limit. + Memory int64 `json:"Memory"` + + // MemorySwap defines the total memory usage limit (memory + swap). + MemorySwap int64 `json:"MemorySwap"` + + // CPUShares is the CPU shares (relative weight vs. other containers). + CPUShares int64 `json:"CpuShares"` + + // ExposedPorts a set of ports to expose from a container running this image. + ExposedPorts map[string]struct{} `json:"ExposedPorts"` + + // Env is a list of environment variables to be used in a container. + Env []string `json:"Env"` + + // Entrypoint defines a list of arguments to use as the command to execute when the container starts. + EntryPoint []string `json:"EntryPoint"` + + // Cmd defines the default arguments to the entry point of the container. + Cmd []string `json:"Cmd"` + + // Volumes is a set of directories which should be created as data volumes in a container running this image. + Volumes map[string]struct{} `json:"Volumes"` + + // WorkingDir sets the current working directory of the entry point process in the container. + WorkingDir string `json:"WorkingDir"` +} + +// RootFS describes a layer content addresses +type RootFS struct { + // Type is the type of the rootfs. + Type string `json:"type"` + + // DiffIDs is an array of layer content hashes (DiffIDs), in order from bottom-most to top-most. + DiffIDs []string `json:"diff_ids"` +} + +// History describes the history of a layer. +type History struct { + // Created is the creation time. + Created string `json:"created"` + + // CreatedBy is the command which created the layer. + CreatedBy string `json:"created_by"` + + // Author is the author of the build point. + Author string `json:"author"` + + // Comment is a custom message set when creating the layer. + Comment string `json:"comment"` + + // EmptyLayer is used to mark if the history item created a filesystem diff. + EmptyLayer bool `json:"empty_layer"` +} + +// Image is the JSON structure which describes some basic information about the image. +type Image struct { + // Created defines an ISO-8601 formatted combined date and time at which the image was created. + Created string `json:"created"` + + // Author defines the name and/or email address of the person or entity which created and is responsible for maintaining the image. + Author string `json:"author"` + + // Architecture is the CPU architecture which the binaries in this image are built to run on. + Architecture string `json:"architecture"` + + // OS is the name of the operating system which the image is built to run on. + OS string `json:"os"` + + // Config defines the execution parameters which should be used as a base when running a container using the image. + Config ImageConfig `json:"config"` + + // RootFS references the layer content addresses used by the image. + RootFS RootFS `json:"rootfs"` + + // History describes the history of each layer. + History []History `json:"history"` +} diff --git a/specs-go/v1/manifest.go b/specs-go/v1/manifest.go new file mode 100644 index 000000000..10bde0877 --- /dev/null +++ b/specs-go/v1/manifest.go @@ -0,0 +1,32 @@ +// Copyright 2016 The Linux Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1 + +import "github.com/opencontainers/image-spec/specs-go" + +// Manifest defines a schema2 manifest +type Manifest struct { + specs.Versioned + + // Config references a configuration object for a container, by digest. + // The referenced configuration object is a JSON blob that the runtime uses to set up the container. + Config specs.Descriptor `json:"config"` + + // Layers is an indexed list of layers referenced by the manifest. + Layers []specs.Descriptor `json:"layers"` + + // Annotations contains arbitrary metadata for the manifest list. + Annotations map[string]string `json:"annotations"` +} diff --git a/specs-go/v1/manifest_list.go b/specs-go/v1/manifest_list.go new file mode 100644 index 000000000..8c02ee288 --- /dev/null +++ b/specs-go/v1/manifest_list.go @@ -0,0 +1,62 @@ +// Copyright 2016 The Linux Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1 + +import "github.com/opencontainers/image-spec/specs-go" + +// Platform describes the platform which the image in the manifest runs on. +type Platform struct { + // Architecture field specifies the CPU architecture, for example + // `amd64` or `ppc64`. + Architecture string `json:"architecture"` + + // OS specifies the operating system, for example `linux` or `windows`. + OS string `json:"os"` + + // OSVersion is an optional field specifying the operating system + // version, for example `10.0.10586`. + OSVersion string `json:"os.version,omitempty"` + + // OSFeatures is an optional field specifying an array of strings, + // each listing a required OS feature (for example on Windows `win32k`). + OSFeatures []string `json:"os.features,omitempty"` + + // Variant is an optional field specifying a variant of the CPU, for + // example `ppc64le` to specify a little-endian version of a PowerPC CPU. + Variant string `json:"variant,omitempty"` + + // Features is an optional field specifying an array of strings, each + // listing a required CPU feature (for example `sse4` or `aes`). + Features []string `json:"features,omitempty"` +} + +// ManifestDescriptor describes a platform specific manifest. +type ManifestDescriptor struct { + specs.Descriptor + + // Platform describes the platform which the image in the manifest runs on. + Platform Platform `json:"platform"` +} + +// ManifestList references manifests for various platforms. +type ManifestList struct { + specs.Versioned + + // Manifests references platform specific manifests. + Manifests []ManifestDescriptor `json:"manifests"` + + // Annotations contains arbitrary metadata for the manifest list. + Annotations map[string]string `json:"annotations"` +} diff --git a/specs-go/v1/mediatype.go b/specs-go/v1/mediatype.go new file mode 100644 index 000000000..d5f128fc8 --- /dev/null +++ b/specs-go/v1/mediatype.go @@ -0,0 +1,32 @@ +// Copyright 2016 The Linux Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1 + +const ( + // MediaTypeDescriptor specifies the mediaType for a content descriptor. + MediaTypeDescriptor = "application/vnd.oci.descriptor.v1+json" + + // MediaTypeImageManifest specifies the mediaType for an image manifest. + MediaTypeImageManifest = "application/vnd.oci.image.manifest.v1+json" + + // MediaTypeImageManifestList specifies the mediaType for an image manifest list. + MediaTypeImageManifestList = "application/vnd.oci.image.manifest.list.v1+json" + + // MediaTypeImageSerialization is the mediaType used for layers referenced by the manifest. + MediaTypeImageSerialization = "application/vnd.oci.image.serialization.rootfs.tar.gzip" + + // MediaTypeImageSerializationConfig specifies the mediaType for the image configuration. + MediaTypeImageSerializationConfig = "application/vnd.oci.image.serialization.config.v1+json" +) diff --git a/specs-go/version.go b/specs-go/version.go index 9827861b1..77704299d 100644 --- a/specs-go/version.go +++ b/specs-go/version.go @@ -1,3 +1,17 @@ +// Copyright 2016 The Linux Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package specs import "fmt" diff --git a/specs-go/versioned.go b/specs-go/versioned.go new file mode 100644 index 000000000..ca0bd412c --- /dev/null +++ b/specs-go/versioned.go @@ -0,0 +1,26 @@ +// Copyright 2016 The Linux Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package specs + +// Versioned provides a struct with the manifest schemaVersion and mediaType. +// Incoming content with unknown schema version can be decoded against this +// struct to check the version. +type Versioned struct { + // SchemaVersion is the image manifest schema that this image follows + SchemaVersion int `json:"schemaVersion"` + + // MediaType is the media type of this schema. + MediaType string `json:"mediaType,omitempty"` +}