From 62eb279fa09d92f6dca9d1f984ca9330ed0c83b3 Mon Sep 17 00:00:00 2001 From: Pavel Busko Date: Wed, 26 Jun 2024 10:05:36 +0200 Subject: [PATCH] Write analyzed.toml with target metadata --- cmd/builder/cli/cli.go | 24 +++++++++++++++++++++++- integration/lifecycle_test.go | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/builder/cli/cli.go b/cmd/builder/cli/cli.go index c4779c0..26c0f8e 100644 --- a/cmd/builder/cli/cli.go +++ b/cmd/builder/cli/cli.go @@ -7,6 +7,7 @@ import ( "encoding/json" "os" "path/filepath" + "runtime" "code.cloudfoundry.org/cnbapplifecycle/pkg/archive" "code.cloudfoundry.org/cnbapplifecycle/pkg/errors" @@ -101,6 +102,13 @@ var builderCmd = &cobra.Command{ return errors.ErrGenericBuild } + analyzePath := filepath.Join(layersDir, "analyzed.toml") + analyzeMD, err := writeAnalyzed(analyzePath, logger) + if err != nil { + logger.Errorf("failed to create 'analyzed.toml', error: %s\n", err.Error()) + return errors.ErrGenericBuild + } + creds, err := keychain.FromEnv() if err != nil { logger.Errorf("failed to parse %s environment variable, error: %s\n", keychain.CnbCredentialsEnv, err.Error()) @@ -128,6 +136,7 @@ var builderCmd = &cobra.Command{ ) detector, err := detectorFactory.NewDetector(platform.LifecycleInputs{ + AnalyzedPath: analyzePath, PlatformAPI: platformAPI, AppDir: workspaceDir, BuildpacksDir: buildpacksDir, @@ -179,7 +188,7 @@ var builderCmd = &cobra.Command{ Err: os.Stderr, Plan: plan, PlatformAPI: platformAPI, - AnalyzeMD: files.Analyzed{}, + AnalyzeMD: analyzeMD, } logger.Phase("BUILDING") @@ -270,3 +279,16 @@ var builderCmd = &cobra.Command{ return nil }, } + +func writeAnalyzed(path string, logger *log.Logger) (files.Analyzed, error) { + analyzed := files.Analyzed{ + RunImage: &files.RunImage{ + TargetMetadata: &files.TargetMetadata{ + OS: "linux", + Arch: runtime.GOARCH, + }, + }, + } + + return analyzed, files.Handler.WriteAnalyzed(path, &analyzed, logger) +} diff --git a/integration/lifecycle_test.go b/integration/lifecycle_test.go index 23d6567..16ad605 100644 --- a/integration/lifecycle_test.go +++ b/integration/lifecycle_test.go @@ -114,6 +114,8 @@ var _ = Describe("Lifecycle", func() { Expect(err).To(BeNil()) outString := buf.String() + Expect(outString).To(ContainSubstring("Run image info in analyzed metadata is")) + Expect(outString).To(ContainSubstring("Checking for match against descriptor")) Expect(outString).To(ContainSubstring("Finished running build")) Expect(outString).To(ContainSubstring("Copying SBOM files")) Expect(outString).To(ContainSubstring("Listing processes"))