Skip to content

Commit 7559dd6

Browse files
committed
Make BUILD_SCRIPT an environment variable. Move more configuration to preprocessor
1 parent bc1f788 commit 7559dd6

File tree

6 files changed

+96
-23
lines changed

6 files changed

+96
-23
lines changed

deploy/tasks/pre-build.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ spec:
8383
script: |
8484
$(params.BUILD_SCRIPT)
8585
/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
86+
env:
87+
- name: BUILD_SCRIPT
88+
value: $(params.BUILD_SCRIPT)
8689
# TODO: Look at making this optional until we know whether we need to store source
8790
- name: create-pre-build-source
8891
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: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.redhat.hacbs.container.build.preprocessor;
22

3+
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
4+
35
import java.io.IOException;
46
import java.nio.file.Files;
57
import java.nio.file.Path;
@@ -9,8 +11,6 @@
911
import io.quarkus.logging.Log;
1012
import picocli.CommandLine;
1113

12-
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
13-
1414
/**
1515
* We keep all the options the same between maven, gradle, sbt and ant for now to keep the pipeline setup simpler.
1616
* Some of these may be ignored by different processors
@@ -55,13 +55,84 @@ public String toString() {
5555
@Override
5656
public void run() {
5757

58-
Log.warnf("### Using tool {} with version {} and javaHome {}", type, buildToolVersion, javaHome);
58+
Log.warnf("### Using tool %s with version %s and javaHome %s", type, buildToolVersion, javaHome);
59+
Log.warnf("### ENV %s", System.getenv("jvm-build-service"));
60+
Log.warnf("### BUILD_SCRIPT %s", System.getenv("BUILD_SCRIPT"));
5961

6062
Path jbsDirectory = Path.of(buildRoot.toString(), ".jbs");
6163
//noinspection ResultOfMethodCallIgnored
6264
jbsDirectory.toFile().mkdirs();
6365

64-
Log.warnf("### ENV %s", System.getenv("jvm-build-service"));
66+
String runBuild = """
67+
#!/usr/bin/env bash
68+
set -o verbose
69+
set -eu
70+
set -o pipefail
71+
72+
export LANG="en_US.UTF-8"
73+
export LC_ALL="en_US.UTF-8"
74+
export JAVA_HOME=%s
75+
# This might get overridden by the tool home configuration below. This is
76+
# useful if Gradle/Ant also requires Maven configured.
77+
export MAVEN_HOME=/opt/maven/3.8.8
78+
export %s_HOME=/opt/%s/%s
79+
80+
cd %s
81+
mkdir -p ../logs ../packages
82+
83+
if [ ! -z ${JAVA_HOME+x} ]; then
84+
echo "JAVA_HOME:$JAVA_HOME"
85+
PATH="${JAVA_HOME}/bin:$PATH"
86+
fi
87+
88+
if [ ! -z ${MAVEN_HOME+x} ]; then
89+
echo "MAVEN_HOME:$MAVEN_HOME"
90+
PATH="${MAVEN_HOME}/bin:$PATH"
91+
92+
if [ ! -d "${MAVEN_HOME}" ]; then
93+
echo "Maven home directory not found at ${MAVEN_HOME}" >&2
94+
exit 1
95+
fi
96+
fi
97+
98+
if [ ! -z ${GRADLE_HOME+x} ]; then
99+
echo "GRADLE_HOME:$GRADLE_HOME"
100+
PATH="${GRADLE_HOME}/bin:$PATH"
101+
102+
if [ ! -d "${GRADLE_HOME}" ]; then
103+
echo "Gradle home directory not found at ${GRADLE_HOME}" >&2
104+
exit 1
105+
fi
106+
fi
107+
108+
if [ ! -z ${ANT_HOME+x} ]; then
109+
echo "ANT_HOME:$ANT_HOME"
110+
PATH="${ANT_HOME}/bin:$PATH"
111+
112+
if [ ! -d "${ANT_HOME}" ]; then
113+
echo "Ant home directory not found at ${ANT_HOME}" >&2
114+
exit 1
115+
fi
116+
fi
117+
118+
if [ ! -z ${SBT_DIST+x} ]; then
119+
echo "SBT_DIST:$SBT_DIST"
120+
PATH="${SBT_DIST}/bin:$PATH"
121+
122+
if [ ! -d "${SBT_DIST}" ]; then
123+
echo "SBT home directory not found at ${SBT_DIST}" >&2
124+
exit 1
125+
fi
126+
fi
127+
echo "PATH:$PATH"
128+
129+
#fix this when we no longer need to run as root
130+
export HOME=/root
131+
132+
133+
""".formatted(javaHome, type.name(), type, buildToolVersion, buildRoot);
134+
135+
Log.warnf("### runBuild is %s", runBuild);
65136

66137
String containerFile = """
67138
FROM %s
@@ -71,8 +142,8 @@ public void run() {
71142

72143
// This block is only needed for running inside JBS
73144
if (isNotEmpty(System.getenv("jvm-build-service"))) {
145+
//RUN mkdir -p /var/workdir/software/settings /original-content/marker
74146
containerFile += """
75-
RUN mkdir -p /var/workdir/software/settings /original-content/marker
76147
77148
ARG CACHE_URL=""
78149
ENV CACHE_URL=$CACHE_URL

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env bash
22

3-
if [ ! -d "${ANT_HOME}" ]; then
4-
echo "Ant home directory not found at ${ANT_HOME}" >&2
5-
exit 1
6-
fi
3+
#if [ ! -d "${ANT_HOME}" ]; then
4+
# echo "Ant home directory not found at ${ANT_HOME}" >&2
5+
# exit 1
6+
#fi
77

88
if [ -z ${JBS_DISABLE_CACHE+x} ]; then
99
# XXX: It's possible that build.xml is not in the root directory

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ if [ ! -z ${ENFORCE_VERSION+x} ]; then
4646
git tag -m ${PROJECT_VERSION} -a ${PROJECT_VERSION} || true
4747
fi
4848

49-
if [ ! -d "${GRADLE_HOME}" ]; then
50-
echo "Gradle home directory not found at ${GRADLE_HOME}" >&2
51-
exit 1
52-
fi
49+
#if [ ! -d "${GRADLE_HOME}" ]; then
50+
# echo "Gradle home directory not found at ${GRADLE_HOME}" >&2
51+
# exit 1
52+
#fi
5353

5454
export LANG="en_US.UTF-8"
5555
export LC_ALL="en_US.UTF-8"

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
mkdir -p "${HOME}/.m2/repository"
44

5-
echo "MAVEN_HOME=${MAVEN_HOME}"
6-
7-
if [ ! -d "${MAVEN_HOME}" ]; then
8-
echo "Maven home directory not found at ${MAVEN_HOME}" >&2
9-
exit 1
10-
fi
5+
#echo "MAVEN_HOME=${MAVEN_HOME}"
6+
#if [ ! -d "${MAVEN_HOME}" ]; then
7+
# echo "Maven home directory not found at ${MAVEN_HOME}" >&2
8+
# exit 1
9+
#fi
1110

1211
TOOLCHAINS_XML="$(workspaces.build-settings.path)"/toolchains.xml
1312

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
mkdir -p "${HOME}/.sbt/1.0"
44
cp -r /maven-artifacts/* "$HOME/.sbt/*" || true
55

6-
if [ ! -d "${SBT_DIST}" ]; then
7-
echo "SBT home directory not found at ${SBT_DIST}" >&2
8-
exit 1
9-
fi
6+
#if [ ! -d "${SBT_DIST}" ]; then
7+
# echo "SBT home directory not found at ${SBT_DIST}" >&2
8+
# exit 1
9+
#fi
1010

1111
if [ -z ${JBS_DISABLE_CACHE+x} ]; then
1212
cat > "$HOME/.sbt/repositories" <<EOF

0 commit comments

Comments
 (0)