Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cargo/crates.io Sparse Index support #217

Merged
merged 2 commits into from
Feb 6, 2023
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
4 changes: 2 additions & 2 deletions cargo/cargo.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ func (c Cargo) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
return libcnb.Layer{}, fmt.Errorf("unable to find CARGO_HOME, it must be set")
}

if err := os.Setenv("CARGO_UNSTABLE_SPARSE_REGISTRY", "true"); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to set CARGO_UNSTABLE_SPARSE_REGISTRY\n%w", err)
if err := os.Setenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL", "sparse"); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to set CARGO_REGISTRIES_CRATES_IO_PROTOCOL\n%w", err)
}

if err = preserver.RestoreAll(targetPath, cargoHome, layer.Path); err != nil {
Expand Down
14 changes: 7 additions & 7 deletions cargo/cargo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
_, err = c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

Expect(service.Calls[2].Method).To(Equal("InstallTool"))
Expect(service.Calls[2].Arguments[0]).To(Equal("foo-tool"))
Expand Down Expand Up @@ -343,7 +343,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -390,7 +390,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -437,7 +437,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertNotCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -489,7 +489,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -539,7 +539,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

sbomScanner.AssertCalled(t, "ScanLayer", inputLayer, ctx.Application.Path, libcnb.CycloneDXJSON, libcnb.SyftJSON)

Expand Down Expand Up @@ -653,7 +653,7 @@ func testCargo(t *testing.T, context spec.G, it spec.S) {
outputLayer, err := c.Contribute(inputLayer)
Expect(err).NotTo(HaveOccurred())

Expect(os.Getenv("CARGO_UNSTABLE_SPARSE_REGISTRY")).To(Equal("true"))
Expect(os.Getenv("CARGO_REGISTRIES_CRATES_IO_PROTOCOL")).To(Equal("sparse"))

Expect(outputLayer.LayerTypes.Cache).To(BeTrue())
Expect(outputLayer.LayerTypes.Build).To(BeFalse())
Expand Down