Skip to content

Commit 292cb12

Browse files
authored
Refactor cache and update provenance to v0.2 (#198)
* Refactor cache * Update sigs.k8s.io/bom to v0.6.0 * Sync go work * Improve S3 * Always rely on the cache * Ensure build on osx * Improve format * Improve gitinfo * Fix build * Add tests
1 parent cf69008 commit 292cb12

24 files changed

+1734
-1048
lines changed

cmd/build.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import (
1212
"time"
1313

1414
"github.com/gitpod-io/leeway/pkg/leeway"
15+
"github.com/gitpod-io/leeway/pkg/leeway/cache"
16+
"github.com/gitpod-io/leeway/pkg/leeway/cache/local"
17+
"github.com/gitpod-io/leeway/pkg/leeway/cache/remote"
1518
"github.com/gookit/color"
1619
log "github.com/sirupsen/logrus"
1720
"github.com/spf13/cobra"
@@ -84,7 +87,7 @@ var buildCmd = &cobra.Command{
8487
},
8588
}
8689

87-
func serveBuildResult(ctx context.Context, addr string, localCache *leeway.FilesystemCache, pkg *leeway.Package) {
90+
func serveBuildResult(ctx context.Context, addr string, localCache cache.LocalCache, pkg *leeway.Package) {
8891
br, exists := localCache.Location(pkg)
8992
if !exists {
9093
log.Fatal("build result is not in local cache despite just being built. Something's wrong with the cache.")
@@ -121,7 +124,7 @@ func serveBuildResult(ctx context.Context, addr string, localCache *leeway.Files
121124
}
122125
}
123126

124-
func saveBuildResult(ctx context.Context, loc string, localCache *leeway.FilesystemCache, pkg *leeway.Package) {
127+
func saveBuildResult(ctx context.Context, loc string, localCache cache.LocalCache, pkg *leeway.Package) {
125128
br, exists := localCache.Location(pkg)
126129
if !exists {
127130
log.Fatal("build result is not in local cache despite just being built. Something's wrong with the cache.")
@@ -178,20 +181,21 @@ func addBuildFlags(cmd *cobra.Command) {
178181
cmd.Flags().Bool("report-github", os.Getenv("GITHUB_OUTPUT") != "", "Report package build success/failure to GitHub Actions using the GITHUB_OUTPUT environment variable")
179182
}
180183

181-
func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, *leeway.FilesystemCache) {
184+
func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, cache.LocalCache) {
182185
cm, _ := cmd.Flags().GetString("cache")
183186
log.WithField("cacheMode", cm).Debug("configuring caches")
184187
cacheLevel := leeway.CacheLevel(cm)
185188

186-
remoteCache := getRemoteCache()
189+
var remoteCache cache.RemoteCache
187190
switch cacheLevel {
188191
case leeway.CacheNone, leeway.CacheLocal:
189-
remoteCache = leeway.NoRemoteCache{}
192+
remoteCache = remote.NewNoRemoteCache()
190193
case leeway.CacheRemotePull:
191-
remoteCache = &pullOnlyRemoteCache{C: remoteCache}
194+
remoteCache = &pullOnlyRemoteCache{C: remote.NewNoRemoteCache()}
192195
case leeway.CacheRemotePush:
193-
remoteCache = &pushOnlyRemoteCache{C: remoteCache}
196+
remoteCache = &pushOnlyRemoteCache{C: remote.NewNoRemoteCache()}
194197
case leeway.CacheRemote:
198+
remoteCache = remote.NewNoRemoteCache()
195199
default:
196200
log.Fatalf("invalid cache level: %s", cacheLevel)
197201
}
@@ -212,7 +216,7 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, *leeway.FilesystemC
212216
}
213217
}
214218
log.WithField("location", localCacheLoc).Debug("set up local cache")
215-
localCache, err := leeway.NewFilesystemCache(localCacheLoc)
219+
localCache, err := local.NewFilesystemCache(localCacheLoc)
216220
if err != nil {
217221
log.Fatal(err)
218222
}
@@ -310,33 +314,33 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, *leeway.FilesystemC
310314
}
311315

312316
type pushOnlyRemoteCache struct {
313-
C leeway.RemoteCache
317+
C cache.RemoteCache
314318
}
315319

316-
func (c *pushOnlyRemoteCache) ExistingPackages(pkgs []*leeway.Package) (map[*leeway.Package]struct{}, error) {
317-
return c.C.ExistingPackages(pkgs)
320+
func (c *pushOnlyRemoteCache) ExistingPackages(ctx context.Context, pkgs []cache.Package) (map[cache.Package]struct{}, error) {
321+
return c.C.ExistingPackages(ctx, pkgs)
318322
}
319323

320-
func (c *pushOnlyRemoteCache) Download(dst leeway.Cache, pkgs []*leeway.Package) error {
324+
func (c *pushOnlyRemoteCache) Download(ctx context.Context, dst cache.LocalCache, pkgs []cache.Package) error {
321325
return nil
322326
}
323327

324-
func (c *pushOnlyRemoteCache) Upload(src leeway.Cache, pkgs []*leeway.Package) error {
325-
return c.C.Upload(src, pkgs)
328+
func (c *pushOnlyRemoteCache) Upload(ctx context.Context, src cache.LocalCache, pkgs []cache.Package) error {
329+
return c.C.Upload(ctx, src, pkgs)
326330
}
327331

328332
type pullOnlyRemoteCache struct {
329-
C leeway.RemoteCache
333+
C cache.RemoteCache
330334
}
331335

332-
func (c *pullOnlyRemoteCache) ExistingPackages(pkgs []*leeway.Package) (map[*leeway.Package]struct{}, error) {
333-
return c.C.ExistingPackages(pkgs)
336+
func (c *pullOnlyRemoteCache) ExistingPackages(ctx context.Context, pkgs []cache.Package) (map[cache.Package]struct{}, error) {
337+
return c.C.ExistingPackages(ctx, pkgs)
334338
}
335339

336-
func (c *pullOnlyRemoteCache) Download(dst leeway.Cache, pkgs []*leeway.Package) error {
337-
return c.C.Download(dst, pkgs)
340+
func (c *pullOnlyRemoteCache) Download(ctx context.Context, dst cache.LocalCache, pkgs []cache.Package) error {
341+
return c.C.Download(ctx, dst, pkgs)
338342
}
339343

340-
func (c *pullOnlyRemoteCache) Upload(src leeway.Cache, pkgs []*leeway.Package) error {
344+
func (c *pullOnlyRemoteCache) Upload(ctx context.Context, src cache.LocalCache, pkgs []cache.Package) error {
341345
return nil
342346
}

cmd/provenance-assert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var provenanceAssertCmd = &cobra.Command{
7373
return nil
7474
}
7575

76-
failures = append(assertions.AssertEnvelope(env), failures...)
76+
failures = append(assertions.AssertBundle(env), failures...)
7777

7878
raw, err := base64.StdEncoding.DecodeString(env.Payload)
7979
if err != nil {

cmd/root.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -173,33 +173,6 @@ func getBuildArgs() (leeway.Arguments, error) {
173173
return res, nil
174174
}
175175

176-
func getRemoteCache() leeway.RemoteCache {
177-
remoteCacheBucket := os.Getenv(EnvvarRemoteCacheBucket)
178-
remoteStorage := os.Getenv(EnvvarRemoteCacheStorage)
179-
if remoteCacheBucket != "" {
180-
switch remoteStorage {
181-
case "GCP":
182-
return leeway.GSUtilRemoteCache{
183-
BucketName: remoteCacheBucket,
184-
}
185-
case "AWS":
186-
rc, err := leeway.NewS3RemoteCache(remoteCacheBucket, nil)
187-
if err != nil {
188-
log.Fatalf("cannot access remote S3 cache: %v", err)
189-
}
190-
191-
return rc
192-
default:
193-
return leeway.GSUtilRemoteCache{
194-
BucketName: remoteCacheBucket,
195-
}
196-
}
197-
198-
}
199-
200-
return leeway.NoRemoteCache{}
201-
}
202-
203176
func addExperimentalCommand(parent, child *cobra.Command) {
204177
if os.Getenv("LEEWAY_EXPERIMENTAL") != "true" {
205178
return

go.mod

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ module github.com/gitpod-io/leeway
33
go 1.23
44

55
require (
6-
github.com/aws/aws-sdk-go-v2 v1.32.3
7-
github.com/aws/aws-sdk-go-v2/config v1.28.1
8-
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.35
9-
github.com/aws/aws-sdk-go-v2/service/s3 v1.66.2
10-
github.com/aws/aws-sdk-go-v2/service/sts v1.32.3
6+
github.com/aws/aws-sdk-go-v2 v1.36.1
7+
github.com/aws/aws-sdk-go-v2/config v1.29.6
8+
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.59
9+
github.com/aws/aws-sdk-go-v2/service/s3 v1.75.4
1110
github.com/creack/pty v1.1.23
1211
github.com/disiqueira/gotree v1.0.0
1312
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd
@@ -16,7 +15,7 @@ require (
1615
github.com/google/uuid v1.6.0
1716
github.com/gookit/color v1.5.4
1817
github.com/imdario/mergo v0.3.13
19-
github.com/in-toto/in-toto-golang v0.3.3
18+
github.com/in-toto/in-toto-golang v0.9.0
2019
github.com/karrick/godirwalk v1.17.0
2120
github.com/minio/highwayhash v1.0.2
2221
github.com/opencontainers/runc v1.1.10
@@ -26,49 +25,50 @@ require (
2625
github.com/sirupsen/logrus v1.9.3
2726
github.com/spf13/cobra v1.8.1
2827
github.com/stretchr/testify v1.9.0
29-
golang.org/x/mod v0.21.0
30-
golang.org/x/sync v0.8.0
28+
golang.org/x/mod v0.23.0
29+
golang.org/x/sync v0.11.0
3130
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da
3231
gopkg.in/yaml.v3 v3.0.1
33-
sigs.k8s.io/bom v0.1.0
32+
sigs.k8s.io/bom v0.6.0
3433
)
3534

3635
require (
37-
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 // indirect
38-
github.com/aws/aws-sdk-go-v2/credentials v1.17.42 // indirect
39-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.18 // indirect
40-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.22 // indirect
41-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.22 // indirect
42-
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
43-
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.22 // indirect
44-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect
45-
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.3 // indirect
46-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.3 // indirect
47-
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.3 // indirect
48-
github.com/aws/aws-sdk-go-v2/service/sso v1.24.3 // indirect
49-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.3 // indirect
50-
github.com/aws/smithy-go v1.22.0 // indirect
36+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.8 // indirect
37+
github.com/aws/aws-sdk-go-v2/credentials v1.17.59 // indirect
38+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.28 // indirect
39+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.32 // indirect
40+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.32 // indirect
41+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.2 // indirect
42+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.32 // indirect
43+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.2 // indirect
44+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.6 // indirect
45+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.13 // indirect
46+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.13 // indirect
47+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.15 // indirect
48+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.14 // indirect
49+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.14 // indirect
50+
github.com/aws/smithy-go v1.22.2 // indirect
5151
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
52-
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
53-
github.com/cyphar/filepath-securejoin v0.3.4 // indirect
52+
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
53+
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
5454
github.com/davecgh/go-spew v1.1.1 // indirect
5555
github.com/dlclark/regexp2 v1.11.4 // indirect
5656
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
57-
github.com/godbus/dbus/v5 v5.1.0 // indirect
57+
github.com/godbus/dbus/v5 v5.0.6 // indirect
5858
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
5959
github.com/inconshreveable/mousetrap v1.1.0 // indirect
60-
github.com/kr/pretty v0.3.1 // indirect
61-
github.com/moby/sys/mountinfo v0.7.1 // indirect
62-
github.com/pkg/errors v0.9.1 // indirect
60+
github.com/moby/sys/mountinfo v0.5.0 // indirect
6361
github.com/pmezard/go-difflib v1.0.0 // indirect
64-
github.com/rogpeppe/go-internal v1.11.0 // indirect
65-
github.com/seccomp/libseccomp-golang v0.10.0 // indirect
62+
github.com/rogpeppe/go-internal v1.13.1 // indirect
63+
github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646 // indirect
64+
github.com/secure-systems-lab/go-securesystemslib v0.6.0 // indirect
6665
github.com/segmentio/backo-go v1.0.0 // indirect
67-
github.com/shibumi/go-pathspec v1.2.0 // indirect
66+
github.com/shibumi/go-pathspec v1.3.0 // indirect
6867
github.com/spf13/pflag v1.0.5 // indirect
6968
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
70-
golang.org/x/net v0.24.0 // indirect
71-
golang.org/x/sys v0.22.0 // indirect
69+
golang.org/x/crypto v0.18.0 // indirect
70+
golang.org/x/net v0.20.0 // indirect
71+
golang.org/x/sys v0.21.0 // indirect
7272
golang.org/x/text v0.14.0 // indirect
73-
sigs.k8s.io/release-utils v0.3.0 // indirect
73+
sigs.k8s.io/release-utils v0.7.7 // indirect
7474
)

0 commit comments

Comments
 (0)