Skip to content

Commit

Permalink
epoch: refactor frontend attribute parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Chadwell <me@jedevc.com>
  • Loading branch information
jedevc committed Dec 8, 2022
1 parent 2fe41bc commit 50c2083
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*
}

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

Expand Down
2 changes: 1 addition & 1 deletion exporter/containerimage/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (c *ImageCommitOpts) Load(opt map[string]string) (map[string]string, error)
}
opt = toStringMap(optb)

c.Epoch, opt, err = epoch.ParseAttr(opt)
c.Epoch, opt, err = epoch.ParseExporterAttrs(opt)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/local/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func New(opt Opt) (exporter.Exporter, error) {
}

func (e *localExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) {
tm, _, err := epoch.ParseAttr(opt)
tm, _, err := epoch.ParseExporterAttrs(opt)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/tar/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func New(opt Opt) (exporter.Exporter, error) {
func (e *localExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) {
li := &localExporterInstance{localExporter: e}

tm, _, err := epoch.ParseAttr(opt)
tm, _, err := epoch.ParseExporterAttrs(opt)
if err != nil {
return nil, err
}
Expand Down
9 changes: 8 additions & 1 deletion exporter/util/epoch/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ import (
)

const (
frontendSourceDateEpochArg = "build-arg:SOURCE_DATE_EPOCH"

KeySourceDateEpoch = "source-date-epoch"
)

func ParseAttr(opt map[string]string) (*time.Time, map[string]string, error) {
func ParseBuildArgs(opt map[string]string) (string, bool) {
v, ok := opt[frontendSourceDateEpochArg]
return v, ok
}

func ParseExporterAttrs(opt map[string]string) (*time.Time, map[string]string, error) {
rest := make(map[string]string, len(opt))

var tm *time.Time
Expand Down

0 comments on commit 50c2083

Please sign in to comment.