github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/packages/container/oci/oci.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 package oci 7 8 import ( 9 "time" 10 ) 11 12 // https://github.com/opencontainers/image-spec/tree/main/specs-go/v1 13 14 // ImageConfig defines the execution parameters which should be used as a base when running a container using an image. 15 type ImageConfig struct { 16 // User defines the username or UID which the process in the container should run as. 17 User string `json:"User,omitempty"` 18 19 // ExposedPorts a set of ports to expose from a container running this image. 20 ExposedPorts map[string]struct{} `json:"ExposedPorts,omitempty"` 21 22 // Env is a list of environment variables to be used in a container. 23 Env []string `json:"Env,omitempty"` 24 25 // Entrypoint defines a list of arguments to use as the command to execute when the container starts. 26 Entrypoint []string `json:"Entrypoint,omitempty"` 27 28 // Cmd defines the default arguments to the entrypoint of the container. 29 Cmd []string `json:"Cmd,omitempty"` 30 31 // Volumes is a set of directories describing where the process is likely write data specific to a container instance. 32 Volumes map[string]struct{} `json:"Volumes,omitempty"` 33 34 // WorkingDir sets the current working directory of the entrypoint process in the container. 35 WorkingDir string `json:"WorkingDir,omitempty"` 36 37 // Labels contains arbitrary metadata for the container. 38 Labels map[string]string `json:"Labels,omitempty"` 39 40 // StopSignal contains the system call signal that will be sent to the container to exit. 41 StopSignal string `json:"StopSignal,omitempty"` 42 } 43 44 // RootFS describes a layer content addresses 45 type RootFS struct { 46 // Type is the type of the rootfs. 47 Type string `json:"type"` 48 49 // DiffIDs is an array of layer content hashes, in order from bottom-most to top-most. 50 DiffIDs []string `json:"diff_ids"` 51 } 52 53 // History describes the history of a layer. 54 type History struct { 55 // Created is the combined date and time at which the layer was created, formatted as defined by RFC 3339, section 5.6. 56 Created *time.Time `json:"created,omitempty"` 57 58 // CreatedBy is the command which created the layer. 59 CreatedBy string `json:"created_by,omitempty"` 60 61 // Author is the author of the build point. 62 Author string `json:"author,omitempty"` 63 64 // Comment is a custom message set when creating the layer. 65 Comment string `json:"comment,omitempty"` 66 67 // EmptyLayer is used to mark if the history item created a filesystem diff. 68 EmptyLayer bool `json:"empty_layer,omitempty"` 69 } 70 71 // Image is the JSON structure which describes some basic information about the image. 72 // This provides the `application/vnd.oci.image.config.v1+json` mediatype when marshalled to JSON. 73 type Image struct { 74 // Created is the combined date and time at which the image was created, formatted as defined by RFC 3339, section 5.6. 75 Created *time.Time `json:"created,omitempty"` 76 77 // Author defines the name and/or email address of the person or entity which created and is responsible for maintaining the image. 78 Author string `json:"author,omitempty"` 79 80 // Architecture is the CPU architecture which the binaries in this image are built to run on. 81 Architecture string `json:"architecture"` 82 83 // Variant is the variant of the specified CPU architecture which image binaries are intended to run on. 84 Variant string `json:"variant,omitempty"` 85 86 // OS is the name of the operating system which the image is built to run on. 87 OS string `json:"os"` 88 89 // OSVersion is an optional field specifying the operating system 90 // version, for example on Windows `10.0.14393.1066`. 91 OSVersion string `json:"os.version,omitempty"` 92 93 // OSFeatures is an optional field specifying an array of strings, 94 // each listing a required OS feature (for example on Windows `win32k`). 95 OSFeatures []string `json:"os.features,omitempty"` 96 97 // Config defines the execution parameters which should be used as a base when running a container using the image. 98 Config ImageConfig `json:"config,omitempty"` 99 100 // RootFS references the layer content addresses used by the image. 101 RootFS RootFS `json:"rootfs"` 102 103 // History describes the history of each layer. 104 History []History `json:"history,omitempty"` 105 } 106 107 // Descriptor describes the disposition of targeted content. 108 // This structure provides `application/vnd.oci.descriptor.v1+json` mediatype 109 // when marshalled to JSON. 110 type Descriptor struct { 111 // MediaType is the media type of the object this schema refers to. 112 MediaType MediaType `json:"mediaType,omitempty"` 113 114 // Digest is the digest of the targeted content. 115 Digest Digest `json:"digest"` 116 117 // Size specifies the size in bytes of the blob. 118 Size int64 `json:"size"` 119 120 // URLs specifies a list of URLs from which this object MAY be downloaded 121 URLs []string `json:"urls,omitempty"` 122 123 // Annotations contains arbitrary metadata relating to the targeted content. 124 Annotations map[string]string `json:"annotations,omitempty"` 125 126 // Data is an embedding of the targeted content. This is encoded as a base64 127 // string when marshalled to JSON (automatically, by encoding/json). If 128 // present, Data can be used directly to avoid fetching the targeted content. 129 Data []byte `json:"data,omitempty"` 130 131 // Platform describes the platform which the image in the manifest runs on. 132 // 133 // This should only be used when referring to a manifest. 134 Platform *Platform `json:"platform,omitempty"` 135 } 136 137 // Platform describes the platform which the image in the manifest runs on. 138 type Platform struct { 139 // Architecture field specifies the CPU architecture, for example 140 // `amd64` or `ppc64`. 141 Architecture string `json:"architecture"` 142 143 // OS specifies the operating system, for example `linux` or `windows`. 144 OS string `json:"os"` 145 146 // OSVersion is an optional field specifying the operating system 147 // version, for example on Windows `10.0.14393.1066`. 148 OSVersion string `json:"os.version,omitempty"` 149 150 // OSFeatures is an optional field specifying an array of strings, 151 // each listing a required OS feature (for example on Windows `win32k`). 152 OSFeatures []string `json:"os.features,omitempty"` 153 154 // Variant is an optional field specifying a variant of the CPU, for 155 // example `v7` to specify ARMv7 when architecture is `arm`. 156 Variant string `json:"variant,omitempty"` 157 } 158 159 type SchemaMediaBase struct { 160 // SchemaVersion is the image manifest schema that this image follows 161 SchemaVersion int `json:"schemaVersion"` 162 163 // MediaType specifies the type of this document data structure e.g. `application/vnd.oci.image.manifest.v1+json` 164 MediaType MediaType `json:"mediaType,omitempty"` 165 } 166 167 // Manifest provides `application/vnd.oci.image.manifest.v1+json` mediatype structure when marshalled to JSON. 168 type Manifest struct { 169 SchemaMediaBase 170 171 // Config references a configuration object for a container, by digest. 172 // The referenced configuration object is a JSON blob that the runtime uses to set up the container. 173 Config Descriptor `json:"config"` 174 175 // Layers is an indexed list of layers referenced by the manifest. 176 Layers []Descriptor `json:"layers"` 177 178 // Annotations contains arbitrary metadata for the image manifest. 179 Annotations map[string]string `json:"annotations,omitempty"` 180 } 181 182 // Index references manifests for various platforms. 183 // This structure provides `application/vnd.oci.image.index.v1+json` mediatype when marshalled to JSON. 184 type Index struct { 185 SchemaMediaBase 186 187 // Manifests references platform specific manifests. 188 Manifests []Descriptor `json:"manifests"` 189 190 // Annotations contains arbitrary metadata for the image index. 191 Annotations map[string]string `json:"annotations,omitempty"` 192 }