Skip to content

Commit

Permalink
exporter: Add exptypes with Common exporter keys
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 cecab8d commit d82a803
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion exporter/containerimage/exptypes/keys.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package exptypes

import commonexptypes "github.com/moby/buildkit/exporter/exptypes"

type ImageExporterOptKey string

// Options keys supported by the image exporter output.
Expand Down Expand Up @@ -55,7 +57,7 @@ var (
// Clamp produced timestamps. For more information see the
// SOURCE_DATE_EPOCH specification.
// Value: int (number of seconds since Unix epoch)
OptKeySourceDateEpoch ImageExporterOptKey = "source-date-epoch"
OptKeySourceDateEpoch ImageExporterOptKey = ImageExporterOptKey(commonexptypes.OptKeySourceDateEpoch)

// Compression type for newly created and cached layers.
// estargz should be used with OptKeyOCITypes set to true.
Expand Down
1 change: 0 additions & 1 deletion exporter/containerimage/exptypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const (
ExporterImageDescriptorKey = "containerimage.descriptor"
ExporterInlineCache = "containerimage.inlinecache"
ExporterPlatformsKey = "refs.platforms"
ExporterEpochKey = "source.date.epoch"
)

// KnownRefMetadataKeys are the subset of exporter keys that can be suffixed by
Expand Down
15 changes: 15 additions & 0 deletions exporter/exptypes/keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package exptypes

const (
ExporterEpochKey = "source.date.epoch"
)

type ExporterOptKey string

// Options keys supported by all exporters.
var (
// Clamp produced timestamps. For more information see the
// SOURCE_DATE_EPOCH specification.
// Value: int (number of seconds since Unix epoch)
OptKeySourceDateEpoch ExporterOptKey = "source-date-epoch"
)
6 changes: 3 additions & 3 deletions exporter/util/epoch/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
commonexptypes "github.com/moby/buildkit/exporter/exptypes"
"github.com/pkg/errors"
)

Expand All @@ -25,7 +25,7 @@ func ParseExporterAttrs(opt map[string]string) (*time.Time, map[string]string, e

for k, v := range opt {
switch k {
case string(exptypes.OptKeySourceDateEpoch):
case string(commonexptypes.OptKeySourceDateEpoch):
var err error
tm, err = parseTime(k, v)
if err != nil {
Expand All @@ -40,7 +40,7 @@ func ParseExporterAttrs(opt map[string]string) (*time.Time, map[string]string, e
}

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

0 comments on commit d82a803

Please sign in to comment.