Skip to content

Commit ab97675

Browse files
authored
Merge pull request moby#3694 from vvoland/containerimage-consts-public
containerimage: Export option keys
2 parents 80b91c5 + d82a803 commit ab97675

File tree

7 files changed

+110
-40
lines changed

7 files changed

+110
-40
lines changed

control/control.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/moby/buildkit/cmd/buildkitd/config"
2121
controlgateway "github.com/moby/buildkit/control/gateway"
2222
"github.com/moby/buildkit/exporter"
23+
"github.com/moby/buildkit/exporter/containerimage/exptypes"
2324
"github.com/moby/buildkit/exporter/util/epoch"
2425
"github.com/moby/buildkit/frontend"
2526
"github.com/moby/buildkit/frontend/attestations"
@@ -331,11 +332,11 @@ func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*
331332

332333
// if SOURCE_DATE_EPOCH is set, enable it for the exporter
333334
if v, ok := epoch.ParseBuildArgs(req.FrontendAttrs); ok {
334-
if _, ok := req.ExporterAttrs[epoch.KeySourceDateEpoch]; !ok {
335+
if _, ok := req.ExporterAttrs[string(exptypes.OptKeySourceDateEpoch)]; !ok {
335336
if req.ExporterAttrs == nil {
336337
req.ExporterAttrs = make(map[string]string)
337338
}
338-
req.ExporterAttrs[epoch.KeySourceDateEpoch] = v
339+
req.ExporterAttrs[string(exptypes.OptKeySourceDateEpoch)] = v
339340
}
340341
}
341342

exporter/containerimage/export.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ import (
3434
)
3535

3636
const (
37-
keyPush = "push"
38-
keyPushByDigest = "push-by-digest"
39-
keyInsecure = "registry.insecure"
40-
keyUnpack = "unpack"
41-
keyDanglingPrefix = "dangling-name-prefix"
42-
keyNameCanonical = "name-canonical"
43-
keyStore = "store"
44-
4537
// keyUnsafeInternalStoreAllowIncomplete should only be used for tests. This option allows exporting image to the image store
4638
// as well as lacking some blobs in the content store. Some integration tests for lazyref behaviour depends on this option.
4739
// Ignored when store=false.
@@ -87,8 +79,8 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
8779
}
8880

8981
for k, v := range opt {
90-
switch k {
91-
case keyPush:
82+
switch exptypes.ImageExporterOptKey(k) {
83+
case exptypes.OptKeyPush:
9284
if v == "" {
9385
i.push = true
9486
continue
@@ -98,7 +90,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
9890
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
9991
}
10092
i.push = b
101-
case keyPushByDigest:
93+
case exptypes.OptKeyPushByDigest:
10294
if v == "" {
10395
i.pushByDigest = true
10496
continue
@@ -108,7 +100,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
108100
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
109101
}
110102
i.pushByDigest = b
111-
case keyInsecure:
103+
case exptypes.OptKeyInsecure:
112104
if v == "" {
113105
i.insecure = true
114106
continue
@@ -118,7 +110,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
118110
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
119111
}
120112
i.insecure = b
121-
case keyUnpack:
113+
case exptypes.OptKeyUnpack:
122114
if v == "" {
123115
i.unpack = true
124116
continue
@@ -128,7 +120,7 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
128120
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
129121
}
130122
i.unpack = b
131-
case keyStore:
123+
case exptypes.OptKeyStore:
132124
if v == "" {
133125
i.store = true
134126
continue
@@ -148,9 +140,9 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp
148140
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
149141
}
150142
i.storeAllowIncomplete = b
151-
case keyDanglingPrefix:
143+
case exptypes.OptKeyDanglingPrefix:
152144
i.danglingPrefix = v
153-
case keyNameCanonical:
145+
case exptypes.OptKeyNameCanonical:
154146
if v == "" {
155147
i.nameCanonical = true
156148
continue
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package exptypes
2+
3+
import commonexptypes "github.com/moby/buildkit/exporter/exptypes"
4+
5+
type ImageExporterOptKey string
6+
7+
// Options keys supported by the image exporter output.
8+
var (
9+
// Name of the image.
10+
// Value: string
11+
OptKeyName ImageExporterOptKey = "name"
12+
13+
// Push after creating image.
14+
// Value: bool <true|false>
15+
OptKeyPush ImageExporterOptKey = "push"
16+
17+
// Push unnamed image.
18+
// Value: bool <true|false>
19+
OptKeyPushByDigest ImageExporterOptKey = "push-by-digest"
20+
21+
// Allow pushing to insecure HTTP registry.
22+
// Value: bool <true|false>
23+
OptKeyInsecure ImageExporterOptKey = "registry.insecure"
24+
25+
// Unpack image after it's created (containerd).
26+
// Value: bool <true|false>
27+
OptKeyUnpack ImageExporterOptKey = "unpack"
28+
29+
// Fallback image name prefix if image name isn't provided.
30+
// If used, image will be named as <value>@<digest>
31+
// Value: string
32+
OptKeyDanglingPrefix ImageExporterOptKey = "dangling-name-prefix"
33+
34+
// Creates additional image name with format <name>@<digest>
35+
// Value: bool <true|false>
36+
OptKeyNameCanonical ImageExporterOptKey = "name-canonical"
37+
38+
// Store the resulting image along with all of the content it references.
39+
// Ignored if the worker doesn't have image store (e.g. OCI worker).
40+
// Value: bool <true|false>
41+
OptKeyStore ImageExporterOptKey = "store"
42+
43+
// Use OCI mediatypes instead of Docker in JSON configs.
44+
// Value: bool <true|false>
45+
OptKeyOCITypes ImageExporterOptKey = "oci-mediatypes"
46+
47+
// Force attestation to be attached.
48+
// Value: bool <true|false>
49+
OptKeyForceInlineAttestations ImageExporterOptKey = "attestation-inline"
50+
51+
// Mark layers as non-distributable if they are found to use a
52+
// non-distributable media type. When this option is not set, the exporter
53+
// will change the media type of the layer to a distributable one.
54+
// Value: bool <true|false>
55+
OptKeyPreferNondistLayers ImageExporterOptKey = "prefer-nondist-layers"
56+
57+
// Clamp produced timestamps. For more information see the
58+
// SOURCE_DATE_EPOCH specification.
59+
// Value: int (number of seconds since Unix epoch)
60+
OptKeySourceDateEpoch ImageExporterOptKey = ImageExporterOptKey(commonexptypes.OptKeySourceDateEpoch)
61+
62+
// Compression type for newly created and cached layers.
63+
// estargz should be used with OptKeyOCITypes set to true.
64+
// Value: string <uncompressed|gzip|estargz|zstd>
65+
OptKeyLayerCompression ImageExporterOptKey = "compression"
66+
67+
// Force compression on all (including existing) layers.
68+
// Value: bool <true|false>
69+
OptKeyForceCompression ImageExporterOptKey = "force-compression"
70+
71+
// Compression level
72+
// Value: int (0-9) for gzip and estargz
73+
// Value: int (0-22) for zstd
74+
OptKeyCompressionLevel ImageExporterOptKey = "compression-level"
75+
)

exporter/containerimage/exptypes/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const (
1212
ExporterImageDescriptorKey = "containerimage.descriptor"
1313
ExporterInlineCache = "containerimage.inlinecache"
1414
ExporterPlatformsKey = "refs.platforms"
15-
ExporterEpochKey = "source.date.epoch"
1615
)
1716

1817
// KnownRefMetadataKeys are the subset of exporter keys that can be suffixed by

exporter/containerimage/opts.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,13 @@ import (
66
"time"
77

88
cacheconfig "github.com/moby/buildkit/cache/config"
9+
"github.com/moby/buildkit/exporter/containerimage/exptypes"
910
"github.com/moby/buildkit/exporter/util/epoch"
1011
"github.com/moby/buildkit/util/bklog"
1112
"github.com/moby/buildkit/util/compression"
1213
"github.com/pkg/errors"
1314
)
1415

15-
const (
16-
keyImageName = "name"
17-
keyOCITypes = "oci-mediatypes"
18-
keyForceInlineAttestations = "attestation-inline"
19-
20-
// preferNondistLayersKey is an exporter option which can be used to mark a layer as non-distributable if the layer reference was
21-
// already found to use a non-distributable media type.
22-
// When this option is not set, the exporter will change the media type of the layer to a distributable one.
23-
keyPreferNondistLayers = "prefer-nondist-layers"
24-
)
25-
2616
type ImageCommitOpts struct {
2717
ImageName string
2818
RefCfg cacheconfig.RefConfig
@@ -53,14 +43,14 @@ func (c *ImageCommitOpts) Load(ctx context.Context, opt map[string]string) (map[
5343

5444
for k, v := range opt {
5545
var err error
56-
switch k {
57-
case keyImageName:
46+
switch exptypes.ImageExporterOptKey(k) {
47+
case exptypes.OptKeyName:
5848
c.ImageName = v
59-
case keyOCITypes:
49+
case exptypes.OptKeyOCITypes:
6050
err = parseBoolWithDefault(&c.OCITypes, k, v, true)
61-
case keyForceInlineAttestations:
51+
case exptypes.OptKeyForceInlineAttestations:
6252
err = parseBool(&c.ForceInlineAttestations, k, v)
63-
case keyPreferNondistLayers:
53+
case exptypes.OptKeyPreferNondistLayers:
6454
err = parseBool(&c.RefCfg.PreferNonDistributable, k, v)
6555
default:
6656
rest[k] = v

exporter/exptypes/keys.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package exptypes
2+
3+
const (
4+
ExporterEpochKey = "source.date.epoch"
5+
)
6+
7+
type ExporterOptKey string
8+
9+
// Options keys supported by all exporters.
10+
var (
11+
// Clamp produced timestamps. For more information see the
12+
// SOURCE_DATE_EPOCH specification.
13+
// Value: int (number of seconds since Unix epoch)
14+
OptKeySourceDateEpoch ExporterOptKey = "source-date-epoch"
15+
)

exporter/util/epoch/parse.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import (
55
"time"
66

77
"github.com/moby/buildkit/exporter"
8-
"github.com/moby/buildkit/exporter/containerimage/exptypes"
8+
commonexptypes "github.com/moby/buildkit/exporter/exptypes"
99
"github.com/pkg/errors"
1010
)
1111

1212
const (
1313
frontendSourceDateEpochArg = "build-arg:SOURCE_DATE_EPOCH"
14-
15-
KeySourceDateEpoch = "source-date-epoch"
1614
)
1715

1816
func ParseBuildArgs(opt map[string]string) (string, bool) {
@@ -27,7 +25,7 @@ func ParseExporterAttrs(opt map[string]string) (*time.Time, map[string]string, e
2725

2826
for k, v := range opt {
2927
switch k {
30-
case KeySourceDateEpoch:
28+
case string(commonexptypes.OptKeySourceDateEpoch):
3129
var err error
3230
tm, err = parseTime(k, v)
3331
if err != nil {
@@ -42,7 +40,7 @@ func ParseExporterAttrs(opt map[string]string) (*time.Time, map[string]string, e
4240
}
4341

4442
func ParseSource(inp *exporter.Source) (*time.Time, bool, error) {
45-
if v, ok := inp.Metadata[exptypes.ExporterEpochKey]; ok {
43+
if v, ok := inp.Metadata[commonexptypes.ExporterEpochKey]; ok {
4644
epoch, err := parseTime("", string(v))
4745
if err != nil {
4846
return nil, false, errors.Wrapf(err, "invalid SOURCE_DATE_EPOCH from frontend: %q", v)

0 commit comments

Comments
 (0)