diff --git a/pkg/platform/runtime/buildplan/buildplan.go b/pkg/platform/runtime/buildplan/buildplan.go index 737163ac8a..ad646245ff 100644 --- a/pkg/platform/runtime/buildplan/buildplan.go +++ b/pkg/platform/runtime/buildplan/buildplan.go @@ -19,8 +19,23 @@ type ArtifactListing struct { artifactIDs []artifact.ArtifactID } -func NewArtifactListing(build *model.Build) *ArtifactListing { - return &ArtifactListing{build: build} +func NewArtifactListing(build *model.Build, buildtimeClosure bool) (*ArtifactListing, error) { + al := &ArtifactListing{build: build} + if buildtimeClosure { + buildtimeClosure, err := newMapFromBuildPlan(al.build, true) + if err != nil { + return nil, errs.Wrap(err, "Could not create buildtime closure") + } + al.buildtimeClosure = buildtimeClosure + } else { + runtimeClosure, err := newMapFromBuildPlan(al.build, false) + if err != nil { + return nil, errs.Wrap(err, "Could not create runtime closure") + } + al.runtimeClosure = runtimeClosure + } + + return al, nil } func (al *ArtifactListing) RuntimeClosure() (artifact.Map, error) { @@ -56,30 +71,28 @@ func (al *ArtifactListing) ArtifactIDs(buildtimeClosure bool) ([]artifact.Artifa return al.artifactIDs, nil } + var artifactMap artifact.Map + var err error if buildtimeClosure { - if al.buildtimeClosure != nil { - for _, artifact := range al.buildtimeClosure { - al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) + if al.buildtimeClosure == nil { + artifactMap, err = al.BuildtimeClosure() + if err != nil { + return nil, errs.Wrap(err, "Could not calculate buildtime closure") } - return al.artifactIDs, nil - } - - buildTimeClosure, err := al.BuildtimeClosure() - if err != nil { - return nil, errs.Wrap(err, "Could not create buildtime closure") - } - - for _, artifact := range buildTimeClosure { - al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) } } else { - if al.runtimeClosure != nil { - for _, artifact := range al.runtimeClosure { - al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) + if al.runtimeClosure == nil { + artifactMap, err = al.RuntimeClosure() + if err != nil { + return nil, errs.Wrap(err, "Could not calculate runtime closure") } } } + for _, artifact := range artifactMap { + al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID) + } + return al.artifactIDs, nil } diff --git a/pkg/platform/runtime/setup/setup.go b/pkg/platform/runtime/setup/setup.go index 389af26017..b4f66c76cd 100644 --- a/pkg/platform/runtime/setup/setup.go +++ b/pkg/platform/runtime/setup/setup.go @@ -402,9 +402,17 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal return nil, nil, errs.Wrap(err, "Could not handle SolveSuccess event") } + // If the build is not ready or if we are installing the buildtime closure + // then we need to include the buildtime closure in the changed artifacts + // and the progress reporting. + includeBuildtimeClosure := strings.EqualFold(os.Getenv(constants.InstallBuildDependencies), "true") || !buildResult.BuildReady + // Compute and handle the change summary var requestedArtifacts artifact.Map // Artifacts required for the runtime to function - artifactListing := buildplan.NewArtifactListing(buildResult.Build) + artifactListing, err := buildplan.NewArtifactListing(buildResult.Build, includeBuildtimeClosure) + if err != nil { + return nil, nil, errs.Wrap(err, "Failed to create artifact listing") + } // If we are installing build dependencies, then the requested artifacts // will include the buildtime closure. Otherwise, we only need the runtime @@ -465,10 +473,6 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal s.analytics.Event(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeBuild, dimensions) } - // If the build is not ready or if we are installing the buildtime closure - // then we need to include the buildtime closure in the changed artifacts - // and the progress reporting. - includeBuildtimeClosure := strings.EqualFold(os.Getenv(constants.InstallBuildDependencies), "true") || !buildResult.BuildReady changedArtifacts, err := buildplan.NewBaseArtifactChangesetByBuildPlan(buildResult.Build, false, includeBuildtimeClosure) if err != nil { return nil, nil, errs.Wrap(err, "Could not compute base artifact changeset")