Skip to content

Commit e620f56

Browse files
committed
Correct handling of project_version/enforce_version. Remove unused tool_version
1 parent b056a8f commit e620f56

File tree

7 files changed

+44
-37
lines changed

7 files changed

+44
-37
lines changed

deploy/tasks/pre-build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ spec:
8282
memory: 512Mi
8383
script: |
8484
$(params.BUILD_SCRIPT)
85-
/opt/jboss/container/java/run/run-java.sh $(params.BUILD_TOOL)-prepare --java-home=$(params.JAVA_HOME) --build-tool-version=$(params.BUILD_TOOL_VERSION) $(workspaces.source.path)/source --recipe-image=$(params.RECIPE_IMAGE) --request-processor-image=$(params.JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE) --disabled-plugins=$(params.BUILD_PLUGINS)
85+
/opt/jboss/container/java/run/run-java.sh $(params.BUILD_TOOL)-prepare --java-home=$(params.JAVA_HOME) --build-tool-version=$(params.BUILD_TOOL_VERSION) --recipe-image=$(params.RECIPE_IMAGE) --request-processor-image=$(params.JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE) --disabled-plugins=$(params.BUILD_PLUGINS) $(workspaces.source.path)/source
8686
# TODO: Look at making this optional until we know whether we need to store source
8787
- name: create-pre-build-source
8888
image: $(params.JVM_BUILD_SERVICE_REQPROCESSOR_IMAGE)

java-components/build-request-processor/src/main/java/com/redhat/hacbs/container/build/preprocessor/AbstractPreprocessor.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
public abstract class AbstractPreprocessor implements Runnable {
1717

18+
/**
19+
* Equivalent to <code>$(workspaces.source.path)/source</code>
20+
*/
1821
@CommandLine.Parameters(description = "The directory to process")
1922
protected Path buildRoot;
2023

@@ -37,7 +40,12 @@ protected enum ToolType {
3740
ANT,
3841
GRADLE,
3942
MAVEN,
40-
SBT
43+
SBT;
44+
45+
@Override
46+
public String toString() {
47+
return name().toLowerCase();
48+
}
4149
}
4250

4351
protected ToolType type;
@@ -51,12 +59,14 @@ public void run() {
5159
//noinspection ResultOfMethodCallIgnored
5260
jbsDirectory.toFile().mkdirs();
5361

62+
Log.warnf("### ENV {}", System.getenv("jvm-build-service"));
63+
5464
String containerFile = """
5565
FROM %s
5666
USER 0
5767
WORKDIR /var/workdir
5868
RUN mkdir -p /var/workdir/software/settings /original-content/marker
59-
# CACHE_URL is deprecated.
69+
6070
ARG CACHE_URL=""
6171
ENV CACHE_URL=$CACHE_URL
6272
COPY .jbs/run-build.sh /var/workdir

pkg/reconciler/dependencybuild/buildrecipeyaml.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,23 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
158158
javaHome = "/lib/jvm/java-" + recipe.JavaVersion
159159
}
160160

161-
var toolVersion string
162161
toolEnv := []v1.EnvVar{}
163162
if recipe.ToolVersions["maven"] != "" {
164163
toolEnv = append(toolEnv, v1.EnvVar{Name: "MAVEN_HOME", Value: "/opt/maven/" + recipe.ToolVersions["maven"]})
165-
toolVersion = recipe.ToolVersions["maven"]
166164
}
167165
if recipe.ToolVersions["gradle"] != "" {
168166
toolEnv = append(toolEnv, v1.EnvVar{Name: "GRADLE_HOME", Value: "/opt/gradle/" + recipe.ToolVersions["gradle"]})
169-
toolVersion = recipe.ToolVersions["gradle"]
170167
}
171168
if recipe.ToolVersions["ant"] != "" {
172169
toolEnv = append(toolEnv, v1.EnvVar{Name: "ANT_HOME", Value: "/opt/ant/" + recipe.ToolVersions["ant"]})
173-
toolVersion = recipe.ToolVersions["ant"]
174170
}
175171
if recipe.ToolVersions["sbt"] != "" {
176172
toolEnv = append(toolEnv, v1.EnvVar{Name: "SBT_DIST", Value: "/opt/sbt/" + recipe.ToolVersions["sbt"]})
177-
toolVersion = recipe.ToolVersions["sbt"]
178173
}
179-
//toolEnv = append(toolEnv, v1.EnvVar{Name: PipelineParamToolVersion, Value: recipe.ToolVersion})
180-
//toolEnv = append(toolEnv, v1.EnvVar{Name: PipelineParamProjectVersion, Value: db.Spec.Version})
181174
toolEnv = append(toolEnv, v1.EnvVar{Name: JavaHome, Value: javaHome})
175+
// Used by JBS to override the version
182176
toolEnv = append(toolEnv, v1.EnvVar{Name: PipelineParamEnforceVersion, Value: recipe.EnforceVersion})
177+
toolEnv = append(toolEnv, v1.EnvVar{Name: PipelineParamProjectVersion, Value: db.Spec.Version})
183178

184179
additionalMemory := recipe.AdditionalMemory
185180
if systemConfig.Spec.MaxAdditionalMemory > 0 && additionalMemory > systemConfig.Spec.MaxAdditionalMemory {
@@ -288,8 +283,6 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
288283
{Name: PipelineParamJavaVersion, Type: tektonpipeline.ParamTypeString},
289284
// {Name: PipelineParamToolVersion, Type: tektonpipeline.ParamTypeString},
290285
{Name: PipelineParamPath, Type: tektonpipeline.ParamTypeString},
291-
{Name: PipelineParamEnforceVersion, Type: tektonpipeline.ParamTypeString},
292-
{Name: PipelineParamProjectVersion, Type: tektonpipeline.ParamTypeString},
293286
{Name: PipelineParamCacheUrl, Type: tektonpipeline.ParamTypeString, Default: &tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: cacheUrl}},
294287
}
295288
secretVariables := secretVariables(jbsConfig)
@@ -455,7 +448,7 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
455448
Name: "BUILD_TOOL_VERSION",
456449
Value: tektonpipeline.ParamValue{
457450
Type: tektonpipeline.ParamTypeString,
458-
StringVal: toolVersion,
451+
StringVal: recipe.ToolVersion,
459452
},
460453
},
461454
{
@@ -550,8 +543,11 @@ func createPipelineSpec(log logr.Logger, tool string, commitTime int64, jbsConfi
550543
{
551544
Name: "BUILD_ARGS",
552545
Value: tektonpipeline.ParamValue{
553-
Type: tektonpipeline.ParamTypeArray,
554-
ArrayVal: []string{"CACHE_URL=" + cacheUrl},
546+
Type: tektonpipeline.ParamTypeArray,
547+
ArrayVal: []string{
548+
// This allows us to set environment variables that can be picked up by our Containerfile/build script.
549+
"CACHE_URL=" + cacheUrl,
550+
},
555551
},
556552
},
557553
},

pkg/reconciler/dependencybuild/dependencybuild.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const (
5050
PipelineParamChainsGitCommit = "CHAINS-GIT_COMMIT"
5151
PipelineParamGoals = "GOALS"
5252
PipelineParamJavaVersion = "JAVA_VERSION"
53-
PipelineParamToolVersion = "TOOL_VERSION"
5453
PipelineParamEnforceVersion = "ENFORCE_VERSION"
5554
PipelineParamProjectVersion = "PROJECT_VERSION"
5655
PipelineParamCacheUrl = "CACHE_URL"
@@ -591,9 +590,6 @@ func (r *ReconcileDependencyBuild) handleStateBuilding(ctx context.Context, db *
591590
{Name: PipelineParamChainsGitCommit, Value: tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: db.Spec.ScmInfo.CommitHash}},
592591
{Name: PipelineParamPath, Value: tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: contextDir}},
593592
{Name: PipelineParamGoals, Value: tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeArray, ArrayVal: attempt.Recipe.CommandLine}},
594-
{Name: PipelineParamEnforceVersion, Value: tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: attempt.Recipe.EnforceVersion}},
595-
{Name: PipelineParamProjectVersion, Value: tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: db.Spec.Version}},
596-
// {Name: PipelineParamToolVersion, Value: tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: attempt.Recipe.ToolVersion}},
597593
{Name: PipelineParamJavaVersion, Value: tektonpipeline.ResultValue{Type: tektonpipeline.ParamTypeString, StringVal: attempt.Recipe.JavaVersion}},
598594
}
599595

@@ -636,18 +632,25 @@ func (r *ReconcileDependencyBuild) handleStateBuilding(ctx context.Context, db *
636632
},
637633
}},
638634
}
639-
if orasOptions != "" {
640-
pr.Spec.TaskRunTemplate = tektonpipeline.PipelineTaskRunTemplate{
641-
PodTemplate: &pod.Template{
642-
Env: []v1.EnvVar{
643-
{
644-
Name: "ORAS_OPTIONS",
645-
Value: orasOptions,
646-
},
635+
pr.Spec.TaskRunTemplate = tektonpipeline.PipelineTaskRunTemplate{
636+
PodTemplate: &pod.Template{
637+
Env: []v1.EnvVar{
638+
{
639+
Name: util.ControllerNamespace,
640+
Value: util.ControllerDeploymentName,
647641
},
648642
},
649-
}
643+
},
650644
}
645+
if orasOptions != "" {
646+
pr.Spec.TaskRunTemplate.PodTemplate.Env = append([]v1.EnvVar{
647+
{
648+
Name: "ORAS_OPTIONS",
649+
Value: orasOptions,
650+
},
651+
}, pr.Spec.TaskRunTemplate.PodTemplate.Env...)
652+
}
653+
651654
if jbsConfig.Annotations != nil && jbsConfig.Annotations[jbsconfig.CITests] == "true" {
652655
log.Info(fmt.Sprintf("Configuring resources for %#v", BuildTaskName))
653656
podMemR, _ := resource.ParseQuantity("1792Mi")

pkg/reconciler/dependencybuild/dependencybuild_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func TestStateDetect(t *testing.T) {
228228
g.Expect(or.Name).Should(Equal(db.Name))
229229
}
230230
}
231-
g.Expect(len(tr.Spec.Params)).Should(Equal(12))
231+
g.Expect(len(tr.Spec.Params)).Should(Equal(9))
232232
for _, param := range tr.Spec.Params {
233233
switch param.Name {
234234
case PipelineParamScmHash:
@@ -244,8 +244,6 @@ func TestStateDetect(t *testing.T) {
244244
g.Expect(param.Value.StringVal).Should(Equal("some-url"))
245245
case PipelineParamGoals:
246246
g.Expect(param.Value.ArrayVal).Should(ContainElement("testgoal"))
247-
case PipelineParamEnforceVersion:
248-
g.Expect(param.Value.StringVal).Should(BeEmpty())
249247
}
250248
}
251249
}

pkg/reconciler/dependencybuild/scripts/gradle-build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export PATH="${JAVA_HOME}/bin:${PATH}"
4141
#so just create one to fool the plugin
4242
git config user.email "[email protected]"
4343
git config user.name "HACBS"
44-
if [ -n "$(params.ENFORCE_VERSION)" ]; then
45-
echo "Creating tag $(params.PROJECT_VERSION) to match enforced version"
46-
git tag -m $(params.PROJECT_VERSION) -a $(params.PROJECT_VERSION) || true
44+
if [ ! -z ${ENFORCE_VERSION+x} ]; then
45+
echo "Creating tag ${PROJECT_VERSION} to match enforced version"
46+
git tag -m ${PROJECT_VERSION} -a ${PROJECT_VERSION} || true
4747
fi
4848

4949
if [ ! -d "${GRADLE_HOME}" ]; then

pkg/reconciler/dependencybuild/scripts/maven-build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ cat >>"$TOOLCHAINS_XML" <<EOF
4242
</toolchains>
4343
EOF
4444

45-
if [ -n "$(params.ENFORCE_VERSION)" ]; then
46-
echo "Setting version to $(params.PROJECT_VERSION) to match enforced version"
47-
mvn -B -e -s "$(workspaces.build-settings.path)/settings.xml" -t "$(workspaces.build-settings.path)/toolchains.xml" org.codehaus.mojo:versions-maven-plugin:2.8.1:set -DnewVersion="$(params.PROJECT_VERSION)" | tee $(workspaces.source.path)/logs/enforce-version.log
45+
if [ ! -z ${ENFORCE_VERSION+x} ]; then
46+
echo "Setting version to ${PROJECT_VERSION} to match enforced version"
47+
mvn -B -e -s "$(workspaces.build-settings.path)/settings.xml" -t "$(workspaces.build-settings.path)/toolchains.xml" org.codehaus.mojo:versions-maven-plugin:2.8.1:set -DnewVersion="${PROJECT_VERSION}" | tee $(workspaces.source.path)/logs/enforce-version.log
4848
fi
4949

5050
#if we run out of memory we want the JVM to die with error code 134

0 commit comments

Comments
 (0)