Skip to content

Commit cecab8d

Browse files
committed
exporter/image/exptypes: Make strongly typed
Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 4fc2d7b commit cecab8d

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

control/control.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*
332332

333333
// if SOURCE_DATE_EPOCH is set, enable it for the exporter
334334
if v, ok := epoch.ParseBuildArgs(req.FrontendAttrs); ok {
335-
if _, ok := req.ExporterAttrs[exptypes.OptKeySourceDateEpoch]; !ok {
335+
if _, ok := req.ExporterAttrs[string(exptypes.OptKeySourceDateEpoch)]; !ok {
336336
if req.ExporterAttrs == nil {
337337
req.ExporterAttrs = make(map[string]string)
338338
}
339-
req.ExporterAttrs[exptypes.OptKeySourceDateEpoch] = v
339+
req.ExporterAttrs[string(exptypes.OptKeySourceDateEpoch)] = v
340340
}
341341
}
342342

exporter/containerimage/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
7979
}
8080

8181
for k, v := range opt {
82-
switch k {
82+
switch exptypes.ImageExporterOptKey(k) {
8383
case exptypes.OptKeyPush:
8484
if v == "" {
8585
i.push = true
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,73 @@
11
package exptypes
22

3+
type ImageExporterOptKey string
4+
35
// Options keys supported by the image exporter output.
46
var (
57
// Name of the image.
68
// Value: string
7-
OptKeyName = "name"
9+
OptKeyName ImageExporterOptKey = "name"
810

911
// Push after creating image.
1012
// Value: bool <true|false>
11-
OptKeyPush = "push"
13+
OptKeyPush ImageExporterOptKey = "push"
1214

1315
// Push unnamed image.
1416
// Value: bool <true|false>
15-
OptKeyPushByDigest = "push-by-digest"
17+
OptKeyPushByDigest ImageExporterOptKey = "push-by-digest"
1618

1719
// Allow pushing to insecure HTTP registry.
1820
// Value: bool <true|false>
19-
OptKeyInsecure = "registry.insecure"
21+
OptKeyInsecure ImageExporterOptKey = "registry.insecure"
2022

2123
// Unpack image after it's created (containerd).
2224
// Value: bool <true|false>
23-
OptKeyUnpack = "unpack"
25+
OptKeyUnpack ImageExporterOptKey = "unpack"
2426

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

3032
// Creates additional image name with format <name>@<digest>
3133
// Value: bool <true|false>
32-
OptKeyNameCanonical = "name-canonical"
34+
OptKeyNameCanonical ImageExporterOptKey = "name-canonical"
3335

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

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

4345
// Force attestation to be attached.
4446
// Value: bool <true|false>
45-
OptKeyForceInlineAttestations = "attestation-inline"
47+
OptKeyForceInlineAttestations ImageExporterOptKey = "attestation-inline"
4648

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

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

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

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

6769
// Compression level
6870
// Value: int (0-9) for gzip and estargz
6971
// Value: int (0-22) for zstd
70-
OptKeyCompressionLevel = "compression-level"
72+
OptKeyCompressionLevel ImageExporterOptKey = "compression-level"
7173
)

exporter/containerimage/opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (c *ImageCommitOpts) Load(ctx context.Context, opt map[string]string) (map[
4343

4444
for k, v := range opt {
4545
var err error
46-
switch k {
46+
switch exptypes.ImageExporterOptKey(k) {
4747
case exptypes.OptKeyName:
4848
c.ImageName = v
4949
case exptypes.OptKeyOCITypes:

exporter/util/epoch/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func ParseExporterAttrs(opt map[string]string) (*time.Time, map[string]string, e
2525

2626
for k, v := range opt {
2727
switch k {
28-
case exptypes.OptKeySourceDateEpoch:
28+
case string(exptypes.OptKeySourceDateEpoch):
2929
var err error
3030
tm, err = parseTime(k, v)
3131
if err != nil {

0 commit comments

Comments
 (0)