in pkg/trait/builder.go [166:285]
func (t *builderTrait) builderTask(e *Environment) (*v1.BuilderTask, error) {
maven := v1.MavenBuildSpec{
MavenSpec: e.Platform.Status.Build.Maven,
}
// Add Maven repositories defined in the IntegrationKit
for _, repo := range e.IntegrationKit.Spec.Repositories {
maven.Repositories = append(maven.Repositories, mvn.NewRepository(repo))
}
if trait := e.Catalog.GetTrait(quarkusTraitID); trait != nil {
quarkus, ok := trait.(*quarkusTrait)
isNativeIntegration := quarkus.isNativeIntegration(e)
isNativeKit, err := quarkus.isNativeKit(e)
if err != nil {
return nil, err
}
// The builder trait must define certain resources requirements when we have a native build
if ok && pointer.BoolDeref(quarkus.Enabled, true) && (isNativeIntegration || isNativeKit) {
// Force the build to run in a separate Pod and strictly sequential
t.L.Info("This is a Quarkus native build: setting build configuration with build Pod strategy, 1 CPU core and 4 GiB memory. Make sure your cluster can handle it.")
t.Strategy = string(v1.BuildStrategyPod)
t.OrderStrategy = string(v1.BuildOrderStrategySequential)
t.RequestCPU = "1000m"
t.RequestMemory = "4Gi"
}
}
buildConfig := v1.BuildConfiguration{
RequestCPU: t.RequestCPU,
RequestMemory: t.RequestMemory,
LimitCPU: t.LimitCPU,
LimitMemory: t.LimitMemory,
}
if t.Strategy != "" {
t.L.Infof("User defined build strategy %s", t.Strategy)
found := false
for _, s := range v1.BuildStrategies {
if string(s) == t.Strategy {
found = true
buildConfig.Strategy = s
break
}
}
if !found {
var strategies []string
for _, s := range v1.BuildStrategies {
strategies = append(strategies, string(s))
}
return nil, fmt.Errorf("unknown build strategy: %s. One of [%s] is expected", t.Strategy, strings.Join(strategies, ", "))
}
}
if t.OrderStrategy != "" {
t.L.Infof("User defined build order strategy %s", t.OrderStrategy)
found := false
for _, s := range v1.BuildOrderStrategies {
if string(s) == t.OrderStrategy {
found = true
buildConfig.OrderStrategy = s
break
}
}
if !found {
var strategies []string
for _, s := range v1.BuildOrderStrategies {
strategies = append(strategies, string(s))
}
return nil, fmt.Errorf("unknown build order strategy: %s. One of [%s] is expected", t.OrderStrategy, strings.Join(strategies, ", "))
}
}
task := &v1.BuilderTask{
BaseTask: v1.BaseTask{
Name: "builder",
},
Configuration: buildConfig,
BaseImage: e.Platform.Status.Build.BaseImage,
Runtime: e.CamelCatalog.Runtime,
Dependencies: e.IntegrationKit.Spec.Dependencies,
Maven: maven,
}
if task.Maven.Properties == nil {
task.Maven.Properties = make(map[string]string)
}
// User provided Maven properties
if t.Properties != nil {
for _, v := range t.Properties {
key, value := property.SplitPropertyFileEntry(v)
if len(key) == 0 || len(value) == 0 {
return nil, fmt.Errorf("maven property must have key=value format, it was %v", v)
}
task.Maven.Properties[key] = value
}
}
// User provides a maven profile
if t.MavenProfile != "" {
mavenProfile, err := v1.DecodeValueSource(t.MavenProfile, "profile.xml",
"illegal profile definition, syntax: configmap|secret:resource-name[/profile path]")
if err != nil {
return nil, fmt.Errorf("invalid maven profile: %s: %w. ", t.MavenProfile, err)
}
task.Maven.Profile = mavenProfile
}
steps := make([]builder.Step, 0)
steps = append(steps, builder.Project.CommonSteps...)
// sort steps by phase
sort.SliceStable(steps, func(i, j int) bool {
return steps[i].Phase() < steps[j].Phase()
})
task.Steps = builder.StepIDsFor(steps...)
return task, nil
}