-
Notifications
You must be signed in to change notification settings - Fork 107
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
Restorer changes for run image extension #1014
Merged
Merged
Changes from 27 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
f22c4f9
Make a single constructor for lifecycle inputs
natalieparellano 433bf3c
Read values from environment
natalieparellano f40616e
Buildpack API: run.Dockerfiles are allowed instructions on versions >…
natalieparellano 29a94a6
Platform API: the detector accepts a new -run flag
natalieparellano 569f985
Move responsibility for validating Dockerfiles into the buildpack pac…
natalieparellano c72a10e
When verifying Dockerfiles, return the new base image name if necessary
natalieparellano 4c5a564
When determining the new runtime base image, use criteria outlined in…
natalieparellano 01ab4b6
Platform API: the schema of analyzed.toml is updated to include run-i…
natalieparellano 9ba40e3
TESTME: Update analyzed.toml with new run image if needed
natalieparellano eea3182
If extensions are used to switch the runtime base image, the detector…
natalieparellano 647a3db
Add fixture to test re-writing of analyzed.toml
natalieparellano 9157796
Move updating analyzed.toml into lifecycle package for easier testing
natalieparellano 62411e8
Platform API: the restorer will update analyzed.toml with:
natalieparellano 362e755
Update acceptance/extender_test.go
natalieparellano 15c4c06
Merge branch 'main' into runext/restore-997
natalieparellano 8917ca0
Fix merge and restore selective package
natalieparellano ea13f10
Update analyzed.toml with digest reference or target data if needed
natalieparellano d0ce558
Merge branch 'main' into runext/detect-996
natalieparellano 9ba92d1
Fix acceptance
natalieparellano 6487081
Merge branch 'main' into runext/restore-997
natalieparellano 76c7284
Merge branch 'runext/detect-996' into runext/restore-997
natalieparellano b8f029f
Don't redefine -layers
natalieparellano 2d78993
Merge branch 'runext/detect-996' into runext/restore-997
natalieparellano 44663c5
Merge branch 'main' into runext/restore-997
natalieparellano 8a70c55
Test organization and remove the requirement that we're exporting to …
natalieparellano 5cce13c
Fix acceptance
natalieparellano c630e7d
Fix acceptance
natalieparellano 0f2305a
Test that we don't update target data for older platforms
natalieparellano 5adcca5
Remove target partial and use helper function
natalieparellano 2c17e05
Fix acceptance
natalieparellano 4054ebd
Bump imgutil
natalieparellano 95dbc52
Fix acceptance
natalieparellano cc1a045
Merge branch 'main' into runext/restore-997
natalieparellano c8398c3
Use imgutil/sparse package instead of internal/selective package
natalieparellano ac6ad80
Don't try to pull a builder image if it wasn't specified
natalieparellano da9e2ff
Fix lint
natalieparellano f2a068e
Add and update comment
natalieparellano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,13 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/google/go-containerregistry/pkg/name" | ||
"github.com/sclevine/spec" | ||
"github.com/sclevine/spec/report" | ||
|
||
"github.com/buildpacks/lifecycle" | ||
"github.com/buildpacks/lifecycle/api" | ||
"github.com/buildpacks/lifecycle/cmd" | ||
h "github.com/buildpacks/lifecycle/testhelpers" | ||
) | ||
|
||
|
@@ -38,7 +40,7 @@ func TestRestorer(t *testing.T) { | |
|
||
testImageDockerContext := filepath.Join("testdata", "restorer") | ||
restoreTest = NewPhaseTest(t, "restorer", testImageDockerContext) | ||
restoreTest.Start(t) | ||
restoreTest.Start(t, updateAnalyzedTOMLFixturesWithRegRepoName) | ||
defer restoreTest.Stop(t) | ||
|
||
restoreImage = restoreTest.testImageRef | ||
|
@@ -80,7 +82,7 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe | |
}) | ||
}) | ||
|
||
when("called with -analyzed", func() { | ||
when("called with -analyzed (on older platforms)", func() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A+ update to test descriptions |
||
it("errors", func() { | ||
h.SkipIf(t, api.MustParse(platformAPI).AtLeast("0.7"), "Platform API >= 0.7 supports -analyzed flag") | ||
command := exec.Command("docker", "run", "--rm", restoreImage, "-analyzed some-file-location") | ||
|
@@ -91,7 +93,7 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe | |
}) | ||
}) | ||
|
||
when("called with -skip-layers", func() { | ||
when("called with -skip-layers (on older platforms)", func() { | ||
it("errors", func() { | ||
h.SkipIf(t, api.MustParse(platformAPI).AtLeast("0.7"), "Platform API >= 0.7 supports -skip-layers flag") | ||
command := exec.Command("docker", "run", "--rm", restoreImage, "-skip-layers true") | ||
|
@@ -188,9 +190,9 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe | |
}) | ||
}) | ||
|
||
when("using kaniko cache", func() { | ||
it("accepts -build-image", func() { | ||
h.SkipIf(t, api.MustParse(platformAPI).LessThan("0.10"), "Platform API < 0.10 does not use kaniko") | ||
when("restoring builder image metadata", func() { | ||
it("accepts -build-image and saves the metadata to /kaniko/cache", func() { | ||
h.SkipIf(t, api.MustParse(platformAPI).LessThan("0.10"), "Platform API < 0.10 does not restore builder image metadata") | ||
h.DockerRunAndCopy(t, | ||
containerName, | ||
copyDir, | ||
|
@@ -204,14 +206,79 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe | |
h.WithArgs("-build-image", restoreRegFixtures.SomeCacheImage), // some-cache-image simulates a builder image in a registry | ||
) | ||
t.Log("records builder image digest in analyzed.toml") | ||
analyzedMD, err := lifecycle.Config.ReadAnalyzed(filepath.Join(copyDir, "layers", "analyzed.toml"), nil) | ||
analyzedMD, err := lifecycle.Config.ReadAnalyzed(filepath.Join(copyDir, "layers", "analyzed.toml"), cmd.DefaultLogger) | ||
h.AssertNil(t, err) | ||
h.AssertStringContains(t, analyzedMD.BuildImage.Reference, restoreRegFixtures.SomeCacheImage+"@sha256:") | ||
t.Log("writes builder manifest and config to the kaniko cache") | ||
ref, err := name.ParseReference(analyzedMD.BuildImage.Reference) | ||
h.AssertNil(t, err) | ||
fis, err := os.ReadDir(filepath.Join(copyDir, "kaniko", "cache", "base")) | ||
h.AssertNil(t, err) | ||
h.AssertEq(t, len(fis), 1) | ||
h.AssertPathExists(t, filepath.Join(copyDir, "kaniko", "cache", "base", fis[0].Name(), "oci-layout")) | ||
h.AssertPathExists(t, filepath.Join(copyDir, "kaniko", "cache", "base", ref.Identifier(), "oci-layout")) | ||
}) | ||
}) | ||
|
||
when("restoring run image metadata", func() { | ||
it("saves metadata to /kaniko/cache", func() { | ||
h.SkipIf(t, api.MustParse(platformAPI).LessThan("0.12"), "Platform API < 0.12 does not restore run image metadata") | ||
h.DockerRunAndCopy(t, | ||
containerName, | ||
copyDir, | ||
"/", | ||
restoreImage, | ||
h.WithFlags( | ||
"--env", "CNB_PLATFORM_API="+platformAPI, | ||
"--env", "DOCKER_CONFIG=/docker-config", | ||
"--network", restoreRegNetwork, | ||
), | ||
h.WithArgs( | ||
"-analyzed", "/layers/some-extend-true-analyzed.toml", | ||
"-log-level", "debug", | ||
), | ||
) | ||
t.Log("updates run image reference in analyzed.toml to include digest and target data") | ||
analyzedMD, err := lifecycle.Config.ReadAnalyzed(filepath.Join(copyDir, "layers", "some-extend-true-analyzed.toml"), cmd.DefaultLogger) | ||
h.AssertNil(t, err) | ||
h.AssertStringContains(t, analyzedMD.RunImage.Reference, restoreRegFixtures.ReadOnlyRunImage+"@sha256:") | ||
h.AssertEq(t, analyzedMD.RunImage.TargetMetadata.OS, "linux") | ||
t.Log("writes run image manifest and config to the kaniko cache") | ||
ref, err := name.ParseReference(analyzedMD.RunImage.Reference) | ||
h.AssertNil(t, err) | ||
fis, err := os.ReadDir(filepath.Join(copyDir, "kaniko", "cache", "base")) | ||
h.AssertNil(t, err) | ||
h.AssertEq(t, len(fis), 1) | ||
h.AssertPathExists(t, filepath.Join(copyDir, "kaniko", "cache", "base", ref.Identifier(), "oci-layout")) | ||
}) | ||
|
||
when("only target data needs updating", func() { | ||
it("updates run image reference in analyzed.toml to include digest and target data", func() { | ||
h.SkipIf(t, api.MustParse(platformAPI).LessThan("0.12"), "Platform API < 0.12 does not restore run image metadata") | ||
h.DockerRunAndCopy(t, | ||
containerName, | ||
copyDir, | ||
"/", | ||
restoreImage, | ||
h.WithFlags( | ||
"--env", "CNB_PLATFORM_API="+platformAPI, | ||
"--env", "DOCKER_CONFIG=/docker-config", | ||
"--network", restoreRegNetwork, | ||
), | ||
h.WithArgs( | ||
"-analyzed", "/layers/some-extend-false-analyzed.toml", | ||
"-log-level", "debug", | ||
), | ||
) | ||
t.Log("updates run image reference in analyzed.toml to include digest and target data") | ||
analyzedMD, err := lifecycle.Config.ReadAnalyzed(filepath.Join(copyDir, "layers", "some-extend-false-analyzed.toml"), cmd.DefaultLogger) | ||
h.AssertNil(t, err) | ||
h.AssertStringContains(t, analyzedMD.RunImage.Reference, restoreRegFixtures.ReadOnlyRunImage+"@sha256:") | ||
h.AssertEq(t, analyzedMD.RunImage.TargetMetadata.OS, "linux") | ||
t.Log("does not write run image manifest and config to the kaniko cache") | ||
fis, err := os.ReadDir(filepath.Join(copyDir, "kaniko")) | ||
h.AssertNil(t, err) | ||
h.AssertEq(t, len(fis), 1) // .gitkeep | ||
}) | ||
}) | ||
}) | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
acceptance/testdata/restorer/container/layers/some-extend-false-analyzed.toml.placeholder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[run-image] | ||
reference = "REPLACE" | ||
|
||
[run-image.target] | ||
id = "some-target-id" |
3 changes: 3 additions & 0 deletions
3
acceptance/testdata/restorer/container/layers/some-extend-true-analyzed.toml.placeholder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[run-image] | ||
reference = "REPLACE" | ||
extend = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,10 @@ type TargetPartial struct { | |
|
||
type TargetMetadata struct { | ||
TargetPartial | ||
Distributions []DistributionMetadata `json:"distributions" toml:"distributions"` | ||
Distributions []OSDistribution `json:"distributions" toml:"distributions"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preferred the slightly more descriptive name |
||
} | ||
|
||
type DistributionMetadata struct { | ||
type OSDistribution struct { | ||
Name string `json:"name" toml:"name"` | ||
Version string `json:"version" toml:"version"` | ||
} | ||
|
@@ -66,7 +66,7 @@ func ReadBpDescriptor(path string) (*BpDescriptor, error) { | |
if len(descriptor.Targets) == 0 { | ||
for _, stack := range descriptor.Stacks { | ||
if stack.ID == "io.buildpacks.stacks.bionic" { | ||
descriptor.Targets = append(descriptor.Targets, TargetMetadata{TargetPartial: TargetPartial{OS: "linux", Arch: "amd64"}, Distributions: []DistributionMetadata{{Name: "ubuntu", Version: "18.04"}}}) | ||
descriptor.Targets = append(descriptor.Targets, TargetMetadata{TargetPartial: TargetPartial{OS: "linux", Arch: "amd64"}, Distributions: []OSDistribution{{Name: "ubuntu", Version: "18.04"}}}) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper function exists because we expect the run image in analyzed.toml to contain the registry IP and port, which aren't known until we start the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about leaving this comment as a
//comment
in the code?