Skip to content

Commit

Permalink
Get build time artifact calculation working
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Sep 26, 2023
1 parent c875c3e commit 95f2dd1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
3 changes: 3 additions & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const DisableUpdates = "ACTIVESTATE_CLI_DISABLE_UPDATES"
// UpdateBranchEnvVarName is the env var that is used to override which branch to pull the update from
const UpdateBranchEnvVarName = "ACTIVESTATE_CLI_UPDATE_BRANCH"

// InstallBuildDependencies is the env var that is used to override whether to install build dependencies
const InstallBuildDependencies = "ACTIVESTATE_CLI_INSTALL_BUILD_DEPENDENCIES"

// InternalConfigFileNameLegacy is effectively the same as InternalConfigName, but includes our preferred extension
const InternalConfigFileNameLegacy = "config.yaml"

Expand Down
2 changes: 1 addition & 1 deletion pkg/platform/api/buildplanner/model/buildplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (

// Tag types
TagSource = "src"
TagDependency = "dep"
TagDependency = "deps"
TagBuilder = "builder"
TagOrphan = "orphans"

Expand Down
7 changes: 3 additions & 4 deletions pkg/platform/model/buildplanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@ func (bp *BuildPlanner) FetchBuildResult(commitID strfmt.UUID, owner, project st
}

res := BuildResult{
BuildEngine: buildEngine,
Build: build,
// BuildReady: build.Status == bpModel.Completed,
BuildReady: false,
BuildEngine: buildEngine,
Build: build,
BuildReady: build.Status == bpModel.Completed,
CommitID: id,
BuildExpression: expr,
BuildStatus: build.Status,
Expand Down
29 changes: 13 additions & 16 deletions pkg/platform/runtime/buildplan/buildplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,8 @@ func buildBuildClosureMap(baseID strfmt.UUID, lookup map[strfmt.UUID]interface{}
return errs.New("Incorrect target type for id %s, expected Artifact", baseID)
}

_, ok = result[strfmt.UUID(currentArtifact.NodeID)]
// We are only interested in artifacts that have not already been added
// to the result and that have been submitted to be built.
if ok || currentArtifact.Status == model.ArtifactNotSubmitted {
if currentArtifact.MimeType == model.XActiveStateBuilderMimeType {
// Dependency is a builder, skipping
return nil
}

Expand All @@ -365,20 +363,20 @@ func buildBuildClosureMap(baseID strfmt.UUID, lookup map[strfmt.UUID]interface{}
for a := range recursiveDeps {
deps[a] = struct{}{}
}

// For each runtime dependency we need to add its dependencies
// to the result map.
err = buildBuildClosureMap(depID, lookup, result)
if err != nil {
return errs.Wrap(err, "Could not build map for runtime dependency %s", currentArtifact.NodeID)
}
}

// We need to convert the map of dependencies to a list of
// dependencies.
var uniqueDeps []strfmt.UUID
for depID := range deps {
uniqueDeps = append(uniqueDeps, depID)

// For each buildtime dependency we need to add it and its dependencies
// to the result map.
err := buildBuildClosureMap(depID, lookup, result)
if err != nil {
return errs.Wrap(err, "Could not build map for runtime dependency %s", currentArtifact.NodeID)
}
}

// We need to get the source information for the artifact.
Expand Down Expand Up @@ -419,18 +417,17 @@ func generateBuildtimeDependencies(artifactID strfmt.UUID, lookup map[strfmt.UUI
return nil, errs.New("Incorrect target type for id %s, expected Artifact or Source", artifactID)
}

result[artifactID] = struct{}{}

if artifact.MimeType == model.XActiveStateBuilderMimeType {
// Dependency is a builder, skipping
return nil, nil
}

// Once we have verified that the artifact has a step that generated it
// we add it to the result map.
result[artifactID] = struct{}{}

// We iterate through the direct dependencies of the artifact
// and recursively add all of the dependencies of those artifacts map.
for _, depID := range artifact.RuntimeDependencies {
result[artifactID] = struct{}{}
_, err := generateBuildtimeDependencies(depID, lookup, result)
if err != nil {
return nil, errs.Wrap(err, "Could not build map for runtime dependencies of artifact %s", artifact.NodeID)
Expand All @@ -455,7 +452,7 @@ func generateBuildtimeDependencies(artifactID strfmt.UUID, lookup map[strfmt.UUI
// artifact and recursively add all of the dependencies and builders
// of those artifacts.
for _, input := range step.Inputs {
if input.Tag != model.TagDependency || input.Tag != model.TagBuilder {
if input.Tag != model.TagDependency && input.Tag != model.TagBuilder {
continue
}

Expand Down
21 changes: 17 additions & 4 deletions pkg/platform/runtime/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,21 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal

// Compute and handle the change summary
// runtimeAndBuildtimeArtifacts records all artifacts that will need to be built in order to obtain the runtime.
// Disabled due to DX-2033.
// Please use this var when we come back to this in the future as we need to make a clear distinction between this
// and runtime-only artifacts.
// var runtimeAndBuildtimeArtifacts artifact.Map
var runtimeAndBuildtimeArtifacts artifact.Map
var runtimeArtifacts artifact.Map // Artifacts required for the runtime to function
if buildResult.Build != nil {
runtimeArtifacts, err = buildplan.NewMapFromBuildPlan(buildResult.Build)
if err != nil {
return nil, nil, errs.Wrap(err, "Failed to create artifact map from build plan")
}

if strings.EqualFold(os.Getenv(constants.InstallBuildDependencies), "true") {
runtimeAndBuildtimeArtifacts, err = buildplan.BuildtimeArtifacts(buildResult.Build)
if err != nil {
return nil, nil, errs.Wrap(err, "Failed to create artifact map from build plan")
}
runtimeArtifacts = runtimeAndBuildtimeArtifacts
}
}

setup, err := s.selectSetupImplementation(buildResult.BuildEngine, runtimeArtifacts)
Expand Down Expand Up @@ -506,6 +511,14 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal
return nil, nil, errs.Wrap(err, "Could not get buildtime artifacts")
}

buildtimeArtifactIDs := []artifact.ArtifactID{}
for _, a := range buildtimeArtifacts {
buildtimeArtifactIDs = append(buildtimeArtifactIDs, a.ArtifactID)
}

// Update artifactNames to ensure it now includes buildtime artifacts
artifactNames = artifact.ResolveArtifactNames(setup.ResolveArtifactName, buildtimeArtifactIDs)

buildList := []string{}
for _, a := range buildtimeArtifacts {
buildList = append(buildList, artifactNames[a.ArtifactID])
Expand Down

0 comments on commit 95f2dd1

Please sign in to comment.