Skip to content

Commit

Permalink
exporter/image/exptypes: Make strongly typed
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Gronowski <[email protected]>
  • Loading branch information
vvoland committed Jun 2, 2023
1 parent 4fc2d7b commit cecab8d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*

// if SOURCE_DATE_EPOCH is set, enable it for the exporter
if v, ok := epoch.ParseBuildArgs(req.FrontendAttrs); ok {
if _, ok := req.ExporterAttrs[exptypes.OptKeySourceDateEpoch]; !ok {
if _, ok := req.ExporterAttrs[string(exptypes.OptKeySourceDateEpoch)]; !ok {
if req.ExporterAttrs == nil {
req.ExporterAttrs = make(map[string]string)
}
req.ExporterAttrs[exptypes.OptKeySourceDateEpoch] = v
req.ExporterAttrs[string(exptypes.OptKeySourceDateEpoch)] = v
}
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/containerimage/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
}

for k, v := range opt {
switch k {
switch exptypes.ImageExporterOptKey(k) {
case exptypes.OptKeyPush:
if v == "" {
i.push = true
Expand Down
32 changes: 17 additions & 15 deletions exporter/containerimage/exptypes/keys.go
Original file line number Diff line number Diff line change
@@ -1,71 +1,73 @@
package exptypes

type ImageExporterOptKey string

// Options keys supported by the image exporter output.
var (
// Name of the image.
// Value: string
OptKeyName = "name"
OptKeyName ImageExporterOptKey = "name"

// Push after creating image.
// Value: bool <true|false>
OptKeyPush = "push"
OptKeyPush ImageExporterOptKey = "push"

// Push unnamed image.
// Value: bool <true|false>
OptKeyPushByDigest = "push-by-digest"
OptKeyPushByDigest ImageExporterOptKey = "push-by-digest"

// Allow pushing to insecure HTTP registry.
// Value: bool <true|false>
OptKeyInsecure = "registry.insecure"
OptKeyInsecure ImageExporterOptKey = "registry.insecure"

// Unpack image after it's created (containerd).
// Value: bool <true|false>
OptKeyUnpack = "unpack"
OptKeyUnpack ImageExporterOptKey = "unpack"

// Fallback image name prefix if image name isn't provided.
// If used, image will be named as <value>@<digest>
// Value: string
OptKeyDanglingPrefix = "dangling-name-prefix"
OptKeyDanglingPrefix ImageExporterOptKey = "dangling-name-prefix"

// Creates additional image name with format <name>@<digest>
// Value: bool <true|false>
OptKeyNameCanonical = "name-canonical"
OptKeyNameCanonical ImageExporterOptKey = "name-canonical"

// Store the resulting image along with all of the content it references.
// Ignored if the worker doesn't have image store (e.g. OCI worker).
// Value: bool <true|false>
OptKeyStore = "store"
OptKeyStore ImageExporterOptKey = "store"

// Use OCI mediatypes instead of Docker in JSON configs.
// Value: bool <true|false>
OptKeyOCITypes = "oci-mediatypes"
OptKeyOCITypes ImageExporterOptKey = "oci-mediatypes"

// Force attestation to be attached.
// Value: bool <true|false>
OptKeyForceInlineAttestations = "attestation-inline"
OptKeyForceInlineAttestations ImageExporterOptKey = "attestation-inline"

// Mark layers as non-distributable if they are found to use a
// non-distributable media type. When this option is not set, the exporter
// will change the media type of the layer to a distributable one.
// Value: bool <true|false>
OptKeyPreferNondistLayers = "prefer-nondist-layers"
OptKeyPreferNondistLayers ImageExporterOptKey = "prefer-nondist-layers"

// Clamp produced timestamps. For more information see the
// SOURCE_DATE_EPOCH specification.
// Value: int (number of seconds since Unix epoch)
OptKeySourceDateEpoch = "source-date-epoch"
OptKeySourceDateEpoch ImageExporterOptKey = "source-date-epoch"

// Compression type for newly created and cached layers.
// estargz should be used with OptKeyOCITypes set to true.
// Value: string <uncompressed|gzip|estargz|zstd>
OptKeyLayerCompression = "compression"
OptKeyLayerCompression ImageExporterOptKey = "compression"

// Force compression on all (including existing) layers.
// Value: bool <true|false>
OptKeyForceCompression = "force-compression"
OptKeyForceCompression ImageExporterOptKey = "force-compression"

// Compression level
// Value: int (0-9) for gzip and estargz
// Value: int (0-22) for zstd
OptKeyCompressionLevel = "compression-level"
OptKeyCompressionLevel ImageExporterOptKey = "compression-level"
)
2 changes: 1 addition & 1 deletion exporter/containerimage/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *ImageCommitOpts) Load(ctx context.Context, opt map[string]string) (map[

for k, v := range opt {
var err error
switch k {
switch exptypes.ImageExporterOptKey(k) {
case exptypes.OptKeyName:
c.ImageName = v
case exptypes.OptKeyOCITypes:
Expand Down
2 changes: 1 addition & 1 deletion exporter/util/epoch/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ParseExporterAttrs(opt map[string]string) (*time.Time, map[string]string, e

for k, v := range opt {
switch k {
case exptypes.OptKeySourceDateEpoch:
case string(exptypes.OptKeySourceDateEpoch):
var err error
tm, err = parseTime(k, v)
if err != nil {
Expand Down

0 comments on commit cecab8d

Please sign in to comment.