From 6c7d16a7188713e21d858a467240c5c3a560093f Mon Sep 17 00:00:00 2001 From: Natalie Arellano Date: Tue, 26 Sep 2023 11:30:50 -0400 Subject: [PATCH] Move lifecycle package to sub-directory (#1205) * Move files Signed-off-by: Natalie Arellano * Fix imports Signed-off-by: Natalie Arellano * Update mockgen directives Signed-off-by: Natalie Arellano * WIP: add TODOs Signed-off-by: Natalie Arellano * Rename lifecycle -> phase Signed-off-by: Natalie Arellano * Address TODOs by adding comments Signed-off-by: Natalie Arellano * Update phase/handlers.go Signed-off-by: Natalie Arellano --------- Signed-off-by: Natalie Arellano --- acceptance/restorer_test.go | 12 ++-- buildpack/build.go | 6 +- buildpack/build_test.go | 4 +- buildpack/descriptor.go | 5 +- buildpack/detect.go | 7 +- buildpack/generate.go | 7 +- buildpack/generate_test.go | 2 +- buildpack/testmock/env.go | 2 +- cache/image_cache_test.go | 7 +- cache/image_comparer.go | 2 +- cache/image_deleter.go | 2 +- cache/image_deleter_test.go | 2 +- cmd/apis.go | 58 +++++++++------ cmd/lifecycle/analyzer.go | 11 ++- cmd/lifecycle/builder.go | 6 +- cmd/lifecycle/creator.go | 15 ++-- cmd/lifecycle/detector.go | 16 ++--- cmd/lifecycle/exporter.go | 14 ++-- cmd/lifecycle/extender.go | 4 +- cmd/lifecycle/main.go | 10 +-- cmd/lifecycle/rebaser.go | 4 +- cmd/lifecycle/restorer.go | 8 +-- image/handler.go | 5 ++ image/handler_test.go | 4 +- image/registry_handler.go | 2 +- internal/layer/metadata_restorer.go | 7 +- internal/layer/sbom_restorer.go | 7 +- internal/layer/sbom_restorer_test.go | 4 +- analyzer.go => phase/analyzer.go | 2 +- analyzer_test.go => phase/analyzer_test.go | 23 +++--- builder.go => phase/builder.go | 6 +- builder_test.go => phase/builder_test.go | 10 +-- cache.go => phase/cache.go | 2 +- cache_test.go => phase/cache_test.go | 16 ++--- detector.go => phase/detector.go | 9 ++- detector_test.go => phase/detector_test.go | 70 +++++++++---------- exporter.go => phase/exporter.go | 7 +- exporter_test.go => phase/exporter_test.go | 16 ++--- extender.go => phase/extender.go | 7 +- extender_test.go => phase/extender_test.go | 20 +++--- generator.go => phase/generator.go | 2 +- generator_test.go => phase/generator_test.go | 14 ++-- handlers.go => phase/handlers.go | 24 ++++--- handlers_test.go => phase/handlers_test.go | 12 ++-- phase/phase.go | 6 ++ rebaser.go => phase/rebaser.go | 2 +- rebaser_test.go => phase/rebaser_test.go | 8 +-- restorer.go => phase/restorer.go | 2 +- restorer_test.go => phase/restorer_test.go | 12 ++-- save.go => phase/save.go | 2 +- .../testdata}/analyzer/app_metadata.json | 0 .../analyzer/cache_inconsistent_metadata.json | 0 .../testdata}/analyzer/cache_metadata.json | 0 .../buildpack.id/cache-true-no-contents.toml | 0 .../invalid-layers/buildpack.id/layer-1.toml | 0 .../buildpack.id/layer-1/layer-1-file | 0 .../invalid-layers/buildpack.id/layer-2.toml | 0 .../buildpack.id/layer-2/layer-2-file | 0 .../buildpack.id/cache-false-layer.toml | 0 .../file-from-cache-false-layer | 0 .../layers/buildpack.id/cache-true-layer.sha | 0 .../layers/buildpack.id/cache-true-layer.toml | 0 .../file-from-cache-true-layer | 0 .../buildpack.id/cache-true-no-sha-layer.toml | 0 .../file-from-cache-true-no-sha-layer | 0 .../old.buildpack.id/cache-true-layer.sha | 0 .../old.buildpack.id/cache-true-layer.toml | 0 .../file-from-cache-true-layer | 0 .../other-buildpack-layer.toml | 0 .../other-buildpack-layer-file | 0 .../cache-true-layer/bom.cdx.json | 0 .../testdata}/cred_helpers/config1.json | 0 .../testdata}/cred_helpers/config2.json | 0 .../app-slices/layers/app/.hidden.txt | 0 .../layers/app/static/assets/config.txt | 0 .../layers/app/static/assets/logo.svg | 0 .../static/misc/resources/reports/numbers.csv | 0 .../static/misc/resources/reports/report.tps | 0 .../app-slices/layers/app/test_app.sh | 0 .../layers/buildpack.id/layer1.toml | 0 .../buildpack.id/layer1/file-from-layer-1 | 0 .../layers/buildpack.id/layer2.toml | 0 .../buildpack.id/layer2/file-from-layer-2 | 0 .../app-slices/layers/config/metadata.toml | 0 .../local-reusable-layer.toml | 0 .../local-reusable-layer/layer5contents | 0 .../other.buildpack.id/new-launch-layer.toml | 0 .../new-launch-layer/new-launch-layer-file | 0 .../bad-layer/layers/app/metadata.toml | 0 .../exporter/bad-layer/layers/app/test_app.sh | 0 .../layers/buildpack.id/bad-layer.toml | 0 .../bad-layer/layers/config/metadata.toml | 0 .../bad-layers/buildpack.id/build.toml | 0 .../bad-layers/config/metadata.toml | 0 .../bad-layers/other.buildpack.id/build.toml | 0 .../layers/buildpack.id/build.toml | 0 .../layers/config/metadata.toml | 0 .../layers/other.buildpack.id/build.toml | 0 .../layers/app/metadata.toml | 0 .../layers/app/test_app.sh | 0 .../buildpack.id/cache-layer-no-contents.toml | 0 .../layers/config/metadata.toml | 0 .../no-toml-layer/file-for-invalid-layer | 0 .../layers/config/metadata.toml | 0 .../layers/config/metadata.toml | 0 .../layers/config/metadata.toml | 0 .../exporter/escaped-bpid/layers/app/app | 0 .../escaped-bpid/layers/config/metadata.toml | 0 .../layers/some_escaped_bp_id/some-layer.toml | 0 .../some_escaped_bp_id/some-layer/some-file | 0 .../testdata}/exporter/launcher | 0 .../launcher-sbom/layers/config/metadata.toml | 0 .../some-launcher-sbom-dir/a-regular-file.txt | 0 .../some-sbom-file.sbom.spdx.json | 0 .../layers/app/.hidden.txt | 0 .../layers/app/subdir/myfile.txt | 0 .../layers/app/test_app.sh | 0 .../layers/app/test_app_real.sh | 0 .../layers/bad.buildpack.id/bad-layer.toml | 0 .../bad.buildpack.id/bad-layer/layer5contents | 0 .../launch-layer-no-local-dir.toml | 0 .../layers/buildpack.id/launch.toml | 0 .../layers/buildpack.id/new-launch-layer.toml | 0 .../file-from-new-launch-layer | 0 .../layers/config/metadata.toml | 0 .../layers/old.buildpack.id/bad-layer.toml | 0 .../old.buildpack.id/bad-layer/layer5contents | 0 .../local-reusable-layer.toml | 0 .../local-reusable-layer/layer5contents | 0 .../other.buildpack.id/new-launch-layer.toml | 0 .../new-launch-layer/new-launch-layer-file | 0 .../sbom/launch/buildpack.id/bom.cdx.json | 0 .../layers/app/.hidden.txt | 0 .../layers/app/metadata.toml | 0 .../layers/app/test_app.sh | 0 .../layers/buildpack.id/layer1.toml | 0 .../buildpack.id/layer1/file-from-layer-1 | 0 .../layers/buildpack.id/layer2.toml | 0 .../buildpack.id/layer2/file-from-layer-2 | 0 .../layers/config/metadata.toml | 0 .../launch-true-layer/bom.cdx.json | 0 .../cache-false/file-from-cache-false-layer | 0 .../cache-launch/file-from-cache-launch-layer | 0 .../cache-only/file-from-cache-only-layer | 0 .../escaped-bp-layer/file-from-escaped-bp | 0 .../some-layer/file-from-some-layer | 0 .../testmock}/auth/mock_keychain.go | 0 {testmock => phase/testmock}/build_env.go | 2 +- .../testmock}/build_executor.go | 0 .../testmock}/buildpack_api_verifier.go | 2 +- .../testmock}/cache/image_comparer.go | 0 .../testmock}/cache/image_deleter.go | 0 {testmock => phase/testmock}/cache_handler.go | 8 +-- .../testmock}/component_descriptor.go | 16 +++++ .../testmock}/config_handler.go | 2 +- .../testmock}/detect_executor.go | 0 .../testmock}/detect_resolver.go | 4 +- {testmock => phase/testmock}/dir_store.go | 2 +- .../testmock}/dockerfile_applier.go | 2 +- .../testmock}/generate_executor.go | 0 {testmock => phase/testmock}/image_handler.go | 0 {testmock => phase/testmock}/layer_factory.go | 2 +- .../testmock}/metadata_restorer.go | 2 +- {testmock => phase/testmock}/ref.go | 0 .../testmock}/registry_handler.go | 2 +- {testmock => phase/testmock}/sbom_restorer.go | 0 utils.go => phase/utils.go | 2 +- utils_test.go => phase/utils_test.go | 10 +-- 168 files changed, 322 insertions(+), 239 deletions(-) rename analyzer.go => phase/analyzer.go (99%) rename analyzer_test.go => phase/analyzer_test.go (97%) rename builder.go => phase/builder.go (97%) rename builder_test.go => phase/builder_test.go (99%) rename cache.go => phase/cache.go (99%) rename cache_test.go => phase/cache_test.go (96%) rename detector.go => phase/detector.go (97%) rename detector_test.go => phase/detector_test.go (97%) rename exporter.go => phase/exporter.go (99%) rename exporter_test.go => phase/exporter_test.go (99%) rename extender.go => phase/extender.go (98%) rename extender_test.go => phase/extender_test.go (96%) rename generator.go => phase/generator.go (99%) rename generator_test.go => phase/generator_test.go (98%) rename handlers.go => phase/handlers.go (78%) rename handlers_test.go => phase/handlers_test.go (91%) create mode 100644 phase/phase.go rename rebaser.go => phase/rebaser.go (99%) rename rebaser_test.go => phase/rebaser_test.go (99%) rename restorer.go => phase/restorer.go (99%) rename restorer_test.go => phase/restorer_test.go (98%) rename save.go => phase/save.go (99%) rename {testdata => phase/testdata}/analyzer/app_metadata.json (100%) rename {testdata => phase/testdata}/analyzer/cache_inconsistent_metadata.json (100%) rename {testdata => phase/testdata}/analyzer/cache_metadata.json (100%) rename {testdata => phase/testdata}/cacher/invalid-layers/buildpack.id/cache-true-no-contents.toml (100%) rename {testdata => phase/testdata}/cacher/invalid-layers/buildpack.id/layer-1.toml (100%) rename {testdata => phase/testdata}/cacher/invalid-layers/buildpack.id/layer-1/layer-1-file (100%) rename {testdata => phase/testdata}/cacher/invalid-layers/buildpack.id/layer-2.toml (100%) rename {testdata => phase/testdata}/cacher/invalid-layers/buildpack.id/layer-2/layer-2-file (100%) rename {testdata => phase/testdata}/cacher/layers/buildpack.id/cache-false-layer.toml (100%) rename {testdata => phase/testdata}/cacher/layers/buildpack.id/cache-false-layer/file-from-cache-false-layer (100%) rename {testdata => phase/testdata}/cacher/layers/buildpack.id/cache-true-layer.sha (100%) rename {testdata => phase/testdata}/cacher/layers/buildpack.id/cache-true-layer.toml (100%) rename {testdata => phase/testdata}/cacher/layers/buildpack.id/cache-true-layer/file-from-cache-true-layer (100%) rename {testdata => phase/testdata}/cacher/layers/buildpack.id/cache-true-no-sha-layer.toml (100%) rename {testdata => phase/testdata}/cacher/layers/buildpack.id/cache-true-no-sha-layer/file-from-cache-true-no-sha-layer (100%) rename {testdata => phase/testdata}/cacher/layers/old.buildpack.id/cache-true-layer.sha (100%) rename {testdata => phase/testdata}/cacher/layers/old.buildpack.id/cache-true-layer.toml (100%) rename {testdata => phase/testdata}/cacher/layers/old.buildpack.id/cache-true-layer/file-from-cache-true-layer (100%) rename {testdata => phase/testdata}/cacher/layers/other.buildpack.id/other-buildpack-layer.toml (100%) rename {testdata => phase/testdata}/cacher/layers/other.buildpack.id/other-buildpack-layer/other-buildpack-layer-file (100%) rename {testdata => phase/testdata}/cacher/layers/sbom/cache/buildpack.id/cache-true-layer/bom.cdx.json (100%) rename {testdata => phase/testdata}/cred_helpers/config1.json (100%) rename {testdata => phase/testdata}/cred_helpers/config2.json (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/app/.hidden.txt (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/app/static/assets/config.txt (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/app/static/assets/logo.svg (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/app/static/misc/resources/reports/numbers.csv (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/app/static/misc/resources/reports/report.tps (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/app/test_app.sh (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/buildpack.id/layer1.toml (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/buildpack.id/layer1/file-from-layer-1 (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/buildpack.id/layer2.toml (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/buildpack.id/layer2/file-from-layer-2 (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer.toml (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer/layer5contents (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/other.buildpack.id/new-launch-layer.toml (100%) rename {testdata => phase/testdata}/exporter/app-slices/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file (100%) rename {testdata => phase/testdata}/exporter/bad-layer/layers/app/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/bad-layer/layers/app/test_app.sh (100%) rename {testdata => phase/testdata}/exporter/bad-layer/layers/buildpack.id/bad-layer.toml (100%) rename {testdata => phase/testdata}/exporter/bad-layer/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/build-metadata/bad-layers/buildpack.id/build.toml (100%) rename {testdata => phase/testdata}/exporter/build-metadata/bad-layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/build-metadata/bad-layers/other.buildpack.id/build.toml (100%) rename {testdata => phase/testdata}/exporter/build-metadata/layers/buildpack.id/build.toml (100%) rename {testdata => phase/testdata}/exporter/build-metadata/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/build-metadata/layers/other.buildpack.id/build.toml (100%) rename {testdata => phase/testdata}/exporter/cache-layer-no-contents/layers/app/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/cache-layer-no-contents/layers/app/test_app.sh (100%) rename {testdata => phase/testdata}/exporter/cache-layer-no-contents/layers/buildpack.id/cache-layer-no-contents.toml (100%) rename {testdata => phase/testdata}/exporter/cache-layer-no-contents/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/cleanup-cache/layers/buildpack.id/no-toml-layer/file-for-invalid-layer (100%) rename {testdata => phase/testdata}/exporter/default-process/metadata-with-default/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/default-process/metadata-with-no-default/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/empty-metadata/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/escaped-bpid/layers/app/app (100%) rename {testdata => phase/testdata}/exporter/escaped-bpid/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer.toml (100%) rename {testdata => phase/testdata}/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer/some-file (100%) rename {testdata => phase/testdata}/exporter/launcher (100%) rename {testdata => phase/testdata}/exporter/launcher-sbom/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/launcher-sbom/layers/some-launcher-sbom-dir/a-regular-file.txt (100%) rename {testdata => phase/testdata}/exporter/launcher-sbom/layers/some-launcher-sbom-dir/some-sbom-file.sbom.spdx.json (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/app/.hidden.txt (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/app/subdir/myfile.txt (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/app/test_app.sh (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/app/test_app_real.sh (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer/layer5contents (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/buildpack.id/launch-layer-no-local-dir.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/buildpack.id/launch.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer/file-from-new-launch-layer (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer/layer5contents (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer/layer5contents (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file (100%) rename {testdata => phase/testdata}/exporter/previous-image-exists/layers/sbom/launch/buildpack.id/bom.cdx.json (100%) rename {testdata => phase/testdata}/exporter/previous-image-not-exist/layers/app/.hidden.txt (100%) rename {testdata => phase/testdata}/exporter/previous-image-not-exist/layers/app/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-not-exist/layers/app/test_app.sh (100%) rename {testdata => phase/testdata}/exporter/previous-image-not-exist/layers/buildpack.id/layer1.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-not-exist/layers/buildpack.id/layer1/file-from-layer-1 (100%) rename {testdata => phase/testdata}/exporter/previous-image-not-exist/layers/buildpack.id/layer2.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-not-exist/layers/buildpack.id/layer2/file-from-layer-2 (100%) rename {testdata => phase/testdata}/exporter/previous-image-not-exist/layers/config/metadata.toml (100%) rename {testdata => phase/testdata}/exporter/previous-image-not-exist/layers/sbom/launch/buildpack.id/launch-true-layer/bom.cdx.json (100%) rename {testdata => phase/testdata}/restorer/buildpack.id/cache-false/file-from-cache-false-layer (100%) rename {testdata => phase/testdata}/restorer/buildpack.id/cache-launch/file-from-cache-launch-layer (100%) rename {testdata => phase/testdata}/restorer/buildpack.id/cache-only/file-from-cache-only-layer (100%) rename {testdata => phase/testdata}/restorer/escaped_buildpack_id/escaped-bp-layer/file-from-escaped-bp (100%) rename {testdata => phase/testdata}/restorer/nogroup.buildpack.id/some-layer/file-from-some-layer (100%) rename {testmock => phase/testmock}/auth/mock_keychain.go (100%) rename {testmock => phase/testmock}/build_env.go (97%) rename {testmock => phase/testmock}/build_executor.go (100%) rename {testmock => phase/testmock}/buildpack_api_verifier.go (95%) rename {testmock => phase/testmock}/cache/image_comparer.go (100%) rename {testmock => phase/testmock}/cache/image_deleter.go (100%) rename {testmock => phase/testmock}/cache_handler.go (88%) rename {testmock => phase/testmock}/component_descriptor.go (76%) rename {testmock => phase/testmock}/config_handler.go (97%) rename {testmock => phase/testmock}/detect_executor.go (100%) rename {testmock => phase/testmock}/detect_resolver.go (92%) rename {testmock => phase/testmock}/dir_store.go (97%) rename {testmock => phase/testmock}/dockerfile_applier.go (97%) rename {testmock => phase/testmock}/generate_executor.go (100%) rename {testmock => phase/testmock}/image_handler.go (100%) rename {testmock => phase/testmock}/layer_factory.go (97%) rename {testmock => phase/testmock}/metadata_restorer.go (97%) rename {testmock => phase/testmock}/ref.go (100%) rename {testmock => phase/testmock}/registry_handler.go (96%) rename {testmock => phase/testmock}/sbom_restorer.go (100%) rename utils.go => phase/utils.go (95%) rename utils_test.go => phase/utils_test.go (78%) diff --git a/acceptance/restorer_test.go b/acceptance/restorer_test.go index 8ec3ec5ad..60e06eb2d 100644 --- a/acceptance/restorer_test.go +++ b/acceptance/restorer_test.go @@ -14,9 +14,9 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/cmd" + "github.com/buildpacks/lifecycle/phase" h "github.com/buildpacks/lifecycle/testhelpers" ) @@ -198,7 +198,7 @@ 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"), cmd.DefaultLogger) + analyzedMD, err := phase.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") @@ -230,7 +230,7 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe ), ) 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) + analyzedMD, err := phase.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.Image, restoreRegFixtures.ReadOnlyRunImage) @@ -266,7 +266,7 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe ) if api.MustParse(platformAPI).AtLeast("0.12") { 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) + analyzedMD, err := phase.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.Image, restoreRegFixtures.ReadOnlyRunImage) @@ -279,7 +279,7 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe h.AssertEq(t, len(fis), 1) // .gitkeep } else { t.Log("doesn't update analyzed.toml") - analyzedMD, err := lifecycle.Config.ReadAnalyzed(filepath.Join(copyDir, "layers", "some-extend-false-analyzed.toml"), cmd.DefaultLogger) + analyzedMD, err := phase.Config.ReadAnalyzed(filepath.Join(copyDir, "layers", "some-extend-false-analyzed.toml"), cmd.DefaultLogger) h.AssertNil(t, err) h.AssertNil(t, analyzedMD.RunImage.TargetMetadata) } @@ -306,7 +306,7 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe ), ) 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) + analyzedMD, err := phase.Config.ReadAnalyzed(filepath.Join(copyDir, "layers", "some-extend-false-analyzed.toml"), cmd.DefaultLogger) h.AssertNil(t, err) h.AssertStringDoesNotContain(t, analyzedMD.RunImage.Reference, "@sha256:") // daemon image ID h.AssertEq(t, analyzedMD.RunImage.Image, restoreRegFixtures.ReadOnlyRunImage) diff --git a/buildpack/build.go b/buildpack/build.go index f5e3258c5..0e757e330 100644 --- a/buildpack/build.go +++ b/buildpack/build.go @@ -56,7 +56,11 @@ type BuildOutputs struct { Slices []layers.Slice } -//go:generate mockgen -package testmock -destination ../testmock/build_executor.go github.com/buildpacks/lifecycle/buildpack BuildExecutor +// BuildExecutor executes a single buildpack's `./bin/build` binary, +// providing inputs as defined in the Buildpack Interface Specification, +// and processing outputs for the platform. +// +//go:generate mockgen -package testmock -destination ../phase/testmock/build_executor.go github.com/buildpacks/lifecycle/buildpack BuildExecutor type BuildExecutor interface { Build(d BpDescriptor, inputs BuildInputs, logger log.Logger) (BuildOutputs, error) } diff --git a/buildpack/build_test.go b/buildpack/build_test.go index e6ce3420c..a28b31017 100644 --- a/buildpack/build_test.go +++ b/buildpack/build_test.go @@ -24,11 +24,11 @@ import ( "github.com/buildpacks/lifecycle/launch" "github.com/buildpacks/lifecycle/layers" llog "github.com/buildpacks/lifecycle/log" + "github.com/buildpacks/lifecycle/phase/testmock" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) -//go:generate mockgen -package testmock -destination testmock/env.go github.com/buildpacks/lifecycle BuildEnv +//go:generate mockgen -package testmock -destination testmock/env.go github.com/buildpacks/lifecycle/phase BuildEnv func TestBuild(t *testing.T) { spec.Run(t, "unit-build", testBuild, spec.Report(report.Terminal{})) diff --git a/buildpack/descriptor.go b/buildpack/descriptor.go index fbba8bff5..0ea297014 100644 --- a/buildpack/descriptor.go +++ b/buildpack/descriptor.go @@ -5,7 +5,10 @@ const ( KindExtension = "Extension" ) -//go:generate mockgen -package testmock -destination ../testmock/component_descriptor.go github.com/buildpacks/lifecycle/buildpack Descriptor +// Descriptor exposes information contained in a buildpack.toml or extension.toml +// that is generic to buildpacks and/or image extensions. +// +//go:generate mockgen -package testmock -destination ../lifecycle/testmock/component_descriptor.go github.com/buildpacks/lifecycle/buildpack Descriptor type Descriptor interface { API() string Homepage() string diff --git a/buildpack/detect.go b/buildpack/detect.go index f23c5ef62..80716d5dd 100644 --- a/buildpack/detect.go +++ b/buildpack/detect.go @@ -39,7 +39,12 @@ type DetectOutputs struct { Err error `toml:"-"` } -//go:generate mockgen -package testmock -destination ../testmock/detect_executor.go github.com/buildpacks/lifecycle/buildpack DetectExecutor +// DetectExecutor executes a single buildpack or image extension's `./bin/detect` binary, +// providing inputs as defined in the Buildpack Interface Specification, +// and processing outputs for the platform. +// For image extensions (where `./bin/detect` is optional), pre-populated outputs are processed here. +// +//go:generate mockgen -package testmock -destination ../phase/testmock/detect_executor.go github.com/buildpacks/lifecycle/buildpack DetectExecutor type DetectExecutor interface { Detect(d Descriptor, inputs DetectInputs, logger log.Logger) DetectOutputs } diff --git a/buildpack/generate.go b/buildpack/generate.go index acfeaf89a..ba32596d4 100644 --- a/buildpack/generate.go +++ b/buildpack/generate.go @@ -34,7 +34,12 @@ type GenerateOutputs struct { MetRequires []string } -//go:generate mockgen -package testmock -destination ../testmock/generate_executor.go github.com/buildpacks/lifecycle/buildpack GenerateExecutor +// GenerateExecutor executes a single image extension's `./bin/generate` binary, +// providing inputs as defined in the Buildpack Interface Specification, +// and processing outputs for the platform. +// Pre-populated outputs for image extensions that are missing `./bin/generate` are processed here. +// +//go:generate mockgen -package testmock -destination ../phase/testmock/generate_executor.go github.com/buildpacks/lifecycle/buildpack GenerateExecutor type GenerateExecutor interface { Generate(d ExtDescriptor, inputs GenerateInputs, logger log.Logger) (GenerateOutputs, error) } diff --git a/buildpack/generate_test.go b/buildpack/generate_test.go index f71f78e64..b8539ccdd 100644 --- a/buildpack/generate_test.go +++ b/buildpack/generate_test.go @@ -19,8 +19,8 @@ import ( "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/buildpack" llog "github.com/buildpacks/lifecycle/log" + "github.com/buildpacks/lifecycle/phase/testmock" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) func TestGenerate(t *testing.T) { diff --git a/buildpack/testmock/env.go b/buildpack/testmock/env.go index 6fc83b109..59526c8d3 100644 --- a/buildpack/testmock/env.go +++ b/buildpack/testmock/env.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: BuildEnv) +// Source: github.com/buildpacks/lifecycle/phase (interfaces: BuildEnv) // Package testmock is a generated GoMock package. package testmock diff --git a/cache/image_cache_test.go b/cache/image_cache_test.go index 4d1d7d767..d3fcb2d16 100644 --- a/cache/image_cache_test.go +++ b/cache/image_cache_test.go @@ -7,8 +7,6 @@ import ( "path/filepath" "testing" - cacheMock "github.com/buildpacks/lifecycle/testmock/cache" - "github.com/golang/mock/gomock" "github.com/buildpacks/imgutil/fakes" @@ -20,6 +18,7 @@ import ( "github.com/buildpacks/lifecycle/cache" "github.com/buildpacks/lifecycle/cmd" "github.com/buildpacks/lifecycle/log" + testmockcache "github.com/buildpacks/lifecycle/phase/testmock/cache" "github.com/buildpacks/lifecycle/platform" h "github.com/buildpacks/lifecycle/testhelpers" ) @@ -48,8 +47,8 @@ func testImageCache(t *testing.T, when spec.G, it spec.S) { fakeOriginalImage = fakes.NewImage("fake-image", "", local.IDIdentifier{ImageID: "fakeOriginalImage"}) fakeNewImage = fakes.NewImage("fake-image", "", local.IDIdentifier{ImageID: "fakeImage"}) mockController := gomock.NewController(t) - fakeImageDeleter := cacheMock.NewMockImageDeleter(mockController) - fakeImageComparer := cacheMock.NewMockImageComparer(mockController) + fakeImageDeleter := testmockcache.NewMockImageDeleter(mockController) + fakeImageComparer := testmockcache.NewMockImageComparer(mockController) fakeImageComparer.EXPECT().ImagesEq(gomock.Any(), gomock.Any()).AnyTimes().Return(false, nil) fakeImageDeleter.EXPECT().DeleteOrigImageIfDifferentFromNewImage(gomock.Any(), gomock.Any()).AnyTimes() testLogger = cmd.DefaultLogger diff --git a/cache/image_comparer.go b/cache/image_comparer.go index cbac626ca..5faa2a331 100644 --- a/cache/image_comparer.go +++ b/cache/image_comparer.go @@ -5,7 +5,7 @@ import ( "github.com/pkg/errors" ) -//go:generate mockgen -package testmockcache -destination ../testmock/cache/image_comparer.go github.com/buildpacks/lifecycle/cache ImageComparer +//go:generate mockgen -package testmockcache -destination ../lifecycle/testmock/cache/image_comparer.go github.com/buildpacks/lifecycle/cache ImageComparer // ImageComparer provides a way to compare images type ImageComparer interface { diff --git a/cache/image_deleter.go b/cache/image_deleter.go index afde27f80..8807715d1 100644 --- a/cache/image_deleter.go +++ b/cache/image_deleter.go @@ -7,7 +7,7 @@ import ( "github.com/buildpacks/lifecycle/log" ) -//go:generate mockgen -package testmockcache -destination ../testmock/cache/image_deleter.go github.com/buildpacks/lifecycle/cache ImageDeleter +//go:generate mockgen -package testmockcache -destination ../phase/testmock/cache/image_deleter.go github.com/buildpacks/lifecycle/cache ImageDeleter // ImageDeleter defines the methods available to delete and compare cached images type ImageDeleter interface { diff --git a/cache/image_deleter_test.go b/cache/image_deleter_test.go index 1bc9009f2..515314edf 100644 --- a/cache/image_deleter_test.go +++ b/cache/image_deleter_test.go @@ -13,8 +13,8 @@ import ( "github.com/buildpacks/lifecycle/cmd" "github.com/buildpacks/lifecycle/log" + cacheMock "github.com/buildpacks/lifecycle/phase/testmock/cache" h "github.com/buildpacks/lifecycle/testhelpers" - cacheMock "github.com/buildpacks/lifecycle/testmock/cache" ) func TestImageDeleter(t *testing.T) { diff --git a/cmd/apis.go b/cmd/apis.go index f4a99f9f3..1a5838611 100644 --- a/cmd/apis.go +++ b/cmd/apis.go @@ -24,37 +24,45 @@ var DeprecationMode = EnvOrDefault(EnvDeprecationMode, DefaultDeprecationMode) type BuildpackAPIVerifier struct{} -func (v *BuildpackAPIVerifier) VerifyBuildpackAPI(kind, name, requested string, logger log.Logger) error { - return VerifyBuildpackAPI(kind, name, requested, logger) +// VerifyBuildpackAPI given a Buildpack API version and relevant information for logging +// will error if the requested version is unsupported, +// and will log a warning, error, or do nothing if the requested version is deprecated, +// depending on if the configured deprecation mode is "warn", "error", or "silent", respectively. +func (v *BuildpackAPIVerifier) VerifyBuildpackAPI(kind, name, requestedVersion string, logger log.Logger) error { + return VerifyBuildpackAPI(kind, name, requestedVersion, logger) } -func VerifyBuildpackAPI(kind, name, requested string, logger log.Logger) error { - requestedAPI, err := api.NewVersion(requested) +// VerifyBuildpackAPI given a Buildpack API version and relevant information for logging +// will error if the requested version is unsupported, +// and will log a warning, error, or do nothing if the requested version is deprecated, +// depending on if the configured deprecation mode is "warn", "error", or "silent", respectively. +func VerifyBuildpackAPI(kind, name, requestedVersion string, logger log.Logger) error { + requested, err := api.NewVersion(requestedVersion) if err != nil { return FailErrCode( nil, CodeForIncompatibleBuildpackAPI, - fmt.Sprintf("parse buildpack API '%s' for %s '%s'", requestedAPI, strings.ToLower(kind), name), + fmt.Sprintf("parse buildpack API '%s' for %s '%s'", requested, strings.ToLower(kind), name), ) } - if api.Buildpack.IsSupported(requestedAPI) { - if api.Buildpack.IsDeprecated(requestedAPI) { + if api.Buildpack.IsSupported(requested) { + if api.Buildpack.IsDeprecated(requested) { switch DeprecationMode { case ModeQuiet: break case ModeError: - logger.Errorf("%s '%s' requests deprecated API '%s'", kind, name, requested) + logger.Errorf("%s '%s' requests deprecated API '%s'", kind, name, requestedVersion) logger.Errorf("Deprecated APIs are disabled by %s=%s", EnvDeprecationMode, ModeError) - return buildpackAPIError(kind, name, requested) + return buildpackAPIError(kind, name, requestedVersion) case ModeWarn: - logger.Warnf("%s '%s' requests deprecated API '%s'", kind, name, requested) + logger.Warnf("%s '%s' requests deprecated API '%s'", kind, name, requestedVersion) default: - logger.Warnf("%s '%s' requests deprecated API '%s'", kind, name, requested) + logger.Warnf("%s '%s' requests deprecated API '%s'", kind, name, requestedVersion) } } return nil } - return buildpackAPIError(kind, name, requested) + return buildpackAPIError(kind, name, requestedVersion) } func buildpackAPIError(moduleKind string, name string, requested string) error { @@ -65,40 +73,44 @@ func buildpackAPIError(moduleKind string, name string, requested string) error { ) } -func VerifyPlatformAPI(requested string, logger log.Logger) error { - if strings.TrimSpace(requested) == "" { +// VerifyPlatformAPI given a Platform API version and relevant information for logging +// will error if the requested version is unsupported, +// and will log a warning, error, or do nothing if the requested version is deprecated, +// depending on if the configured deprecation mode is "warn", "error", or "silent", respectively. +func VerifyPlatformAPI(requestedVersion string, logger log.Logger) error { + if strings.TrimSpace(requestedVersion) == "" { return FailErrCode( nil, CodeForIncompatiblePlatformAPI, fmt.Sprintf("get platform API version; please set '%s' to specify the desired platform API version", EnvPlatformAPI), ) } - requestedAPI, err := api.NewVersion(requested) + requested, err := api.NewVersion(requestedVersion) if err != nil { return FailErrCode( nil, CodeForIncompatiblePlatformAPI, - fmt.Sprintf("parse platform API '%s'", requested), + fmt.Sprintf("parse platform API '%s'", requestedVersion), ) } - if api.Platform.IsSupported(requestedAPI) { - if api.Platform.IsDeprecated(requestedAPI) { + if api.Platform.IsSupported(requested) { + if api.Platform.IsDeprecated(requested) { switch DeprecationMode { case ModeQuiet: break case ModeError: - logger.Errorf("Platform requested deprecated API '%s'", requested) + logger.Errorf("Platform requested deprecated API '%s'", requestedVersion) logger.Errorf("Deprecated APIs are disabled by %s=%s", EnvDeprecationMode, ModeError) - return platformAPIError(requested) + return platformAPIError(requestedVersion) case ModeWarn: - logger.Warnf("Platform requested deprecated API '%s'", requested) + logger.Warnf("Platform requested deprecated API '%s'", requestedVersion) default: - logger.Warnf("Platform requested deprecated API '%s'", requested) + logger.Warnf("Platform requested deprecated API '%s'", requestedVersion) } } return nil } - return platformAPIError(requested) + return platformAPIError(requestedVersion) } func platformAPIError(requested string) error { diff --git a/cmd/lifecycle/analyzer.go b/cmd/lifecycle/analyzer.go index 070a1d169..33deba288 100644 --- a/cmd/lifecycle/analyzer.go +++ b/cmd/lifecycle/analyzer.go @@ -3,16 +3,15 @@ package main import ( "fmt" - "github.com/buildpacks/lifecycle/image" - "github.com/buildpacks/lifecycle/internal/encoding" - "github.com/docker/docker/client" "github.com/google/go-containerregistry/pkg/authn" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/auth" "github.com/buildpacks/lifecycle/cmd" "github.com/buildpacks/lifecycle/cmd/lifecycle/cli" + "github.com/buildpacks/lifecycle/image" + "github.com/buildpacks/lifecycle/internal/encoding" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/priv" ) @@ -97,11 +96,11 @@ func (a *analyzeCmd) Privileges() error { // Exec executes the command. func (a *analyzeCmd) Exec() error { - factory := lifecycle.NewAnalyzerFactory( + factory := phase.NewAnalyzerFactory( a.PlatformAPI, &cmd.BuildpackAPIVerifier{}, NewCacheHandler(a.keychain), - lifecycle.NewConfigHandler(), + phase.NewConfigHandler(), image.NewHandler(a.docker, a.keychain, a.LayoutDir, a.UseLayout, a.InsecureRegistries), image.NewRegistryHandler(a.keychain, a.InsecureRegistries), ) diff --git a/cmd/lifecycle/builder.go b/cmd/lifecycle/builder.go index 06d56fc58..50b78eaa2 100644 --- a/cmd/lifecycle/builder.go +++ b/cmd/lifecycle/builder.go @@ -5,12 +5,12 @@ import ( "github.com/BurntSushi/toml" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cmd" "github.com/buildpacks/lifecycle/cmd/lifecycle/cli" "github.com/buildpacks/lifecycle/internal/encoding" "github.com/buildpacks/lifecycle/launch" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/platform/files" "github.com/buildpacks/lifecycle/priv" @@ -74,7 +74,7 @@ func (b *buildCmd) Exec() error { } func (b *buildCmd) build(group buildpack.Group, plan files.Plan, analyzedMD files.Analyzed) error { - builder := &lifecycle.Builder{ + builder := &phase.Builder{ AppDir: b.AppDir, BuildConfigDir: b.BuildConfigDir, LayersDir: b.LayersDir, @@ -109,7 +109,7 @@ func (b *buildCmd) unwrapBuildFail(err error) error { } func (b *buildCmd) readData() (buildpack.Group, files.Plan, error) { - group, err := lifecycle.ReadGroup(b.GroupPath) + group, err := phase.ReadGroup(b.GroupPath) if err != nil { return buildpack.Group{}, files.Plan{}, cmd.FailErr(err, "read buildpack group") } diff --git a/cmd/lifecycle/creator.go b/cmd/lifecycle/creator.go index 531da1d31..223718f4d 100644 --- a/cmd/lifecycle/creator.go +++ b/cmd/lifecycle/creator.go @@ -5,19 +5,18 @@ import ( "fmt" "time" - "github.com/buildpacks/lifecycle/image" - "github.com/buildpacks/lifecycle/platform/files" - "github.com/docker/docker/client" "github.com/google/go-containerregistry/pkg/authn" "github.com/pkg/errors" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/auth" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cmd" "github.com/buildpacks/lifecycle/cmd/lifecycle/cli" + "github.com/buildpacks/lifecycle/image" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" + "github.com/buildpacks/lifecycle/platform/files" "github.com/buildpacks/lifecycle/priv" ) @@ -124,11 +123,11 @@ func (c *createCmd) Exec() error { plan files.Plan ) cmd.DefaultLogger.Phase("ANALYZING") - analyzerFactory := lifecycle.NewAnalyzerFactory( + analyzerFactory := phase.NewAnalyzerFactory( c.PlatformAPI, &cmd.BuildpackAPIVerifier{}, NewCacheHandler(c.keychain), - lifecycle.NewConfigHandler(), + phase.NewConfigHandler(), image.NewHandler(c.docker, c.keychain, c.LayoutDir, c.UseLayout, c.InsecureRegistries), image.NewRegistryHandler(c.keychain, c.InsecureRegistries), ) @@ -143,10 +142,10 @@ func (c *createCmd) Exec() error { // Detect cmd.DefaultLogger.Phase("DETECTING") - detectorFactory := lifecycle.NewDetectorFactory( + detectorFactory := phase.NewDetectorFactory( c.PlatformAPI, &cmd.BuildpackAPIVerifier{}, - lifecycle.NewConfigHandler(), + phase.NewConfigHandler(), dirStore, ) detector, err := detectorFactory.NewDetector(analyzedMD, c.AppDir, c.BuildConfigDir, c.OrderPath, c.PlatformDir, cmd.DefaultLogger) diff --git a/cmd/lifecycle/detector.go b/cmd/lifecycle/detector.go index 2fdff6528..3be1dcfd6 100644 --- a/cmd/lifecycle/detector.go +++ b/cmd/lifecycle/detector.go @@ -3,11 +3,11 @@ package main import ( "errors" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cmd" "github.com/buildpacks/lifecycle/cmd/lifecycle/cli" "github.com/buildpacks/lifecycle/internal/encoding" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/platform/files" "github.com/buildpacks/lifecycle/priv" @@ -60,10 +60,10 @@ func (d *detectCmd) Privileges() error { func (d *detectCmd) Exec() error { dirStore := platform.NewDirStore(d.BuildpacksDir, d.ExtensionsDir) - detectorFactory := lifecycle.NewDetectorFactory( + detectorFactory := phase.NewDetectorFactory( d.PlatformAPI, &cmd.BuildpackAPIVerifier{}, - lifecycle.NewConfigHandler(), + phase.NewConfigHandler(), dirStore, ) amd, err := files.ReadAnalyzed(d.AnalyzedPath, cmd.DefaultLogger) @@ -91,12 +91,12 @@ func (d *detectCmd) Exec() error { return err // pass through error } if group.HasExtensions() { - generatorFactory := lifecycle.NewGeneratorFactory( + generatorFactory := phase.NewGeneratorFactory( &cmd.BuildpackAPIVerifier{}, - lifecycle.Config, + phase.Config, dirStore, ) - var generator *lifecycle.Generator + var generator *phase.Generator generator, err = generatorFactory.NewGenerator( d.AnalyzedPath, d.AppDir, @@ -113,7 +113,7 @@ func (d *detectCmd) Exec() error { if err != nil { return unwrapErrorFailWithMessage(err, "initialize generator") } - var result lifecycle.GenerateResult + var result phase.GenerateResult result, err = generator.Generate() if err != nil { return d.unwrapGenerateFail(err) @@ -147,7 +147,7 @@ func (d *detectCmd) unwrapGenerateFail(err error) error { return cmd.FailErrCode(err, d.CodeFor(platform.GenerateError), "build") } -func doDetect(detector *lifecycle.Detector, p *platform.Platform) (buildpack.Group, files.Plan, error) { +func doDetect(detector *phase.Detector, p *platform.Platform) (buildpack.Group, files.Plan, error) { group, plan, err := detector.Detect() if err != nil { switch err := err.(type) { diff --git a/cmd/lifecycle/exporter.go b/cmd/lifecycle/exporter.go index bc9006e9e..a95a9005c 100644 --- a/cmd/lifecycle/exporter.go +++ b/cmd/lifecycle/exporter.go @@ -20,7 +20,6 @@ import ( v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/pkg/errors" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/auth" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cache" @@ -29,6 +28,7 @@ import ( "github.com/buildpacks/lifecycle/image" "github.com/buildpacks/lifecycle/internal/encoding" "github.com/buildpacks/lifecycle/layers" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/platform/files" "github.com/buildpacks/lifecycle/priv" @@ -131,7 +131,7 @@ func (e *exportCmd) Privileges() error { } func (e *exportCmd) Exec() error { - group, err := lifecycle.ReadGroup(e.GroupPath) + group, err := phase.ReadGroup(e.GroupPath) if err != nil { return cmd.FailErr(err, "read buildpack group") } @@ -160,7 +160,7 @@ func (e *exportCmd) registryImages() []string { return registryImages } -func (e *exportCmd) export(group buildpack.Group, cacheStore lifecycle.Cache, analyzedMD files.Analyzed) error { +func (e *exportCmd) export(group buildpack.Group, cacheStore phase.Cache, analyzedMD files.Analyzed) error { artifactsDir, err := os.MkdirTemp("", "lifecycle.exporter.layer") if err != nil { @@ -177,7 +177,7 @@ func (e *exportCmd) export(group buildpack.Group, cacheStore lifecycle.Cache, an cmd.DefaultLogger.Debugf("no project metadata found at path '%s', project metadata will not be exported\n", e.ProjectMetadataPath) } - exporter := &lifecycle.Exporter{ + exporter := &phase.Exporter{ Buildpacks: group.Group, LayerFactory: &layers.Factory{ ArtifactsDir: artifactsDir, @@ -210,7 +210,7 @@ func (e *exportCmd) export(group buildpack.Group, cacheStore lifecycle.Cache, an return err } - report, err := exporter.Export(lifecycle.ExportOptions{ + report, err := exporter.Export(phase.ExportOptions{ AdditionalNames: e.AdditionalTags, AppDir: e.AppDir, DefaultProcessType: e.DefaultProcessType, @@ -451,8 +451,8 @@ func (e *exportCmd) initLayoutAppImage(analyzedMD files.Analyzed) (imgutil.Image return appImage, runImageID.String(), nil } -func launcherConfig(launcherPath, launcherSBOMDir string) lifecycle.LauncherConfig { - return lifecycle.LauncherConfig{ +func launcherConfig(launcherPath, launcherSBOMDir string) phase.LauncherConfig { + return phase.LauncherConfig{ Path: launcherPath, SBOMDir: launcherSBOMDir, Metadata: files.LauncherMetadata{ diff --git a/cmd/lifecycle/extender.go b/cmd/lifecycle/extender.go index fc8ba47b3..4991c95d2 100644 --- a/cmd/lifecycle/extender.go +++ b/cmd/lifecycle/extender.go @@ -4,11 +4,11 @@ import ( "errors" "fmt" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cmd" "github.com/buildpacks/lifecycle/cmd/lifecycle/cli" "github.com/buildpacks/lifecycle/internal/extend/kaniko" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/priv" ) @@ -52,7 +52,7 @@ func (e *extendCmd) Privileges() error { } func (e *extendCmd) Exec() error { - extenderFactory := lifecycle.NewExtenderFactory(&cmd.BuildpackAPIVerifier{}, lifecycle.NewConfigHandler()) + extenderFactory := phase.NewExtenderFactory(&cmd.BuildpackAPIVerifier{}, phase.NewConfigHandler()) applier, err := kaniko.NewDockerfileApplier() if err != nil { return err diff --git a/cmd/lifecycle/main.go b/cmd/lifecycle/main.go index fdcfdc33e..74b51a010 100644 --- a/cmd/lifecycle/main.go +++ b/cmd/lifecycle/main.go @@ -8,11 +8,11 @@ import ( "github.com/google/go-containerregistry/pkg/authn" "github.com/pkg/errors" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cache" "github.com/buildpacks/lifecycle/cmd" "github.com/buildpacks/lifecycle/cmd/lifecycle/cli" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" ) @@ -91,9 +91,9 @@ func NewCacheHandler(keychain authn.Keychain) *DefaultCacheHandler { } // InitCache is a factory used to create either a NewImageCache or a NewVolumeCache -func (ch *DefaultCacheHandler) InitCache(cacheImageRef string, cacheDir string, deletionEnabled bool) (lifecycle.Cache, error) { +func (ch *DefaultCacheHandler) InitCache(cacheImageRef string, cacheDir string, deletionEnabled bool) (phase.Cache, error) { var ( - cacheStore lifecycle.Cache + cacheStore phase.Cache err error ) if cacheImageRef != "" { @@ -113,9 +113,9 @@ func (ch *DefaultCacheHandler) InitCache(cacheImageRef string, cacheDir string, // helpers -func initCache(cacheImageTag, cacheDir string, keychain authn.Keychain, deletionEnabled bool) (lifecycle.Cache, error) { +func initCache(cacheImageTag, cacheDir string, keychain authn.Keychain, deletionEnabled bool) (phase.Cache, error) { var ( - cacheStore lifecycle.Cache + cacheStore phase.Cache err error ) if cacheImageTag != "" { diff --git a/cmd/lifecycle/rebaser.go b/cmd/lifecycle/rebaser.go index 448beb924..c687be4e9 100644 --- a/cmd/lifecycle/rebaser.go +++ b/cmd/lifecycle/rebaser.go @@ -11,12 +11,12 @@ import ( "github.com/google/go-containerregistry/pkg/name" "github.com/pkg/errors" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/auth" "github.com/buildpacks/lifecycle/cmd" "github.com/buildpacks/lifecycle/cmd/lifecycle/cli" "github.com/buildpacks/lifecycle/image" "github.com/buildpacks/lifecycle/internal/encoding" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/platform/files" "github.com/buildpacks/lifecycle/priv" @@ -128,7 +128,7 @@ func (r *rebaseCmd) Exec() error { return cmd.FailErr(err, "access run image") } - rebaser := &lifecycle.Rebaser{ + rebaser := &phase.Rebaser{ Logger: cmd.DefaultLogger, PlatformAPI: r.PlatformAPI, Force: r.ForceRebase, diff --git a/cmd/lifecycle/restorer.go b/cmd/lifecycle/restorer.go index 536d61cd5..82dc4d483 100644 --- a/cmd/lifecycle/restorer.go +++ b/cmd/lifecycle/restorer.go @@ -13,7 +13,6 @@ import ( "github.com/docker/docker/client" "github.com/google/go-containerregistry/pkg/authn" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/auth" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cmd" @@ -21,6 +20,7 @@ import ( "github.com/buildpacks/lifecycle/image" "github.com/buildpacks/lifecycle/internal/encoding" "github.com/buildpacks/lifecycle/internal/layer" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/platform/files" "github.com/buildpacks/lifecycle/priv" @@ -149,7 +149,7 @@ func (r *restoreCmd) Exec() error { cmd.DefaultLogger.Warnf("Not using analyzed data, usable file not found: %s", err) } - group, err := lifecycle.ReadGroup(r.GroupPath) + group, err := phase.ReadGroup(r.GroupPath) if err != nil { return cmd.FailErr(err, "read buildpack group") } @@ -263,8 +263,8 @@ func (r *restoreCmd) pullSparse(imageRef string) (imgutil.Image, error) { return remoteImage, nil } -func (r *restoreCmd) restore(layerMetadata files.LayersMetadata, group buildpack.Group, cacheStore lifecycle.Cache) error { - restorer := &lifecycle.Restorer{ +func (r *restoreCmd) restore(layerMetadata files.LayersMetadata, group buildpack.Group, cacheStore phase.Cache) error { + restorer := &phase.Restorer{ LayersDir: r.LayersDir, Buildpacks: group.Group, Logger: cmd.DefaultLogger, diff --git a/image/handler.go b/image/handler.go index f579f5e78..2705102ed 100644 --- a/image/handler.go +++ b/image/handler.go @@ -7,6 +7,11 @@ import ( "github.com/google/go-containerregistry/pkg/authn" ) +// Handler wraps initialization of an [imgutil] image. +// +// [imgutil]: github.com/buildpacks/imgutil +// +//go:generate mockgen -package testmock -destination ../phase/testmock/image_handler.go github.com/buildpacks/lifecycle/image Handler type Handler interface { InitImage(imageRef string) (imgutil.Image, error) Kind() string diff --git a/image/handler_test.go b/image/handler_test.go index f97ff4f67..d3d1f9602 100644 --- a/image/handler_test.go +++ b/image/handler_test.go @@ -9,11 +9,11 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" + testmockauth "github.com/buildpacks/lifecycle/phase/testmock/auth" h "github.com/buildpacks/lifecycle/testhelpers" - testmockauth "github.com/buildpacks/lifecycle/testmock/auth" ) -//go:generate mockgen -package testmockauth -destination ../testmock/auth/mock_keychain.go github.com/google/go-containerregistry/pkg/authn Keychain +//go:generate mockgen -package testmockauth -destination ../phase/testmock/auth/mock_keychain.go github.com/google/go-containerregistry/pkg/authn Keychain func TestHandler(t *testing.T) { spec.Run(t, "ImageHandler", testHandler, spec.Sequential(), spec.Report(report.Terminal{})) diff --git a/image/registry_handler.go b/image/registry_handler.go index 83ef8578d..076cfcbaa 100644 --- a/image/registry_handler.go +++ b/image/registry_handler.go @@ -10,7 +10,7 @@ import ( // RegistryHandler takes care of the registry settings and checks // -//go:generate mockgen -package testmock -destination testmock/registry_handler.go github.com/buildpacks/lifecycle RegistryHandler +//go:generate mockgen -package testmock -destination ../phase/testmock/registry_handler.go github.com/buildpacks/lifecycle/image RegistryHandler type RegistryHandler interface { EnsureReadAccess(imageRefs ...string) error EnsureWriteAccess(imageRefs ...string) error diff --git a/internal/layer/metadata_restorer.go b/internal/layer/metadata_restorer.go index 831ff1e81..f33e0e17e 100644 --- a/internal/layer/metadata_restorer.go +++ b/internal/layer/metadata_restorer.go @@ -14,7 +14,12 @@ import ( "github.com/buildpacks/lifecycle/platform/files" ) -//go:generate mockgen -package testmock -destination ../../testmock/metadata_restorer.go github.com/buildpacks/lifecycle/internal/layer MetadataRestorer +// MetadataRestorer given a group of buildpacks and metadata from the previous image and cache, +// will create `//.toml` files containing `metadata` that the buildpack previously wrote. +// Note that layer `types` information is not persisted, as the buildpack must opt in to layer re-use +// by editing the provided `.toml` to configure the desired layer type. +// +//go:generate mockgen -package testmock -destination ../../phase/testmock/metadata_restorer.go github.com/buildpacks/lifecycle/internal/layer MetadataRestorer type MetadataRestorer interface { Restore(buildpacks []buildpack.GroupElement, appMeta files.LayersMetadata, cacheMeta platform.CacheMetadata, layerSHAStore SHAStore) error } diff --git a/internal/layer/sbom_restorer.go b/internal/layer/sbom_restorer.go index 5db324ec8..0af736c76 100644 --- a/internal/layer/sbom_restorer.go +++ b/internal/layer/sbom_restorer.go @@ -20,7 +20,12 @@ import ( "github.com/buildpacks/lifecycle/log" ) -//go:generate mockgen -package testmock -destination ../../testmock/sbom_restorer.go github.com/buildpacks/lifecycle/internal/layer SBOMRestorer +// SBOMRestorer handles the restoration of SBOM layer data. +// Given a previous image or cache, it will extract the SBOM layer to the local filesystem. +// Given a group of buildpacks and a `/sbom/` directory, +// it will copy the relevant SBOM files to `// so that they can be used in the current build. +// +//go:generate mockgen -package testmock -destination ../../phase/testmock/sbom_restorer.go github.com/buildpacks/lifecycle/internal/layer SBOMRestorer type SBOMRestorer interface { RestoreFromPrevious(image imgutil.Image, layerDigest string) error RestoreFromCache(cache Cache, layerDigest string) error diff --git a/internal/layer/sbom_restorer_test.go b/internal/layer/sbom_restorer_test.go index 6d50653a0..544b3f296 100644 --- a/internal/layer/sbom_restorer_test.go +++ b/internal/layer/sbom_restorer_test.go @@ -13,13 +13,13 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cache" "github.com/buildpacks/lifecycle/internal/layer" "github.com/buildpacks/lifecycle/launch" "github.com/buildpacks/lifecycle/layers" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/platform/files" h "github.com/buildpacks/lifecycle/testhelpers" @@ -149,7 +149,7 @@ func testSBOMRestorer(t *testing.T, when spec.G, it spec.S) { artifactsDir string cacheDir string layerDigest string - testCache lifecycle.Cache + testCache phase.Cache ) it.Before(func() { diff --git a/analyzer.go b/phase/analyzer.go similarity index 99% rename from analyzer.go rename to phase/analyzer.go index 1321c85b4..e3ec7a77c 100644 --- a/analyzer.go +++ b/phase/analyzer.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "github.com/buildpacks/imgutil" diff --git a/analyzer_test.go b/phase/analyzer_test.go similarity index 97% rename from analyzer_test.go rename to phase/analyzer_test.go index 0c6ba9aa8..73d0c8be3 100644 --- a/analyzer_test.go +++ b/phase/analyzer_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "encoding/json" @@ -15,17 +15,16 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle/image" - "github.com/buildpacks/lifecycle/platform/files" - - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/cache" "github.com/buildpacks/lifecycle/cmd" + "github.com/buildpacks/lifecycle/image" "github.com/buildpacks/lifecycle/internal/layer" + "github.com/buildpacks/lifecycle/phase" + "github.com/buildpacks/lifecycle/phase/testmock" "github.com/buildpacks/lifecycle/platform" + "github.com/buildpacks/lifecycle/platform/files" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) func TestAnalyzer(t *testing.T) { @@ -38,7 +37,7 @@ func TestAnalyzer(t *testing.T) { func testAnalyzerFactory(t *testing.T, when spec.G, it spec.S) { when("#NewAnalyzer", func() { var ( - analyzerFactory *lifecycle.AnalyzerFactory + analyzerFactory *phase.AnalyzerFactory fakeAPIVerifier *testmock.MockBuildpackAPIVerifier fakeCacheHandler *testmock.MockCacheHandler fakeConfigHandler *testmock.MockConfigHandler @@ -69,7 +68,7 @@ func testAnalyzerFactory(t *testing.T, when spec.G, it spec.S) { when("platform api >= 0.8", func() { it.Before(func() { - analyzerFactory = lifecycle.NewAnalyzerFactory( + analyzerFactory = phase.NewAnalyzerFactory( api.Platform.Latest(), fakeAPIVerifier, fakeCacheHandler, @@ -198,7 +197,7 @@ func testAnalyzerFactory(t *testing.T, when spec.G, it spec.S) { when("platform api = 0.7", func() { it.Before(func() { - analyzerFactory = lifecycle.NewAnalyzerFactory( + analyzerFactory = phase.NewAnalyzerFactory( api.MustParse("0.7"), fakeAPIVerifier, fakeCacheHandler, @@ -270,11 +269,11 @@ func testAnalyzer(platformAPI string) func(t *testing.T, when spec.G, it spec.S) cacheDir string layersDir string tmpDir string - analyzer *lifecycle.Analyzer + analyzer *phase.Analyzer image *fakes.Image mockCtrl *gomock.Controller sbomRestorer *testmock.MockSBOMRestorer - testCache lifecycle.Cache + testCache phase.Cache ) it.Before(func() { @@ -303,7 +302,7 @@ func testAnalyzer(platformAPI string) func(t *testing.T, when spec.G, it spec.S) sbomRestorer = testmock.NewMockSBOMRestorer(mockCtrl) h.AssertNil(t, err) - analyzer = &lifecycle.Analyzer{ + analyzer = &phase.Analyzer{ PreviousImage: image, Logger: &discardLogger, SBOMRestorer: sbomRestorer, diff --git a/builder.go b/phase/builder.go similarity index 97% rename from builder.go rename to phase/builder.go index c4872d42b..6f9ae736f 100644 --- a/builder.go +++ b/phase/builder.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "fmt" @@ -25,7 +25,9 @@ type Platform interface { API() *api.Version } -//go:generate mockgen -package testmock -destination testmock/build_env.go github.com/buildpacks/lifecycle BuildEnv +// BuildEnv encapsulates modifications that the lifecycle can make to buildpacks' build environment. +// +//go:generate mockgen -package testmock -destination testmock/build_env.go github.com/buildpacks/lifecycle/phase BuildEnv type BuildEnv interface { AddRootDir(baseDir string) error AddEnvDir(envDir string, defaultAction env.ActionType) error diff --git a/builder_test.go b/phase/builder_test.go similarity index 99% rename from builder_test.go rename to phase/builder_test.go index 00971bc3b..f47787619 100644 --- a/builder_test.go +++ b/phase/builder_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "bytes" @@ -17,16 +17,16 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/env" "github.com/buildpacks/lifecycle/launch" "github.com/buildpacks/lifecycle/layers" llog "github.com/buildpacks/lifecycle/log" + "github.com/buildpacks/lifecycle/phase" + "github.com/buildpacks/lifecycle/phase/testmock" "github.com/buildpacks/lifecycle/platform/files" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) func TestBuilder(t *testing.T) { @@ -36,7 +36,7 @@ func TestBuilder(t *testing.T) { func testBuilder(t *testing.T, when spec.G, it spec.S) { var ( mockCtrl *gomock.Controller - builder *lifecycle.Builder + builder *phase.Builder tmpDir string appDir string layersDir string @@ -61,7 +61,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) { h.Mkdir(t, layersDir, appDir, filepath.Join(platformDir, "env")) stdout, stderr = &bytes.Buffer{}, &bytes.Buffer{} - builder = &lifecycle.Builder{ + builder = &phase.Builder{ AppDir: appDir, LayersDir: layersDir, PlatformDir: platformDir, diff --git a/cache.go b/phase/cache.go similarity index 99% rename from cache.go rename to phase/cache.go index 880594404..16685d97d 100644 --- a/cache.go +++ b/phase/cache.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "fmt" diff --git a/cache_test.go b/phase/cache_test.go similarity index 96% rename from cache_test.go rename to phase/cache_test.go index dce8b66be..b97ccf8a7 100644 --- a/cache_test.go +++ b/phase/cache_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "errors" @@ -15,13 +15,13 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cache" "github.com/buildpacks/lifecycle/layers" + "github.com/buildpacks/lifecycle/phase" + "github.com/buildpacks/lifecycle/phase/testmock" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) func TestCache(t *testing.T) { @@ -32,12 +32,12 @@ func testCache(t *testing.T, when spec.G, it spec.S) { when("#Cache", func() { var ( cacheDir string - exporter *lifecycle.Exporter + exporter *phase.Exporter layerFactory *testmock.MockLayerFactory layersDir string logHandler *memory.Handler mockCtrl *gomock.Controller - testCache lifecycle.Cache + testCache phase.Cache tmpDir string ) @@ -60,7 +60,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) { level, err := log.ParseLevel("info") h.AssertNil(t, err) - exporter = &lifecycle.Exporter{ + exporter = &phase.Exporter{ PlatformAPI: api.Platform.Latest(), Buildpacks: []buildpack.GroupElement{ {ID: "buildpack.id", API: api.Buildpack.Latest().String()}, @@ -288,7 +288,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) { }) } -func assertCacheHasLayer(t *testing.T, cache lifecycle.Cache, id string) { +func assertCacheHasLayer(t *testing.T, cache phase.Cache, id string) { t.Helper() rc, err := cache.RetrieveLayer(testLayerDigest(id)) @@ -299,7 +299,7 @@ func assertCacheHasLayer(t *testing.T, cache lifecycle.Cache, id string) { h.AssertEq(t, string(contents), testLayerContents(id)) } -func initializeCache(t *testing.T, exporter *lifecycle.Exporter, testCache *lifecycle.Cache, cacheDir, layersDir, metadataTemplate string) { +func initializeCache(t *testing.T, exporter *phase.Exporter, testCache *phase.Cache, cacheDir, layersDir, metadataTemplate string) { previousCache, err := cache.NewVolumeCache(cacheDir) h.AssertNil(t, err) diff --git a/detector.go b/phase/detector.go similarity index 97% rename from detector.go rename to phase/detector.go index f140bb6b8..6c4f8faaf 100644 --- a/detector.go +++ b/phase/detector.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "fmt" @@ -28,7 +28,12 @@ var ( ErrBuildpack = errors.New("buildpack(s) failed with err") ) -//go:generate mockgen -package testmock -destination testmock/detect_resolver.go github.com/buildpacks/lifecycle DetectResolver +// DetectResolver given a group of buildpacks (and optional image extensions) +// processes the outputs of each `./bin/detect` to determine if the group is viable - +// that is, whether all non-optional buildpacks passed detection and a valid Build Plan can be resolved +// from each "requires" and "provides" expressed by each group element. +// +//go:generate mockgen -package testmock -destination testmock/detect_resolver.go github.com/buildpacks/lifecycle/phase DetectResolver type DetectResolver interface { Resolve(done []buildpack.GroupElement, detectRuns *sync.Map) ([]buildpack.GroupElement, []files.BuildPlanEntry, error) } diff --git a/detector_test.go b/phase/detector_test.go similarity index 97% rename from detector_test.go rename to phase/detector_test.go index 9026c91f3..4851ec961 100644 --- a/detector_test.go +++ b/phase/detector_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "errors" @@ -15,13 +15,13 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/log" + "github.com/buildpacks/lifecycle/phase" + "github.com/buildpacks/lifecycle/phase/testmock" "github.com/buildpacks/lifecycle/platform/files" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) func TestDetector(t *testing.T) { @@ -37,7 +37,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { dirStore *testmock.MockDirStore logger log.LoggerHandlerWithLevel - detectorFactory *lifecycle.DetectorFactory + detectorFactory *phase.DetectorFactory ) it.Before(func() { @@ -48,7 +48,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { dirStore = testmock.NewMockDirStore(mockController) logger = log.NewDefaultLogger(io.Discard) - detectorFactory = lifecycle.NewDetectorFactory( + detectorFactory = phase.NewDetectorFactory( api.Platform.Latest(), apiVerifier, configHandler, @@ -82,7 +82,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { h.AssertEq(t, detector.HasExtensions, false) h.AssertEq(t, detector.Order, order) h.AssertEq(t, detector.PlatformDir, "some-platform-dir") - _, ok := detector.Resolver.(*lifecycle.DefaultDetectResolver) + _, ok := detector.Resolver.(*phase.DefaultDetectResolver) h.AssertEq(t, ok, true) h.AssertNotNil(t, detector.Runs) }) @@ -142,7 +142,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { h.AssertEq(t, detector.HasExtensions, true) h.AssertEq(t, detector.Order, expectedOrder) h.AssertEq(t, detector.PlatformDir, "some-platform-dir") - _, ok := detector.Resolver.(*lifecycle.DefaultDetectResolver) + _, ok := detector.Resolver.(*phase.DefaultDetectResolver) h.AssertEq(t, ok, true) h.AssertNotNil(t, detector.Runs) }) @@ -151,7 +151,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { when(".Detect", func() { var ( - detector *lifecycle.Detector + detector *phase.Detector executor *testmock.MockDetectExecutor resolver *testmock.MockDetectResolver ) @@ -317,7 +317,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ) // bpA1 already done @@ -333,7 +333,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ).After(firstResolve) // bpA1 already done @@ -353,7 +353,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ).After(secondResolve) // bpA1 already done @@ -369,7 +369,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ).After(thirdResolve) // bpA1 already done @@ -387,7 +387,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ).After(fourthResolve) order := buildpack.Order{ @@ -490,7 +490,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ) // bpA1 already done @@ -506,7 +506,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ).After(firstResolve) // bpA1 already done @@ -526,7 +526,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ).After(secondResolve) // bpA1 already done @@ -681,7 +681,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { resolver.EXPECT().Resolve(group, detector.Runs).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrBuildpack, + phase.ErrBuildpack, ) detector.Order = buildpack.Order{{Group: group}} @@ -706,7 +706,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { resolver.EXPECT().Resolve(group, detector.Runs).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ) detector.Order = buildpack.Order{{Group: group}} @@ -911,7 +911,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ) executor.EXPECT().Detect(extB1, gomock.Any(), gomock.Any()) @@ -927,7 +927,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ).After(firstResolve) // bpA1 already done @@ -941,7 +941,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ).After(secondResolve) // extA1 already done @@ -957,7 +957,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { ).Return( []buildpack.GroupElement{}, []files.BuildPlanEntry{}, - lifecycle.ErrFailedDetection, + phase.ErrFailedDetection, ).After(thirdResolve) // extB1 already done @@ -988,7 +988,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { {Group: []buildpack.GroupElement{{ID: "B", Version: "v1"}}}, } - detector.Order = lifecycle.PrependExtensions(orderBp, orderExt) + detector.Order = phase.PrependExtensions(orderBp, orderExt) group, _, err := detector.Detect() h.AssertNil(t, err) @@ -1000,7 +1000,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { when(".Resolve", func() { var ( - resolver *lifecycle.DefaultDetectResolver + resolver *phase.DefaultDetectResolver logHandler *memory.Handler logger *log.DefaultLogger ) @@ -1008,12 +1008,12 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { it.Before(func() { logHandler = memory.New() logger = &log.DefaultLogger{Logger: &apexlog.Logger{Handler: logHandler}} - resolver = lifecycle.NewDefaultDetectResolver(logger) + resolver = phase.NewDefaultDetectResolver(logger) }) it("fails if the group is empty", func() { _, _, err := resolver.Resolve([]buildpack.GroupElement{}, &sync.Map{}) - if err != lifecycle.ErrFailedDetection { + if err != phase.ErrFailedDetection { t.Fatalf("Unexpected error:\n%s\n", err) } @@ -1040,7 +1040,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { }) _, _, err := resolver.Resolve(group, detectRuns) - if err != lifecycle.ErrFailedDetection { + if err != phase.ErrFailedDetection { t.Fatalf("Unexpected error:\n%s\n", err) } @@ -1070,7 +1070,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { }) _, _, err := resolver.Resolve(group, detectRuns) - if err != lifecycle.ErrFailedDetection { + if err != phase.ErrFailedDetection { t.Fatalf("Unexpected error:\n%s\n", err) } @@ -1100,7 +1100,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { }) _, _, err := resolver.Resolve(group, detectRuns) - if err != lifecycle.ErrBuildpack { + if err != phase.ErrBuildpack { t.Fatalf("Unexpected error:\n%s\n", err) } @@ -1133,7 +1133,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { }) _, _, err := resolver.Resolve(group, detectRuns) - if err != lifecycle.ErrFailedDetection { + if err != phase.ErrFailedDetection { t.Fatalf("Unexpected error:\n%s\n", err) } @@ -1158,7 +1158,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { }) _, _, err := resolver.Resolve(group, detectRuns) - if err != lifecycle.ErrBuildpack { + if err != phase.ErrBuildpack { t.Fatalf("Unexpected error:\n%s\n", err) } @@ -1315,7 +1315,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { }) _, _, err := resolver.Resolve(group, detectRuns) - if err != lifecycle.ErrFailedDetection { + if err != phase.ErrFailedDetection { t.Fatalf("Unexpected error:\n%s\n", err) } @@ -1372,7 +1372,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { }) _, _, err := resolver.Resolve(group, detectRuns) - if err != lifecycle.ErrFailedDetection { + if err != phase.ErrFailedDetection { t.Fatalf("Unexpected error:\n%s\n", err) } @@ -1603,7 +1603,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { buildpack.Group{Group: []buildpack.GroupElement{{ID: "D", Version: "v1", Extension: true, Optional: true}}}, } - newOrder := lifecycle.PrependExtensions(orderBp, orderExt) + newOrder := phase.PrependExtensions(orderBp, orderExt) t.Log("returns the modified order") if s := cmp.Diff(newOrder, buildpack.Order{ @@ -1639,7 +1639,7 @@ func testDetector(t *testing.T, when spec.G, it spec.S) { buildpack.Group{Group: []buildpack.GroupElement{{ID: "B", Version: "v1"}}}, } - newOrder := lifecycle.PrependExtensions(orderBp, nil) + newOrder := phase.PrependExtensions(orderBp, nil) if s := cmp.Diff(newOrder, buildpack.Order{ buildpack.Group{Group: []buildpack.GroupElement{{ID: "A", Version: "v1"}}}, diff --git a/exporter.go b/phase/exporter.go similarity index 99% rename from exporter.go rename to phase/exporter.go index 992907b1a..004a041a5 100644 --- a/exporter.go +++ b/phase/exporter.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "compress/gzip" @@ -47,7 +47,10 @@ type Exporter struct { PlatformAPI *api.Version } -//go:generate mockgen -package testmock -destination testmock/layer_factory.go github.com/buildpacks/lifecycle LayerFactory +// LayerFactory given a directory on the local filesystem will return a `layers.Layer` +// that can be used to construct an OCI image. +// +//go:generate mockgen -package testmock -destination testmock/layer_factory.go github.com/buildpacks/lifecycle/phase LayerFactory type LayerFactory interface { DirLayer(id string, dir string, createdBy string) (layers.Layer, error) LauncherLayer(path string) (layers.Layer, error) diff --git a/exporter_test.go b/phase/exporter_test.go similarity index 99% rename from exporter_test.go rename to phase/exporter_test.go index f1e3ec23b..96ee824d9 100644 --- a/exporter_test.go +++ b/phase/exporter_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "encoding/json" @@ -20,15 +20,15 @@ import ( "github.com/sclevine/spec" specreport "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/internal/path" "github.com/buildpacks/lifecycle/launch" "github.com/buildpacks/lifecycle/layers" + "github.com/buildpacks/lifecycle/phase" + "github.com/buildpacks/lifecycle/phase/testmock" "github.com/buildpacks/lifecycle/platform/files" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) func TestExporter(t *testing.T) { @@ -37,13 +37,13 @@ func TestExporter(t *testing.T) { func testExporter(t *testing.T, when spec.G, it spec.S) { var ( - exporter *lifecycle.Exporter + exporter *phase.Exporter tmpDir string mockCtrl *gomock.Controller layerFactory *testmock.MockLayerFactory fakeAppImage *fakes.Image logHandler = memory.New() - opts = lifecycle.ExportOptions{ + opts = phase.ExportOptions{ RunImageRef: "run-image-reference", AdditionalNames: []string{}, } @@ -61,7 +61,7 @@ func testExporter(t *testing.T, when spec.G, it spec.S) { launcherPath, err := filepath.Abs(filepath.Join("testdata", "exporter", "launcher")) h.AssertNil(t, err) - opts.LauncherConfig = lifecycle.LauncherConfig{ + opts.LauncherConfig = phase.LauncherConfig{ Path: launcherPath, Metadata: files.LauncherMetadata{ Version: "1.2.3", @@ -135,7 +135,7 @@ func testExporter(t *testing.T, when spec.G, it spec.S) { return []layers.Layer{layer}, nil }).AnyTimes() - exporter = &lifecycle.Exporter{ + exporter = &phase.Exporter{ Buildpacks: []buildpack.GroupElement{ {ID: "buildpack.id", Version: "1.2.3", API: api.Buildpack.Latest().String()}, {ID: "other.buildpack.id", Version: "4.5.6", API: api.Buildpack.Latest().String(), Optional: false}, @@ -1409,7 +1409,7 @@ version = "4.5.6" _, err := exporter.Export(opts) h.AssertNil(t, err) - extensions := lifecycle.SBOMExtensions() + extensions := phase.SBOMExtensions() for _, component := range []string{"lifecycle", "launcher"} { for _, extension := range extensions { assertLogEntry(t, logHandler, fmt.Sprintf("Did not find SBOM %s.%s", component, extension)) diff --git a/extender.go b/phase/extender.go similarity index 98% rename from extender.go rename to phase/extender.go index f97f26823..7efafa113 100644 --- a/extender.go +++ b/phase/extender.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "context" @@ -39,7 +39,10 @@ type Extender struct { Extensions []buildpack.GroupElement // extensions are ordered from group.toml } -//go:generate mockgen -package testmock -destination testmock/dockerfile_applier.go github.com/buildpacks/lifecycle DockerfileApplier +// DockerfileApplier given a base image and a `build.Dockerfile` or `run.Dockerfile` will apply it to the base image +// and return a new image, or an error if encountered. +// +//go:generate mockgen -package testmock -destination testmock/dockerfile_applier.go github.com/buildpacks/lifecycle/phase DockerfileApplier type DockerfileApplier interface { ImageFor(reference string) (v1.Image, error) Apply(dockerfile extend.Dockerfile, toBaseImage v1.Image, withBuildOptions extend.Options, logger log.Logger) (v1.Image, error) diff --git a/extender_test.go b/phase/extender_test.go similarity index 96% rename from extender_test.go rename to phase/extender_test.go index 7f6b5461c..eee873706 100644 --- a/extender_test.go +++ b/phase/extender_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "bytes" @@ -19,14 +19,14 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/internal/extend" llog "github.com/buildpacks/lifecycle/log" + "github.com/buildpacks/lifecycle/phase" + "github.com/buildpacks/lifecycle/phase/testmock" "github.com/buildpacks/lifecycle/platform/files" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) func TestExtender(t *testing.T) { @@ -40,7 +40,7 @@ func testExtenderFactory(t *testing.T, when spec.G, it spec.S) { when("#NewExtender", func() { var ( mockController *gomock.Controller - extenderFactory *lifecycle.ExtenderFactory + extenderFactory *phase.ExtenderFactory fakeAPIVerifier *testmock.MockBuildpackAPIVerifier fakeConfigHandler *testmock.MockConfigHandler fakeDirStore *testmock.MockDirStore @@ -49,7 +49,7 @@ func testExtenderFactory(t *testing.T, when spec.G, it spec.S) { BuildImage: &files.ImageIdentifier{Reference: "some-build-image-ref"}, RunImage: &files.RunImage{Reference: "some-run-image-ref"}, } - extender *lifecycle.Extender + extender *phase.Extender kind = "build" ) @@ -94,7 +94,7 @@ func testExtenderFactory(t *testing.T, when spec.G, it spec.S) { fakeAPIVerifier = testmock.NewMockBuildpackAPIVerifier(mockController) fakeConfigHandler = testmock.NewMockConfigHandler(mockController) fakeDirStore = testmock.NewMockDirStore(mockController) - extenderFactory = lifecycle.NewExtenderFactory(fakeAPIVerifier, fakeConfigHandler) + extenderFactory = phase.NewExtenderFactory(fakeAPIVerifier, fakeConfigHandler) logger = &log.Logger{Handler: &discard.Handler{}} }) @@ -150,7 +150,7 @@ func testExtenderFactory(t *testing.T, when spec.G, it spec.S) { func testExtender(t *testing.T, when spec.G, it spec.S) { when("Extend", func() { var ( - extender *lifecycle.Extender + extender *phase.Extender fakeDockerfileApplier *testmock.MockDockerfileApplier mockCtrl *gomock.Controller extendedDir string @@ -176,7 +176,7 @@ func testExtender(t *testing.T, when spec.G, it spec.S) { {ID: "B", Version: "v2", API: api.Buildpack.Latest().String()}, } fakeDockerfileApplier = testmock.NewMockDockerfileApplier(mockCtrl) - extender = &lifecycle.Extender{ + extender = &phase.Extender{ AppDir: "some-app-dir", ImageRef: "some-image-tag@sha256:9412cff392ca11c0d7b9df015808c4e40aff218fbe324df6490b9552ba82be38", ExtendedDir: extendedDir, @@ -395,7 +395,7 @@ func testExtender(t *testing.T, when spec.G, it spec.S) { }) firstConfig := &v1.ConfigFile{Config: v1.Config{ User: "1234:5678", - Labels: map[string]string{lifecycle.RebasableLabel: fmt.Sprintf("%t", tc.firstDockerfileRebasable)}, + Labels: map[string]string{phase.RebasableLabel: fmt.Sprintf("%t", tc.firstDockerfileRebasable)}, }} someFakeImage.ConfigFileReturnsOnCall(1, firstConfig, nil) @@ -427,7 +427,7 @@ func testExtender(t *testing.T, when spec.G, it spec.S) { }) secondConfig := &v1.ConfigFile{Config: v1.Config{ User: "1234:5678", - Labels: map[string]string{lifecycle.RebasableLabel: fmt.Sprintf("%t", tc.secondDockerfileRebasable)}, + Labels: map[string]string{phase.RebasableLabel: fmt.Sprintf("%t", tc.secondDockerfileRebasable)}, }} someFakeImage.ConfigFileReturnsOnCall(2, secondConfig, nil) diff --git a/generator.go b/phase/generator.go similarity index 99% rename from generator.go rename to phase/generator.go index 8cd091712..2a92af99b 100644 --- a/generator.go +++ b/phase/generator.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "fmt" diff --git a/generator_test.go b/phase/generator_test.go similarity index 98% rename from generator_test.go rename to phase/generator_test.go index d096e310b..0862e413e 100644 --- a/generator_test.go +++ b/phase/generator_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "bytes" @@ -16,13 +16,13 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/buildpack" llog "github.com/buildpacks/lifecycle/log" + "github.com/buildpacks/lifecycle/phase" + "github.com/buildpacks/lifecycle/phase/testmock" "github.com/buildpacks/lifecycle/platform/files" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) func TestGenerator(t *testing.T) { @@ -35,7 +35,7 @@ func TestGenerator(t *testing.T) { func testGeneratorFactory(t *testing.T, when spec.G, it spec.S) { when("#NewGenerator", func() { var ( - generatorFactory *lifecycle.GeneratorFactory + generatorFactory *phase.GeneratorFactory fakeAPIVerifier *testmock.MockBuildpackAPIVerifier fakeConfigHandler *testmock.MockConfigHandler fakeDirStore *testmock.MockDirStore @@ -51,7 +51,7 @@ func testGeneratorFactory(t *testing.T, when spec.G, it spec.S) { fakeDirStore = testmock.NewMockDirStore(mockController) logger = &log.Logger{Handler: &discard.Handler{}} - generatorFactory = lifecycle.NewGeneratorFactory( + generatorFactory = phase.NewGeneratorFactory( fakeAPIVerifier, fakeConfigHandler, fakeDirStore, @@ -114,7 +114,7 @@ func testGeneratorFactory(t *testing.T, when spec.G, it spec.S) { func testGenerator(t *testing.T, when spec.G, it spec.S) { var ( mockCtrl *gomock.Controller - generator *lifecycle.Generator + generator *phase.Generator tmpDir string appDir string generatedDir string @@ -143,7 +143,7 @@ func testGenerator(t *testing.T, when spec.G, it spec.S) { h.Mkdir(t, generatedDir, appDir, filepath.Join(platformDir, "env")) stdout, stderr = &bytes.Buffer{}, &bytes.Buffer{} - generator = &lifecycle.Generator{ + generator = &phase.Generator{ AnalyzedMD: files.Analyzed{}, AppDir: appDir, DirStore: dirStore, diff --git a/handlers.go b/phase/handlers.go similarity index 78% rename from handlers.go rename to phase/handlers.go index 2c4b3c3e0..d5dbd3989 100644 --- a/handlers.go +++ b/phase/handlers.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "fmt" @@ -12,26 +12,34 @@ import ( var Config = &DefaultConfigHandler{} -//go:generate mockgen -package testmock -destination testmock/cache_handler.go github.com/buildpacks/lifecycle CacheHandler +// CacheHandler wraps initialization of a cache image or cache volume. +// +//go:generate mockgen -package testmock -destination testmock/cache_handler.go github.com/buildpacks/lifecycle/phase CacheHandler type CacheHandler interface { InitCache(imageRef, dir string, deletionEnabled bool) (Cache, error) } -//go:generate mockgen -package testmock -destination testmock/dir_store.go github.com/buildpacks/lifecycle DirStore +// DirStore is a repository of buildpacks and/or image extensions. +// Each element should be present on disk according to the format outlined in the Platform Interface Specification, +// namely: `/cnb////`. +// +//go:generate mockgen -package testmock -destination testmock/dir_store.go github.com/buildpacks/lifecycle/phase DirStore type DirStore interface { Lookup(kind, id, version string) (buildpack.Descriptor, error) LookupBp(id, version string) (*buildpack.BpDescriptor, error) LookupExt(id, version string) (*buildpack.ExtDescriptor, error) } -//go:generate mockgen -package testmock -destination testmock/image_handler.go github.com/buildpacks/lifecycle/image Handler - -//go:generate mockgen -package testmock -destination testmock/buildpack_api_verifier.go github.com/buildpacks/lifecycle BuildpackAPIVerifier +// BuildpackAPIVerifier verifies a requested Buildpack API version. +// +//go:generate mockgen -package testmock -destination testmock/buildpack_api_verifier.go github.com/buildpacks/lifecycle/phase BuildpackAPIVerifier type BuildpackAPIVerifier interface { - VerifyBuildpackAPI(kind, name, requested string, logger log.Logger) error + VerifyBuildpackAPI(kind, name, requestedVersion string, logger log.Logger) error } -//go:generate mockgen -package testmock -destination testmock/config_handler.go github.com/buildpacks/lifecycle ConfigHandler +// ConfigHandler reads configuration files for the lifecycle. +// +//go:generate mockgen -package testmock -destination testmock/config_handler.go github.com/buildpacks/lifecycle/phase ConfigHandler type ConfigHandler interface { ReadAnalyzed(path string, logger log.Logger) (files.Analyzed, error) ReadGroup(path string) (buildpackGroup []buildpack.GroupElement, extensionsGroup []buildpack.GroupElement, err error) diff --git a/handlers_test.go b/phase/handlers_test.go similarity index 91% rename from handlers_test.go rename to phase/handlers_test.go index 9241aa073..6518f67d7 100644 --- a/handlers_test.go +++ b/phase/handlers_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "os" @@ -8,8 +8,8 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/buildpack" + "github.com/buildpacks/lifecycle/phase" h "github.com/buildpacks/lifecycle/testhelpers" ) @@ -80,7 +80,7 @@ group = [{id = "D", version = "v1"}] when("#ReadGroup", func() { it("returns a single group object with a buildpack group and an extensions group", func() { h.Mkfile(t, groupTOMLContents, filepath.Join(tmpDir, "group.toml")) - foundGroup, err := lifecycle.ReadGroup(filepath.Join(tmpDir, "group.toml")) + foundGroup, err := phase.ReadGroup(filepath.Join(tmpDir, "group.toml")) h.AssertNil(t, err) h.AssertEq(t, foundGroup, buildpack.Group{ Group: expectedGroupBp, @@ -92,7 +92,7 @@ group = [{id = "D", version = "v1"}] when("#ReadOrder", func() { it("returns an ordering of buildpacks and an ordering of extensions", func() { h.Mkfile(t, orderTOMLContents, filepath.Join(tmpDir, "order.toml")) - foundOrder, foundOrderExt, err := lifecycle.ReadOrder(filepath.Join(tmpDir, "order.toml")) + foundOrder, foundOrderExt, err := phase.ReadOrder(filepath.Join(tmpDir, "order.toml")) h.AssertNil(t, err) h.AssertEq(t, foundOrder, expectedOrderBp) h.AssertEq(t, foundOrderExt, expectedOrderExt) @@ -101,11 +101,11 @@ group = [{id = "D", version = "v1"}] when("DefaultConfigHandler", func() { var ( - configHandler *lifecycle.DefaultConfigHandler + configHandler *phase.DefaultConfigHandler ) it.Before(func() { - configHandler = lifecycle.NewConfigHandler() + configHandler = phase.NewConfigHandler() }) when(".ReadGroup", func() { diff --git a/phase/phase.go b/phase/phase.go new file mode 100644 index 000000000..8d9880cea --- /dev/null +++ b/phase/phase.go @@ -0,0 +1,6 @@ +// Package phase handles logic internal to the CNB lifecycle, +// and roughly corresponds to the actions denoted by "the lifecycle MUST" and "the lifecycle SHALL" +// in the [Platform Interface Specification]. +// +// [Platform Interface Specification]: https://github.com/buildpacks/spec/blob/main/platform.md +package phase diff --git a/rebaser.go b/phase/rebaser.go similarity index 99% rename from rebaser.go rename to phase/rebaser.go index 76a70f186..7887332bf 100644 --- a/rebaser.go +++ b/phase/rebaser.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "encoding/json" diff --git a/rebaser_test.go b/phase/rebaser_test.go similarity index 99% rename from rebaser_test.go rename to phase/rebaser_test.go index 3337dce95..8791f56d5 100644 --- a/rebaser_test.go +++ b/phase/rebaser_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "encoding/json" @@ -13,9 +13,9 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/image" + "github.com/buildpacks/lifecycle/phase" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/platform/files" h "github.com/buildpacks/lifecycle/testhelpers" @@ -27,7 +27,7 @@ func TestRebaser(t *testing.T) { func testRebaser(t *testing.T, when spec.G, it spec.S) { var ( - rebaser *lifecycle.Rebaser + rebaser *phase.Rebaser fakeAppImage *fakes.Image fakeNewBaseImage *fakes.Image fakePreviousImage *fakes.Image @@ -78,7 +78,7 @@ func testRebaser(t *testing.T, when spec.G, it spec.S) { logHandler = memory.New() - rebaser = &lifecycle.Rebaser{ + rebaser = &phase.Rebaser{ Logger: &log.Logger{Handler: logHandler}, PlatformAPI: api.Platform.Latest(), } diff --git a/restorer.go b/phase/restorer.go similarity index 99% rename from restorer.go rename to phase/restorer.go index 4bf29c60c..30357c52e 100644 --- a/restorer.go +++ b/phase/restorer.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "path/filepath" diff --git a/restorer_test.go b/phase/restorer_test.go similarity index 98% rename from restorer_test.go rename to phase/restorer_test.go index 0cef4b599..61066c883 100644 --- a/restorer_test.go +++ b/phase/restorer_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "encoding/json" @@ -14,16 +14,16 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" "github.com/buildpacks/lifecycle/api" "github.com/buildpacks/lifecycle/buildpack" "github.com/buildpacks/lifecycle/cache" "github.com/buildpacks/lifecycle/internal/layer" "github.com/buildpacks/lifecycle/layers" + "github.com/buildpacks/lifecycle/phase" + "github.com/buildpacks/lifecycle/phase/testmock" "github.com/buildpacks/lifecycle/platform" "github.com/buildpacks/lifecycle/platform/files" h "github.com/buildpacks/lifecycle/testhelpers" - "github.com/buildpacks/lifecycle/testmock" ) func TestRestorer(t *testing.T) { @@ -46,8 +46,8 @@ func testRestorer(buildpackAPI, platformAPI string) func(t *testing.T, when spec layersDir string logHandler *memory.Handler skipLayers bool - testCache lifecycle.Cache - restorer *lifecycle.Restorer + testCache phase.Cache + restorer *phase.Restorer mockCtrl *gomock.Controller sbomRestorer *testmock.MockSBOMRestorer ) @@ -74,7 +74,7 @@ func testRestorer(buildpackAPI, platformAPI string) func(t *testing.T, when spec sbomRestorer.EXPECT().RestoreToBuildpackLayers(gomock.Any()).AnyTimes() } - restorer = &lifecycle.Restorer{ + restorer = &phase.Restorer{ LayersDir: layersDir, Logger: &logger, Buildpacks: []buildpack.GroupElement{ diff --git a/save.go b/phase/save.go similarity index 99% rename from save.go rename to phase/save.go index 4505c8e41..b2e4a891b 100644 --- a/save.go +++ b/phase/save.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "fmt" diff --git a/testdata/analyzer/app_metadata.json b/phase/testdata/analyzer/app_metadata.json similarity index 100% rename from testdata/analyzer/app_metadata.json rename to phase/testdata/analyzer/app_metadata.json diff --git a/testdata/analyzer/cache_inconsistent_metadata.json b/phase/testdata/analyzer/cache_inconsistent_metadata.json similarity index 100% rename from testdata/analyzer/cache_inconsistent_metadata.json rename to phase/testdata/analyzer/cache_inconsistent_metadata.json diff --git a/testdata/analyzer/cache_metadata.json b/phase/testdata/analyzer/cache_metadata.json similarity index 100% rename from testdata/analyzer/cache_metadata.json rename to phase/testdata/analyzer/cache_metadata.json diff --git a/testdata/cacher/invalid-layers/buildpack.id/cache-true-no-contents.toml b/phase/testdata/cacher/invalid-layers/buildpack.id/cache-true-no-contents.toml similarity index 100% rename from testdata/cacher/invalid-layers/buildpack.id/cache-true-no-contents.toml rename to phase/testdata/cacher/invalid-layers/buildpack.id/cache-true-no-contents.toml diff --git a/testdata/cacher/invalid-layers/buildpack.id/layer-1.toml b/phase/testdata/cacher/invalid-layers/buildpack.id/layer-1.toml similarity index 100% rename from testdata/cacher/invalid-layers/buildpack.id/layer-1.toml rename to phase/testdata/cacher/invalid-layers/buildpack.id/layer-1.toml diff --git a/testdata/cacher/invalid-layers/buildpack.id/layer-1/layer-1-file b/phase/testdata/cacher/invalid-layers/buildpack.id/layer-1/layer-1-file similarity index 100% rename from testdata/cacher/invalid-layers/buildpack.id/layer-1/layer-1-file rename to phase/testdata/cacher/invalid-layers/buildpack.id/layer-1/layer-1-file diff --git a/testdata/cacher/invalid-layers/buildpack.id/layer-2.toml b/phase/testdata/cacher/invalid-layers/buildpack.id/layer-2.toml similarity index 100% rename from testdata/cacher/invalid-layers/buildpack.id/layer-2.toml rename to phase/testdata/cacher/invalid-layers/buildpack.id/layer-2.toml diff --git a/testdata/cacher/invalid-layers/buildpack.id/layer-2/layer-2-file b/phase/testdata/cacher/invalid-layers/buildpack.id/layer-2/layer-2-file similarity index 100% rename from testdata/cacher/invalid-layers/buildpack.id/layer-2/layer-2-file rename to phase/testdata/cacher/invalid-layers/buildpack.id/layer-2/layer-2-file diff --git a/testdata/cacher/layers/buildpack.id/cache-false-layer.toml b/phase/testdata/cacher/layers/buildpack.id/cache-false-layer.toml similarity index 100% rename from testdata/cacher/layers/buildpack.id/cache-false-layer.toml rename to phase/testdata/cacher/layers/buildpack.id/cache-false-layer.toml diff --git a/testdata/cacher/layers/buildpack.id/cache-false-layer/file-from-cache-false-layer b/phase/testdata/cacher/layers/buildpack.id/cache-false-layer/file-from-cache-false-layer similarity index 100% rename from testdata/cacher/layers/buildpack.id/cache-false-layer/file-from-cache-false-layer rename to phase/testdata/cacher/layers/buildpack.id/cache-false-layer/file-from-cache-false-layer diff --git a/testdata/cacher/layers/buildpack.id/cache-true-layer.sha b/phase/testdata/cacher/layers/buildpack.id/cache-true-layer.sha similarity index 100% rename from testdata/cacher/layers/buildpack.id/cache-true-layer.sha rename to phase/testdata/cacher/layers/buildpack.id/cache-true-layer.sha diff --git a/testdata/cacher/layers/buildpack.id/cache-true-layer.toml b/phase/testdata/cacher/layers/buildpack.id/cache-true-layer.toml similarity index 100% rename from testdata/cacher/layers/buildpack.id/cache-true-layer.toml rename to phase/testdata/cacher/layers/buildpack.id/cache-true-layer.toml diff --git a/testdata/cacher/layers/buildpack.id/cache-true-layer/file-from-cache-true-layer b/phase/testdata/cacher/layers/buildpack.id/cache-true-layer/file-from-cache-true-layer similarity index 100% rename from testdata/cacher/layers/buildpack.id/cache-true-layer/file-from-cache-true-layer rename to phase/testdata/cacher/layers/buildpack.id/cache-true-layer/file-from-cache-true-layer diff --git a/testdata/cacher/layers/buildpack.id/cache-true-no-sha-layer.toml b/phase/testdata/cacher/layers/buildpack.id/cache-true-no-sha-layer.toml similarity index 100% rename from testdata/cacher/layers/buildpack.id/cache-true-no-sha-layer.toml rename to phase/testdata/cacher/layers/buildpack.id/cache-true-no-sha-layer.toml diff --git a/testdata/cacher/layers/buildpack.id/cache-true-no-sha-layer/file-from-cache-true-no-sha-layer b/phase/testdata/cacher/layers/buildpack.id/cache-true-no-sha-layer/file-from-cache-true-no-sha-layer similarity index 100% rename from testdata/cacher/layers/buildpack.id/cache-true-no-sha-layer/file-from-cache-true-no-sha-layer rename to phase/testdata/cacher/layers/buildpack.id/cache-true-no-sha-layer/file-from-cache-true-no-sha-layer diff --git a/testdata/cacher/layers/old.buildpack.id/cache-true-layer.sha b/phase/testdata/cacher/layers/old.buildpack.id/cache-true-layer.sha similarity index 100% rename from testdata/cacher/layers/old.buildpack.id/cache-true-layer.sha rename to phase/testdata/cacher/layers/old.buildpack.id/cache-true-layer.sha diff --git a/testdata/cacher/layers/old.buildpack.id/cache-true-layer.toml b/phase/testdata/cacher/layers/old.buildpack.id/cache-true-layer.toml similarity index 100% rename from testdata/cacher/layers/old.buildpack.id/cache-true-layer.toml rename to phase/testdata/cacher/layers/old.buildpack.id/cache-true-layer.toml diff --git a/testdata/cacher/layers/old.buildpack.id/cache-true-layer/file-from-cache-true-layer b/phase/testdata/cacher/layers/old.buildpack.id/cache-true-layer/file-from-cache-true-layer similarity index 100% rename from testdata/cacher/layers/old.buildpack.id/cache-true-layer/file-from-cache-true-layer rename to phase/testdata/cacher/layers/old.buildpack.id/cache-true-layer/file-from-cache-true-layer diff --git a/testdata/cacher/layers/other.buildpack.id/other-buildpack-layer.toml b/phase/testdata/cacher/layers/other.buildpack.id/other-buildpack-layer.toml similarity index 100% rename from testdata/cacher/layers/other.buildpack.id/other-buildpack-layer.toml rename to phase/testdata/cacher/layers/other.buildpack.id/other-buildpack-layer.toml diff --git a/testdata/cacher/layers/other.buildpack.id/other-buildpack-layer/other-buildpack-layer-file b/phase/testdata/cacher/layers/other.buildpack.id/other-buildpack-layer/other-buildpack-layer-file similarity index 100% rename from testdata/cacher/layers/other.buildpack.id/other-buildpack-layer/other-buildpack-layer-file rename to phase/testdata/cacher/layers/other.buildpack.id/other-buildpack-layer/other-buildpack-layer-file diff --git a/testdata/cacher/layers/sbom/cache/buildpack.id/cache-true-layer/bom.cdx.json b/phase/testdata/cacher/layers/sbom/cache/buildpack.id/cache-true-layer/bom.cdx.json similarity index 100% rename from testdata/cacher/layers/sbom/cache/buildpack.id/cache-true-layer/bom.cdx.json rename to phase/testdata/cacher/layers/sbom/cache/buildpack.id/cache-true-layer/bom.cdx.json diff --git a/testdata/cred_helpers/config1.json b/phase/testdata/cred_helpers/config1.json similarity index 100% rename from testdata/cred_helpers/config1.json rename to phase/testdata/cred_helpers/config1.json diff --git a/testdata/cred_helpers/config2.json b/phase/testdata/cred_helpers/config2.json similarity index 100% rename from testdata/cred_helpers/config2.json rename to phase/testdata/cred_helpers/config2.json diff --git a/testdata/exporter/app-slices/layers/app/.hidden.txt b/phase/testdata/exporter/app-slices/layers/app/.hidden.txt similarity index 100% rename from testdata/exporter/app-slices/layers/app/.hidden.txt rename to phase/testdata/exporter/app-slices/layers/app/.hidden.txt diff --git a/testdata/exporter/app-slices/layers/app/static/assets/config.txt b/phase/testdata/exporter/app-slices/layers/app/static/assets/config.txt similarity index 100% rename from testdata/exporter/app-slices/layers/app/static/assets/config.txt rename to phase/testdata/exporter/app-slices/layers/app/static/assets/config.txt diff --git a/testdata/exporter/app-slices/layers/app/static/assets/logo.svg b/phase/testdata/exporter/app-slices/layers/app/static/assets/logo.svg similarity index 100% rename from testdata/exporter/app-slices/layers/app/static/assets/logo.svg rename to phase/testdata/exporter/app-slices/layers/app/static/assets/logo.svg diff --git a/testdata/exporter/app-slices/layers/app/static/misc/resources/reports/numbers.csv b/phase/testdata/exporter/app-slices/layers/app/static/misc/resources/reports/numbers.csv similarity index 100% rename from testdata/exporter/app-slices/layers/app/static/misc/resources/reports/numbers.csv rename to phase/testdata/exporter/app-slices/layers/app/static/misc/resources/reports/numbers.csv diff --git a/testdata/exporter/app-slices/layers/app/static/misc/resources/reports/report.tps b/phase/testdata/exporter/app-slices/layers/app/static/misc/resources/reports/report.tps similarity index 100% rename from testdata/exporter/app-slices/layers/app/static/misc/resources/reports/report.tps rename to phase/testdata/exporter/app-slices/layers/app/static/misc/resources/reports/report.tps diff --git a/testdata/exporter/app-slices/layers/app/test_app.sh b/phase/testdata/exporter/app-slices/layers/app/test_app.sh similarity index 100% rename from testdata/exporter/app-slices/layers/app/test_app.sh rename to phase/testdata/exporter/app-slices/layers/app/test_app.sh diff --git a/testdata/exporter/app-slices/layers/buildpack.id/layer1.toml b/phase/testdata/exporter/app-slices/layers/buildpack.id/layer1.toml similarity index 100% rename from testdata/exporter/app-slices/layers/buildpack.id/layer1.toml rename to phase/testdata/exporter/app-slices/layers/buildpack.id/layer1.toml diff --git a/testdata/exporter/app-slices/layers/buildpack.id/layer1/file-from-layer-1 b/phase/testdata/exporter/app-slices/layers/buildpack.id/layer1/file-from-layer-1 similarity index 100% rename from testdata/exporter/app-slices/layers/buildpack.id/layer1/file-from-layer-1 rename to phase/testdata/exporter/app-slices/layers/buildpack.id/layer1/file-from-layer-1 diff --git a/testdata/exporter/app-slices/layers/buildpack.id/layer2.toml b/phase/testdata/exporter/app-slices/layers/buildpack.id/layer2.toml similarity index 100% rename from testdata/exporter/app-slices/layers/buildpack.id/layer2.toml rename to phase/testdata/exporter/app-slices/layers/buildpack.id/layer2.toml diff --git a/testdata/exporter/app-slices/layers/buildpack.id/layer2/file-from-layer-2 b/phase/testdata/exporter/app-slices/layers/buildpack.id/layer2/file-from-layer-2 similarity index 100% rename from testdata/exporter/app-slices/layers/buildpack.id/layer2/file-from-layer-2 rename to phase/testdata/exporter/app-slices/layers/buildpack.id/layer2/file-from-layer-2 diff --git a/testdata/exporter/app-slices/layers/config/metadata.toml b/phase/testdata/exporter/app-slices/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/app-slices/layers/config/metadata.toml rename to phase/testdata/exporter/app-slices/layers/config/metadata.toml diff --git a/testdata/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer.toml b/phase/testdata/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer.toml similarity index 100% rename from testdata/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer.toml rename to phase/testdata/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer.toml diff --git a/testdata/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer/layer5contents b/phase/testdata/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer/layer5contents similarity index 100% rename from testdata/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer/layer5contents rename to phase/testdata/exporter/app-slices/layers/other.buildpack.id/local-reusable-layer/layer5contents diff --git a/testdata/exporter/app-slices/layers/other.buildpack.id/new-launch-layer.toml b/phase/testdata/exporter/app-slices/layers/other.buildpack.id/new-launch-layer.toml similarity index 100% rename from testdata/exporter/app-slices/layers/other.buildpack.id/new-launch-layer.toml rename to phase/testdata/exporter/app-slices/layers/other.buildpack.id/new-launch-layer.toml diff --git a/testdata/exporter/app-slices/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file b/phase/testdata/exporter/app-slices/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file similarity index 100% rename from testdata/exporter/app-slices/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file rename to phase/testdata/exporter/app-slices/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file diff --git a/testdata/exporter/bad-layer/layers/app/metadata.toml b/phase/testdata/exporter/bad-layer/layers/app/metadata.toml similarity index 100% rename from testdata/exporter/bad-layer/layers/app/metadata.toml rename to phase/testdata/exporter/bad-layer/layers/app/metadata.toml diff --git a/testdata/exporter/bad-layer/layers/app/test_app.sh b/phase/testdata/exporter/bad-layer/layers/app/test_app.sh similarity index 100% rename from testdata/exporter/bad-layer/layers/app/test_app.sh rename to phase/testdata/exporter/bad-layer/layers/app/test_app.sh diff --git a/testdata/exporter/bad-layer/layers/buildpack.id/bad-layer.toml b/phase/testdata/exporter/bad-layer/layers/buildpack.id/bad-layer.toml similarity index 100% rename from testdata/exporter/bad-layer/layers/buildpack.id/bad-layer.toml rename to phase/testdata/exporter/bad-layer/layers/buildpack.id/bad-layer.toml diff --git a/testdata/exporter/bad-layer/layers/config/metadata.toml b/phase/testdata/exporter/bad-layer/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/bad-layer/layers/config/metadata.toml rename to phase/testdata/exporter/bad-layer/layers/config/metadata.toml diff --git a/testdata/exporter/build-metadata/bad-layers/buildpack.id/build.toml b/phase/testdata/exporter/build-metadata/bad-layers/buildpack.id/build.toml similarity index 100% rename from testdata/exporter/build-metadata/bad-layers/buildpack.id/build.toml rename to phase/testdata/exporter/build-metadata/bad-layers/buildpack.id/build.toml diff --git a/testdata/exporter/build-metadata/bad-layers/config/metadata.toml b/phase/testdata/exporter/build-metadata/bad-layers/config/metadata.toml similarity index 100% rename from testdata/exporter/build-metadata/bad-layers/config/metadata.toml rename to phase/testdata/exporter/build-metadata/bad-layers/config/metadata.toml diff --git a/testdata/exporter/build-metadata/bad-layers/other.buildpack.id/build.toml b/phase/testdata/exporter/build-metadata/bad-layers/other.buildpack.id/build.toml similarity index 100% rename from testdata/exporter/build-metadata/bad-layers/other.buildpack.id/build.toml rename to phase/testdata/exporter/build-metadata/bad-layers/other.buildpack.id/build.toml diff --git a/testdata/exporter/build-metadata/layers/buildpack.id/build.toml b/phase/testdata/exporter/build-metadata/layers/buildpack.id/build.toml similarity index 100% rename from testdata/exporter/build-metadata/layers/buildpack.id/build.toml rename to phase/testdata/exporter/build-metadata/layers/buildpack.id/build.toml diff --git a/testdata/exporter/build-metadata/layers/config/metadata.toml b/phase/testdata/exporter/build-metadata/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/build-metadata/layers/config/metadata.toml rename to phase/testdata/exporter/build-metadata/layers/config/metadata.toml diff --git a/testdata/exporter/build-metadata/layers/other.buildpack.id/build.toml b/phase/testdata/exporter/build-metadata/layers/other.buildpack.id/build.toml similarity index 100% rename from testdata/exporter/build-metadata/layers/other.buildpack.id/build.toml rename to phase/testdata/exporter/build-metadata/layers/other.buildpack.id/build.toml diff --git a/testdata/exporter/cache-layer-no-contents/layers/app/metadata.toml b/phase/testdata/exporter/cache-layer-no-contents/layers/app/metadata.toml similarity index 100% rename from testdata/exporter/cache-layer-no-contents/layers/app/metadata.toml rename to phase/testdata/exporter/cache-layer-no-contents/layers/app/metadata.toml diff --git a/testdata/exporter/cache-layer-no-contents/layers/app/test_app.sh b/phase/testdata/exporter/cache-layer-no-contents/layers/app/test_app.sh similarity index 100% rename from testdata/exporter/cache-layer-no-contents/layers/app/test_app.sh rename to phase/testdata/exporter/cache-layer-no-contents/layers/app/test_app.sh diff --git a/testdata/exporter/cache-layer-no-contents/layers/buildpack.id/cache-layer-no-contents.toml b/phase/testdata/exporter/cache-layer-no-contents/layers/buildpack.id/cache-layer-no-contents.toml similarity index 100% rename from testdata/exporter/cache-layer-no-contents/layers/buildpack.id/cache-layer-no-contents.toml rename to phase/testdata/exporter/cache-layer-no-contents/layers/buildpack.id/cache-layer-no-contents.toml diff --git a/testdata/exporter/cache-layer-no-contents/layers/config/metadata.toml b/phase/testdata/exporter/cache-layer-no-contents/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/cache-layer-no-contents/layers/config/metadata.toml rename to phase/testdata/exporter/cache-layer-no-contents/layers/config/metadata.toml diff --git a/testdata/exporter/cleanup-cache/layers/buildpack.id/no-toml-layer/file-for-invalid-layer b/phase/testdata/exporter/cleanup-cache/layers/buildpack.id/no-toml-layer/file-for-invalid-layer similarity index 100% rename from testdata/exporter/cleanup-cache/layers/buildpack.id/no-toml-layer/file-for-invalid-layer rename to phase/testdata/exporter/cleanup-cache/layers/buildpack.id/no-toml-layer/file-for-invalid-layer diff --git a/testdata/exporter/default-process/metadata-with-default/layers/config/metadata.toml b/phase/testdata/exporter/default-process/metadata-with-default/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/default-process/metadata-with-default/layers/config/metadata.toml rename to phase/testdata/exporter/default-process/metadata-with-default/layers/config/metadata.toml diff --git a/testdata/exporter/default-process/metadata-with-no-default/layers/config/metadata.toml b/phase/testdata/exporter/default-process/metadata-with-no-default/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/default-process/metadata-with-no-default/layers/config/metadata.toml rename to phase/testdata/exporter/default-process/metadata-with-no-default/layers/config/metadata.toml diff --git a/testdata/exporter/empty-metadata/layers/config/metadata.toml b/phase/testdata/exporter/empty-metadata/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/empty-metadata/layers/config/metadata.toml rename to phase/testdata/exporter/empty-metadata/layers/config/metadata.toml diff --git a/testdata/exporter/escaped-bpid/layers/app/app b/phase/testdata/exporter/escaped-bpid/layers/app/app similarity index 100% rename from testdata/exporter/escaped-bpid/layers/app/app rename to phase/testdata/exporter/escaped-bpid/layers/app/app diff --git a/testdata/exporter/escaped-bpid/layers/config/metadata.toml b/phase/testdata/exporter/escaped-bpid/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/escaped-bpid/layers/config/metadata.toml rename to phase/testdata/exporter/escaped-bpid/layers/config/metadata.toml diff --git a/testdata/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer.toml b/phase/testdata/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer.toml similarity index 100% rename from testdata/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer.toml rename to phase/testdata/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer.toml diff --git a/testdata/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer/some-file b/phase/testdata/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer/some-file similarity index 100% rename from testdata/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer/some-file rename to phase/testdata/exporter/escaped-bpid/layers/some_escaped_bp_id/some-layer/some-file diff --git a/testdata/exporter/launcher b/phase/testdata/exporter/launcher similarity index 100% rename from testdata/exporter/launcher rename to phase/testdata/exporter/launcher diff --git a/testdata/exporter/launcher-sbom/layers/config/metadata.toml b/phase/testdata/exporter/launcher-sbom/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/launcher-sbom/layers/config/metadata.toml rename to phase/testdata/exporter/launcher-sbom/layers/config/metadata.toml diff --git a/testdata/exporter/launcher-sbom/layers/some-launcher-sbom-dir/a-regular-file.txt b/phase/testdata/exporter/launcher-sbom/layers/some-launcher-sbom-dir/a-regular-file.txt similarity index 100% rename from testdata/exporter/launcher-sbom/layers/some-launcher-sbom-dir/a-regular-file.txt rename to phase/testdata/exporter/launcher-sbom/layers/some-launcher-sbom-dir/a-regular-file.txt diff --git a/testdata/exporter/launcher-sbom/layers/some-launcher-sbom-dir/some-sbom-file.sbom.spdx.json b/phase/testdata/exporter/launcher-sbom/layers/some-launcher-sbom-dir/some-sbom-file.sbom.spdx.json similarity index 100% rename from testdata/exporter/launcher-sbom/layers/some-launcher-sbom-dir/some-sbom-file.sbom.spdx.json rename to phase/testdata/exporter/launcher-sbom/layers/some-launcher-sbom-dir/some-sbom-file.sbom.spdx.json diff --git a/testdata/exporter/previous-image-exists/layers/app/.hidden.txt b/phase/testdata/exporter/previous-image-exists/layers/app/.hidden.txt similarity index 100% rename from testdata/exporter/previous-image-exists/layers/app/.hidden.txt rename to phase/testdata/exporter/previous-image-exists/layers/app/.hidden.txt diff --git a/testdata/exporter/previous-image-exists/layers/app/subdir/myfile.txt b/phase/testdata/exporter/previous-image-exists/layers/app/subdir/myfile.txt similarity index 100% rename from testdata/exporter/previous-image-exists/layers/app/subdir/myfile.txt rename to phase/testdata/exporter/previous-image-exists/layers/app/subdir/myfile.txt diff --git a/testdata/exporter/previous-image-exists/layers/app/test_app.sh b/phase/testdata/exporter/previous-image-exists/layers/app/test_app.sh similarity index 100% rename from testdata/exporter/previous-image-exists/layers/app/test_app.sh rename to phase/testdata/exporter/previous-image-exists/layers/app/test_app.sh diff --git a/testdata/exporter/previous-image-exists/layers/app/test_app_real.sh b/phase/testdata/exporter/previous-image-exists/layers/app/test_app_real.sh similarity index 100% rename from testdata/exporter/previous-image-exists/layers/app/test_app_real.sh rename to phase/testdata/exporter/previous-image-exists/layers/app/test_app_real.sh diff --git a/testdata/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer.toml b/phase/testdata/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer.toml similarity index 100% rename from testdata/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer.toml rename to phase/testdata/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer.toml diff --git a/testdata/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer/layer5contents b/phase/testdata/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer/layer5contents similarity index 100% rename from testdata/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer/layer5contents rename to phase/testdata/exporter/previous-image-exists/layers/bad.buildpack.id/bad-layer/layer5contents diff --git a/testdata/exporter/previous-image-exists/layers/buildpack.id/launch-layer-no-local-dir.toml b/phase/testdata/exporter/previous-image-exists/layers/buildpack.id/launch-layer-no-local-dir.toml similarity index 100% rename from testdata/exporter/previous-image-exists/layers/buildpack.id/launch-layer-no-local-dir.toml rename to phase/testdata/exporter/previous-image-exists/layers/buildpack.id/launch-layer-no-local-dir.toml diff --git a/testdata/exporter/previous-image-exists/layers/buildpack.id/launch.toml b/phase/testdata/exporter/previous-image-exists/layers/buildpack.id/launch.toml similarity index 100% rename from testdata/exporter/previous-image-exists/layers/buildpack.id/launch.toml rename to phase/testdata/exporter/previous-image-exists/layers/buildpack.id/launch.toml diff --git a/testdata/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer.toml b/phase/testdata/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer.toml similarity index 100% rename from testdata/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer.toml rename to phase/testdata/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer.toml diff --git a/testdata/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer/file-from-new-launch-layer b/phase/testdata/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer/file-from-new-launch-layer similarity index 100% rename from testdata/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer/file-from-new-launch-layer rename to phase/testdata/exporter/previous-image-exists/layers/buildpack.id/new-launch-layer/file-from-new-launch-layer diff --git a/testdata/exporter/previous-image-exists/layers/config/metadata.toml b/phase/testdata/exporter/previous-image-exists/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/previous-image-exists/layers/config/metadata.toml rename to phase/testdata/exporter/previous-image-exists/layers/config/metadata.toml diff --git a/testdata/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer.toml b/phase/testdata/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer.toml similarity index 100% rename from testdata/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer.toml rename to phase/testdata/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer.toml diff --git a/testdata/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer/layer5contents b/phase/testdata/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer/layer5contents similarity index 100% rename from testdata/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer/layer5contents rename to phase/testdata/exporter/previous-image-exists/layers/old.buildpack.id/bad-layer/layer5contents diff --git a/testdata/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer.toml b/phase/testdata/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer.toml similarity index 100% rename from testdata/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer.toml rename to phase/testdata/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer.toml diff --git a/testdata/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer/layer5contents b/phase/testdata/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer/layer5contents similarity index 100% rename from testdata/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer/layer5contents rename to phase/testdata/exporter/previous-image-exists/layers/other.buildpack.id/local-reusable-layer/layer5contents diff --git a/testdata/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer.toml b/phase/testdata/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer.toml similarity index 100% rename from testdata/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer.toml rename to phase/testdata/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer.toml diff --git a/testdata/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file b/phase/testdata/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file similarity index 100% rename from testdata/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file rename to phase/testdata/exporter/previous-image-exists/layers/other.buildpack.id/new-launch-layer/new-launch-layer-file diff --git a/testdata/exporter/previous-image-exists/layers/sbom/launch/buildpack.id/bom.cdx.json b/phase/testdata/exporter/previous-image-exists/layers/sbom/launch/buildpack.id/bom.cdx.json similarity index 100% rename from testdata/exporter/previous-image-exists/layers/sbom/launch/buildpack.id/bom.cdx.json rename to phase/testdata/exporter/previous-image-exists/layers/sbom/launch/buildpack.id/bom.cdx.json diff --git a/testdata/exporter/previous-image-not-exist/layers/app/.hidden.txt b/phase/testdata/exporter/previous-image-not-exist/layers/app/.hidden.txt similarity index 100% rename from testdata/exporter/previous-image-not-exist/layers/app/.hidden.txt rename to phase/testdata/exporter/previous-image-not-exist/layers/app/.hidden.txt diff --git a/testdata/exporter/previous-image-not-exist/layers/app/metadata.toml b/phase/testdata/exporter/previous-image-not-exist/layers/app/metadata.toml similarity index 100% rename from testdata/exporter/previous-image-not-exist/layers/app/metadata.toml rename to phase/testdata/exporter/previous-image-not-exist/layers/app/metadata.toml diff --git a/testdata/exporter/previous-image-not-exist/layers/app/test_app.sh b/phase/testdata/exporter/previous-image-not-exist/layers/app/test_app.sh similarity index 100% rename from testdata/exporter/previous-image-not-exist/layers/app/test_app.sh rename to phase/testdata/exporter/previous-image-not-exist/layers/app/test_app.sh diff --git a/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer1.toml b/phase/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer1.toml similarity index 100% rename from testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer1.toml rename to phase/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer1.toml diff --git a/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer1/file-from-layer-1 b/phase/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer1/file-from-layer-1 similarity index 100% rename from testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer1/file-from-layer-1 rename to phase/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer1/file-from-layer-1 diff --git a/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer2.toml b/phase/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer2.toml similarity index 100% rename from testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer2.toml rename to phase/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer2.toml diff --git a/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer2/file-from-layer-2 b/phase/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer2/file-from-layer-2 similarity index 100% rename from testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer2/file-from-layer-2 rename to phase/testdata/exporter/previous-image-not-exist/layers/buildpack.id/layer2/file-from-layer-2 diff --git a/testdata/exporter/previous-image-not-exist/layers/config/metadata.toml b/phase/testdata/exporter/previous-image-not-exist/layers/config/metadata.toml similarity index 100% rename from testdata/exporter/previous-image-not-exist/layers/config/metadata.toml rename to phase/testdata/exporter/previous-image-not-exist/layers/config/metadata.toml diff --git a/testdata/exporter/previous-image-not-exist/layers/sbom/launch/buildpack.id/launch-true-layer/bom.cdx.json b/phase/testdata/exporter/previous-image-not-exist/layers/sbom/launch/buildpack.id/launch-true-layer/bom.cdx.json similarity index 100% rename from testdata/exporter/previous-image-not-exist/layers/sbom/launch/buildpack.id/launch-true-layer/bom.cdx.json rename to phase/testdata/exporter/previous-image-not-exist/layers/sbom/launch/buildpack.id/launch-true-layer/bom.cdx.json diff --git a/testdata/restorer/buildpack.id/cache-false/file-from-cache-false-layer b/phase/testdata/restorer/buildpack.id/cache-false/file-from-cache-false-layer similarity index 100% rename from testdata/restorer/buildpack.id/cache-false/file-from-cache-false-layer rename to phase/testdata/restorer/buildpack.id/cache-false/file-from-cache-false-layer diff --git a/testdata/restorer/buildpack.id/cache-launch/file-from-cache-launch-layer b/phase/testdata/restorer/buildpack.id/cache-launch/file-from-cache-launch-layer similarity index 100% rename from testdata/restorer/buildpack.id/cache-launch/file-from-cache-launch-layer rename to phase/testdata/restorer/buildpack.id/cache-launch/file-from-cache-launch-layer diff --git a/testdata/restorer/buildpack.id/cache-only/file-from-cache-only-layer b/phase/testdata/restorer/buildpack.id/cache-only/file-from-cache-only-layer similarity index 100% rename from testdata/restorer/buildpack.id/cache-only/file-from-cache-only-layer rename to phase/testdata/restorer/buildpack.id/cache-only/file-from-cache-only-layer diff --git a/testdata/restorer/escaped_buildpack_id/escaped-bp-layer/file-from-escaped-bp b/phase/testdata/restorer/escaped_buildpack_id/escaped-bp-layer/file-from-escaped-bp similarity index 100% rename from testdata/restorer/escaped_buildpack_id/escaped-bp-layer/file-from-escaped-bp rename to phase/testdata/restorer/escaped_buildpack_id/escaped-bp-layer/file-from-escaped-bp diff --git a/testdata/restorer/nogroup.buildpack.id/some-layer/file-from-some-layer b/phase/testdata/restorer/nogroup.buildpack.id/some-layer/file-from-some-layer similarity index 100% rename from testdata/restorer/nogroup.buildpack.id/some-layer/file-from-some-layer rename to phase/testdata/restorer/nogroup.buildpack.id/some-layer/file-from-some-layer diff --git a/testmock/auth/mock_keychain.go b/phase/testmock/auth/mock_keychain.go similarity index 100% rename from testmock/auth/mock_keychain.go rename to phase/testmock/auth/mock_keychain.go diff --git a/testmock/build_env.go b/phase/testmock/build_env.go similarity index 97% rename from testmock/build_env.go rename to phase/testmock/build_env.go index 6fc83b109..59526c8d3 100644 --- a/testmock/build_env.go +++ b/phase/testmock/build_env.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: BuildEnv) +// Source: github.com/buildpacks/lifecycle/phase (interfaces: BuildEnv) // Package testmock is a generated GoMock package. package testmock diff --git a/testmock/build_executor.go b/phase/testmock/build_executor.go similarity index 100% rename from testmock/build_executor.go rename to phase/testmock/build_executor.go diff --git a/testmock/buildpack_api_verifier.go b/phase/testmock/buildpack_api_verifier.go similarity index 95% rename from testmock/buildpack_api_verifier.go rename to phase/testmock/buildpack_api_verifier.go index aaefe0733..86ca9b4f0 100644 --- a/testmock/buildpack_api_verifier.go +++ b/phase/testmock/buildpack_api_verifier.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: BuildpackAPIVerifier) +// Source: github.com/buildpacks/lifecycle/phase (interfaces: BuildpackAPIVerifier) // Package testmock is a generated GoMock package. package testmock diff --git a/testmock/cache/image_comparer.go b/phase/testmock/cache/image_comparer.go similarity index 100% rename from testmock/cache/image_comparer.go rename to phase/testmock/cache/image_comparer.go diff --git a/testmock/cache/image_deleter.go b/phase/testmock/cache/image_deleter.go similarity index 100% rename from testmock/cache/image_deleter.go rename to phase/testmock/cache/image_deleter.go diff --git a/testmock/cache_handler.go b/phase/testmock/cache_handler.go similarity index 88% rename from testmock/cache_handler.go rename to phase/testmock/cache_handler.go index c5281f85d..c62468fb6 100644 --- a/testmock/cache_handler.go +++ b/phase/testmock/cache_handler.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: CacheHandler) +// Source: github.com/buildpacks/lifecycle/phase (interfaces: CacheHandler) // Package testmock is a generated GoMock package. package testmock @@ -9,7 +9,7 @@ import ( gomock "github.com/golang/mock/gomock" - lifecycle "github.com/buildpacks/lifecycle" + phase "github.com/buildpacks/lifecycle/phase" ) // MockCacheHandler is a mock of CacheHandler interface. @@ -36,10 +36,10 @@ func (m *MockCacheHandler) EXPECT() *MockCacheHandlerMockRecorder { } // InitCache mocks base method. -func (m *MockCacheHandler) InitCache(arg0, arg1 string, arg2 bool) (lifecycle.Cache, error) { +func (m *MockCacheHandler) InitCache(arg0, arg1 string, arg2 bool) (phase.Cache, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitCache", arg0, arg1, arg2) - ret0, _ := ret[0].(lifecycle.Cache) + ret0, _ := ret[0].(phase.Cache) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/testmock/component_descriptor.go b/phase/testmock/component_descriptor.go similarity index 76% rename from testmock/component_descriptor.go rename to phase/testmock/component_descriptor.go index 2fbbeaf98..c2259de8e 100644 --- a/testmock/component_descriptor.go +++ b/phase/testmock/component_descriptor.go @@ -8,6 +8,8 @@ import ( reflect "reflect" gomock "github.com/golang/mock/gomock" + + buildpack "github.com/buildpacks/lifecycle/buildpack" ) // MockDescriptor is a mock of Descriptor interface. @@ -60,3 +62,17 @@ func (mr *MockDescriptorMockRecorder) Homepage() *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Homepage", reflect.TypeOf((*MockDescriptor)(nil).Homepage)) } + +// TargetsList mocks base method. +func (m *MockDescriptor) TargetsList() []buildpack.TargetMetadata { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TargetsList") + ret0, _ := ret[0].([]buildpack.TargetMetadata) + return ret0 +} + +// TargetsList indicates an expected call of TargetsList. +func (mr *MockDescriptorMockRecorder) TargetsList() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TargetsList", reflect.TypeOf((*MockDescriptor)(nil).TargetsList)) +} diff --git a/testmock/config_handler.go b/phase/testmock/config_handler.go similarity index 97% rename from testmock/config_handler.go rename to phase/testmock/config_handler.go index 68cbb3b2a..f1ceb5037 100644 --- a/testmock/config_handler.go +++ b/phase/testmock/config_handler.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: ConfigHandler) +// Source: github.com/buildpacks/lifecycle/phase (interfaces: ConfigHandler) // Package testmock is a generated GoMock package. package testmock diff --git a/testmock/detect_executor.go b/phase/testmock/detect_executor.go similarity index 100% rename from testmock/detect_executor.go rename to phase/testmock/detect_executor.go diff --git a/testmock/detect_resolver.go b/phase/testmock/detect_resolver.go similarity index 92% rename from testmock/detect_resolver.go rename to phase/testmock/detect_resolver.go index d62d81ad6..90ecd8510 100644 --- a/testmock/detect_resolver.go +++ b/phase/testmock/detect_resolver.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: DetectResolver) +// Source: github.com/buildpacks/lifecycle/phase (interfaces: DetectResolver) // Package testmock is a generated GoMock package. package testmock @@ -11,7 +11,7 @@ import ( gomock "github.com/golang/mock/gomock" buildpack "github.com/buildpacks/lifecycle/buildpack" - "github.com/buildpacks/lifecycle/platform/files" + files "github.com/buildpacks/lifecycle/platform/files" ) // MockDetectResolver is a mock of DetectResolver interface. diff --git a/testmock/dir_store.go b/phase/testmock/dir_store.go similarity index 97% rename from testmock/dir_store.go rename to phase/testmock/dir_store.go index 9db25b8c7..d47b47655 100644 --- a/testmock/dir_store.go +++ b/phase/testmock/dir_store.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: DirStore) +// Source: github.com/buildpacks/lifecycle/phase (interfaces: DirStore) // Package testmock is a generated GoMock package. package testmock diff --git a/testmock/dockerfile_applier.go b/phase/testmock/dockerfile_applier.go similarity index 97% rename from testmock/dockerfile_applier.go rename to phase/testmock/dockerfile_applier.go index 06b0bd185..e922a46f9 100644 --- a/testmock/dockerfile_applier.go +++ b/phase/testmock/dockerfile_applier.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: DockerfileApplier) +// Source: github.com/buildpacks/lifecycle/phase (interfaces: DockerfileApplier) // Package testmock is a generated GoMock package. package testmock diff --git a/testmock/generate_executor.go b/phase/testmock/generate_executor.go similarity index 100% rename from testmock/generate_executor.go rename to phase/testmock/generate_executor.go diff --git a/testmock/image_handler.go b/phase/testmock/image_handler.go similarity index 100% rename from testmock/image_handler.go rename to phase/testmock/image_handler.go diff --git a/testmock/layer_factory.go b/phase/testmock/layer_factory.go similarity index 97% rename from testmock/layer_factory.go rename to phase/testmock/layer_factory.go index 885c8898d..1e0aede74 100644 --- a/testmock/layer_factory.go +++ b/phase/testmock/layer_factory.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: LayerFactory) +// Source: github.com/buildpacks/lifecycle/phase (interfaces: LayerFactory) // Package testmock is a generated GoMock package. package testmock diff --git a/testmock/metadata_restorer.go b/phase/testmock/metadata_restorer.go similarity index 97% rename from testmock/metadata_restorer.go rename to phase/testmock/metadata_restorer.go index aab08aa3a..6f3f52a62 100644 --- a/testmock/metadata_restorer.go +++ b/phase/testmock/metadata_restorer.go @@ -12,7 +12,7 @@ import ( buildpack "github.com/buildpacks/lifecycle/buildpack" layer "github.com/buildpacks/lifecycle/internal/layer" platform "github.com/buildpacks/lifecycle/platform" - "github.com/buildpacks/lifecycle/platform/files" + files "github.com/buildpacks/lifecycle/platform/files" ) // MockMetadataRestorer is a mock of MetadataRestorer interface. diff --git a/testmock/ref.go b/phase/testmock/ref.go similarity index 100% rename from testmock/ref.go rename to phase/testmock/ref.go diff --git a/testmock/registry_handler.go b/phase/testmock/registry_handler.go similarity index 96% rename from testmock/registry_handler.go rename to phase/testmock/registry_handler.go index 737a15aa3..258ccf414 100644 --- a/testmock/registry_handler.go +++ b/phase/testmock/registry_handler.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/buildpacks/lifecycle (interfaces: RegistryHandler) +// Source: github.com/buildpacks/lifecycle/image (interfaces: RegistryHandler) // Package testmock is a generated GoMock package. package testmock diff --git a/testmock/sbom_restorer.go b/phase/testmock/sbom_restorer.go similarity index 100% rename from testmock/sbom_restorer.go rename to phase/testmock/sbom_restorer.go diff --git a/utils.go b/phase/utils.go similarity index 95% rename from utils.go rename to phase/utils.go index fb39803af..3e6af3659 100644 --- a/utils.go +++ b/phase/utils.go @@ -1,4 +1,4 @@ -package lifecycle +package phase import ( "strings" diff --git a/utils_test.go b/phase/utils_test.go similarity index 78% rename from utils_test.go rename to phase/utils_test.go index b5d396acb..18d5c484e 100644 --- a/utils_test.go +++ b/phase/utils_test.go @@ -1,4 +1,4 @@ -package lifecycle_test +package phase_test import ( "testing" @@ -7,7 +7,7 @@ import ( "github.com/sclevine/spec" "github.com/sclevine/spec/report" - "github.com/buildpacks/lifecycle" + "github.com/buildpacks/lifecycle/phase" ) func TestUtils(t *testing.T) { @@ -17,7 +17,7 @@ func TestUtils(t *testing.T) { func testUtils(t *testing.T, when spec.G, it spec.S) { when(".TruncateSha", func() { it("should truncate the sha", func() { - actual := lifecycle.TruncateSha("ed649d0a36b218c476b64d61f85027477ef5742045799f45c8c353562279065a") + actual := phase.TruncateSha("ed649d0a36b218c476b64d61f85027477ef5742045799f45c8c353562279065a") if s := cmp.Diff(actual, "ed649d0a36b2"); s != "" { t.Fatalf("Unexpected sha:\n%s\n", s) } @@ -25,7 +25,7 @@ func testUtils(t *testing.T, when spec.G, it spec.S) { it("should not truncate the sha with it's short", func() { sha := "not-a-sha" - actual := lifecycle.TruncateSha(sha) + actual := phase.TruncateSha(sha) if s := cmp.Diff(actual, sha); s != "" { t.Fatalf("Unexpected sha:\n%s\n", s) } @@ -33,7 +33,7 @@ func testUtils(t *testing.T, when spec.G, it spec.S) { it("should remove the prefix", func() { sha := "sha256:ed649d0a36b218c476b64d61f85027477ef5742045799f45c8c353562279065a" - actual := lifecycle.TruncateSha(sha) + actual := phase.TruncateSha(sha) if s := cmp.Diff(actual, "ed649d0a36b2"); s != "" { t.Fatalf("Unexpected sha:\n%s\n", s) }