Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7692,8 +7692,9 @@ func testExportAttestations(t *testing.T, sb integration.Sandbox) {

for _, p := range ps {
var attest intoto.Statement
dt := m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation.json")].Data
require.NoError(t, json.Unmarshal(dt, &attest))
item := m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation.json")]
require.NotNil(t, item)
require.NoError(t, json.Unmarshal(item.Data, &attest))

require.Equal(t, "https://in-toto.io/Statement/v0.1", attest.Type)
require.Equal(t, "https://example.com/attestations/v1.0", attest.PredicateType)
Expand All @@ -7705,8 +7706,9 @@ func testExportAttestations(t *testing.T, sb integration.Sandbox) {
}}, attest.Subject)

var attest2 intoto.Statement
dt = m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation2.json")].Data
require.NoError(t, json.Unmarshal(dt, &attest2))
item = m[path.Join(strings.ReplaceAll(platforms.Format(p), "/", "_"), "test.attestation2.json")]
require.NotNil(t, item)
require.NoError(t, json.Unmarshal(item.Data, &attest2))

require.Equal(t, "https://in-toto.io/Statement/v0.1", attest2.Type)
require.Equal(t, "https://example.com/attestations2/v1.0", attest2.PredicateType)
Expand Down
21 changes: 3 additions & 18 deletions exporter/local/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ import (
"golang.org/x/time/rate"
)

const (
keyAttestationPrefix = "attestation-prefix"
)

type Opt struct {
SessionManager *session.Manager
}
Expand All @@ -39,23 +35,12 @@ func New(opt Opt) (exporter.Exporter, error) {
}

func (e *localExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) {
tm, _, err := epoch.ParseExporterAttrs(opt)
if err != nil {
return nil, err
}

i := &localExporterInstance{
localExporter: e,
opts: CreateFSOpts{
Epoch: tm,
},
}

for k, v := range opt {
switch k {
case keyAttestationPrefix:
i.opts.AttestationPrefix = v
}
_, err := i.opts.Load(opt)
if err != nil {
return nil, err
}

return i, nil
Expand Down
26 changes: 26 additions & 0 deletions exporter/local/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/exporter"
"github.com/moby/buildkit/exporter/attestation"
"github.com/moby/buildkit/exporter/util/epoch"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/snapshot"
"github.com/moby/buildkit/solver/result"
Expand All @@ -25,11 +26,36 @@ import (
fstypes "github.com/tonistiigi/fsutil/types"
)

const (
keyAttestationPrefix = "attestation-prefix"
)

type CreateFSOpts struct {
Epoch *time.Time
AttestationPrefix string
}

func (c *CreateFSOpts) Load(opt map[string]string) (map[string]string, error) {
rest := make(map[string]string)

var err error
c.Epoch, opt, err = epoch.ParseExporterAttrs(opt)
if err != nil {
return nil, err
}

for k, v := range opt {
switch k {
case keyAttestationPrefix:
c.AttestationPrefix = v
default:
rest[k] = v
}
}

return rest, nil
}

func CreateFS(ctx context.Context, sessionID string, k string, ref cache.ImmutableRef, attestations []exporter.Attestation, defaultTime time.Time, opt CreateFSOpts) (fsutil.FS, func() error, error) {
var cleanup func() error
var src string
Expand Down
31 changes: 3 additions & 28 deletions exporter/tar/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package local
import (
"context"
"os"
"strconv"
"strings"
"time"

Expand All @@ -20,15 +19,6 @@ import (
fstypes "github.com/tonistiigi/fsutil/types"
)

const (
attestationPrefixKey = "attestation-prefix"

// preferNondistLayersKey is an exporter option which can be used to mark a layer as non-distributable if the layer reference was
// already 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.
preferNondistLayersKey = "prefer-nondist-layers"
)

type Opt struct {
SessionManager *session.Manager
}
Expand All @@ -45,33 +35,18 @@ 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, opt, err := epoch.ParseExporterAttrs(opt)
_, err := li.opts.Load(opt)
if err != nil {
return nil, err
}
li.opts.Epoch = tm

for k, v := range opt {
switch k {
case preferNondistLayersKey:
b, err := strconv.ParseBool(v)
if err != nil {
return nil, errors.Wrapf(err, "non-bool value for %s: %s", preferNondistLayersKey, v)
}
li.preferNonDist = b
case attestationPrefixKey:
li.opts.AttestationPrefix = v
}
}
_ = opt

return li, nil
}

type localExporterInstance struct {
*localExporter
opts local.CreateFSOpts
preferNonDist bool
opts local.CreateFSOpts
}

func (e *localExporterInstance) Name() string {
Expand Down