Skip to content

Commit 53e4626

Browse files
committed
Refactor scripts. Add proxies
1 parent 9b28685 commit 53e4626

File tree

7 files changed

+56
-26
lines changed

7 files changed

+56
-26
lines changed

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

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,34 +87,34 @@ public void run() {
8787
set -eu
8888
set -o pipefail
8989
90-
echo "Using PROXY_URL : $PROXY_URL"
91-
9290
#fix this when we no longer need to run as root
9391
export HOME=${HOME:=/root}
92+
# Custom base working directory.
93+
export JBS_WORKDIR=${JBS_WORKDIR:=/var/workdir/workspace}
9494
9595
export LANG="en_US.UTF-8"
9696
export LC_ALL="en_US.UTF-8"
97-
export JAVA_HOME=%s
98-
export GRADLE_USER_HOME="/var/workdir/software/settings/.gradle"
97+
export JAVA_HOME=${JAVA_HOME:=%s}
9998
# This might get overridden by the tool home configuration below. This is
10099
# useful if Gradle/Ant also requires Maven configured.
101-
export MAVEN_HOME=/opt/maven/3.8.8
100+
export MAVEN_HOME=${MAVEN_HOME:=/opt/maven/3.8.8}
102101
# If we run out of memory we want the JVM to die with error code 134
103102
export MAVEN_OPTS="-XX:+CrashOnOutOfMemoryError"
104103
# If we run out of memory we want the JVM to die with error code 134
105104
export JAVA_OPTS="-XX:+CrashOnOutOfMemoryError"
106-
export %s_HOME=/opt/%s/%s
105+
export %s_HOME=${%s_HOME:=/opt/%s/%s}
106+
export GRADLE_USER_HOME="${JBS_WORKDIR}/software/settings/.gradle"
107107
108-
mkdir -p /var/workdir/workspace/logs /var/workdir/workspace/packages ${HOME}/.sbt/1.0 ${GRADLE_USER_HOME} ${HOME}/.m2
109-
cd /var/workdir/workspace/source
108+
mkdir -p ${JBS_WORKDIR}/logs ${JBS_WORKDIR}/packages ${HOME}/.sbt/1.0 ${GRADLE_USER_HOME} ${HOME}/.m2
109+
cd ${JBS_WORKDIR}/source
110110
111111
if [ ! -z ${JAVA_HOME+x} ]; then
112112
echo "JAVA_HOME:$JAVA_HOME"
113113
PATH="${JAVA_HOME}/bin:$PATH"
114114
fi
115115
116116
if [ ! -z ${MAVEN_HOME+x} ]; then
117-
""".formatted(javaHome, type.name(), type, buildToolVersion);
117+
""".formatted(javaHome, type.name(), type.name(), type, buildToolVersion);
118118

119119
runBuild += getMavenSetup();
120120

@@ -178,7 +178,7 @@ private String getContainerFile() {
178178
COPY .jbs/run-build.sh /var/workdir
179179
COPY . /var/workdir/workspace/source/
180180
RUN /var/workdir/run-build.sh
181-
""".formatted(recipeImage);;
181+
""".formatted(recipeImage);
182182

183183
if (type == ToolType.ANT) {
184184
// Don't think we need to mess with keystore as copy-artifacts is simply calling copy commands.
@@ -208,7 +208,7 @@ private String getContainerFile() {
208208
* altDeploymentDirectory to be used by default.
209209
*/
210210
private String getMavenSetup() {
211-
return """
211+
String result = """
212212
echo "MAVEN_HOME:$MAVEN_HOME"
213213
PATH="${MAVEN_HOME}/bin:$PATH"
214214
@@ -244,7 +244,7 @@ private String getMavenSetup() {
244244
<repositories>
245245
<repository>
246246
<id>artifacts</id>
247-
<url>file:///var/workdir/workspace/artifacts</url>
247+
<url>file://${JBS_WORKDIR}/artifacts</url>
248248
<releases>
249249
<enabled>true</enabled>
250250
<checksumPolicy>ignore</checksumPolicy>
@@ -254,7 +254,7 @@ private String getMavenSetup() {
254254
<pluginRepositories>
255255
<pluginRepository>
256256
<id>artifacts</id>
257-
<url>file:///var/workdir/workspace/artifacts</url>
257+
<url>file://${JBS_WORKDIR}/artifacts</url>
258258
<releases>
259259
<enabled>true</enabled>
260260
<checksumPolicy>ignore</checksumPolicy>
@@ -269,13 +269,45 @@ private String getMavenSetup() {
269269
</activation>
270270
<properties>
271271
<altDeploymentRepository>
272-
local::file:///var/workdir/workspace/artifacts
272+
local::file://${JBS_WORKDIR}/artifacts
273273
</altDeploymentRepository>
274274
</properties>
275275
</profile>
276276
</profiles>
277277
278278
<interactiveMode>false</interactiveMode>
279+
""";
280+
281+
// This block is only needed when running outside of JBS
282+
if (isEmpty(System.getenv("jvm-build-service"))) {
283+
result += """
284+
<proxies>
285+
<proxy>
286+
<id>indy-http</id>
287+
<active>true</active>
288+
<protocol>http</protocol>
289+
<host>indy-generic-proxy</host>
290+
<port>80</port>
291+
<!-- <username>build-ADDTW3JAGHYAA+tracking</username> -->
292+
<username>${BUILD_ID}+tracking</username>
293+
<password>${MVN_TOKEN}</password>
294+
<nonProxyHosts>indy|localhost</nonProxyHosts>
295+
</proxy>
296+
<proxy>
297+
<id>indy-https</id>
298+
<active>true</active>
299+
<protocol>https</protocol>
300+
<host>indy-generic-proxy</host>
301+
<port>80</port>
302+
<username>${BUILD_ID}+tracking</username>
303+
<password>${MVN_TOKEN}</password>
304+
<nonProxyHosts>indy|localhost</nonProxyHosts>
305+
</proxy>
306+
</proxies>
307+
""";
308+
}
309+
310+
result += """
279311
</settings>
280312
EOF
281313
@@ -312,6 +344,8 @@ private String getMavenSetup() {
312344
</toolchains>
313345
EOF
314346
""".formatted(javaVersion);
347+
348+
return result;
315349
}
316350

317351

@@ -335,7 +369,7 @@ private String getGradleSetup() {
335369
systemProp.http.connectionTimeout=600000
336370
337371
# Settings for <https://github.com/vanniktech/gradle-maven-publish-plugin>
338-
RELEASE_REPOSITORY_URL=file:///var/workdir/workspace/artifacts
372+
RELEASE_REPOSITORY_URL=file://${JBS_WORKDIR}/artifacts
339373
RELEASE_SIGNING_ENABLED=false
340374
mavenCentralUsername=
341375
mavenCentralPassword=
@@ -346,7 +380,7 @@ private String getGradleSetup() {
346380
347381
# Default deployment target
348382
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_system_properties
349-
systemProp.maven.repo.local=/var/workdir/workspace/artifacts
383+
systemProp.maven.repo.local=${JBS_WORKDIR}/artifacts
350384
EOF
351385
""";
352386
}
@@ -405,7 +439,7 @@ private String getSbtSetup() {
405439
fi
406440
# TODO: we may need .allowInsecureProtocols here for minikube based tests that don't have access to SSL
407441
cat >"$HOME/.sbt/1.0/global.sbt" <<EOF
408-
publishTo := Some(("MavenRepo" at s"file:/var/workdir/workspace/artifacts")),
442+
publishTo := Some(("MavenRepo" at s"file:${JBS_WORKDIR}/artifacts")),
409443
EOF
410444
""";
411445
}

pkg/reconciler/dependencybuild/buildrecipeyaml.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,6 @@ func doSubstitution(script string, paramValues []tektonpipeline.Param, commitTim
901901
}
902902
}
903903
script = strings.ReplaceAll(script, "$(params."+PipelineParamProxyUrl+")", "http://localhost:8080/v2/cache/rebuild"+buildRepos+"/"+strconv.FormatInt(commitTime, 10)+"/")
904-
// script = strings.ReplaceAll(script, "$(workspaces.build-settings.path)", "/var/workdir/software/settings")
905904
script = strings.ReplaceAll(script, "$(workspaces.source.path)", "/var/workdir/workspace")
906905
script = strings.ReplaceAll(script, "$(workspaces.tls.path)", "/var/workdir/software/tls/service-ca.crt")
907906
return script
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
echo "Running $(which ant) with arguments: $@"
2-
eval "ant $@" | tee $(workspaces.source.path)/logs/ant.log
2+
eval "ant $@" | tee ${JBS_WORKDIR}/logs/ant.log

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

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

3-
cd $(workspaces.source.path)/source
4-
53
if [ -n "$(params.CONTEXT_DIR)" ]
64
then
75
cd $(params.CONTEXT_DIR)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ rm -f gradle/verification-metadata.xml
2424

2525
echo "Running Gradle command with arguments: $@"
2626

27-
gradle --info --stacktrace "$@" | tee $(workspaces.source.path)/logs/gradle.log
28-
#gradle -Dmaven.repo.local=$(workspaces.source.path)/artifacts --info --stacktrace "$@" | tee $(workspaces.source.path)/logs/gradle.log
27+
gradle --info --stacktrace "$@" | tee ${JBS_WORKDIR}/logs/gradle.log
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
if [ ! -z ${ENFORCE_VERSION+x} ]; then
22
echo "Setting version to ${PROJECT_VERSION} to match enforced version"
3-
mvn -B -e org.codehaus.mojo:versions-maven-plugin:2.8.1:set -DnewVersion="${PROJECT_VERSION}" | tee $(workspaces.source.path)/logs/enforce-version.log
3+
mvn -B -e org.codehaus.mojo:versions-maven-plugin:2.8.1:set -DnewVersion="${PROJECT_VERSION}" | tee ${JBS_WORKDIR}/logs/enforce-version.log
44
fi
55

66
echo "Running Maven command with arguments: $@"
77

8-
mvn -V -B -e "$@" | tee $(workspaces.source.path)/logs/maven.log
8+
mvn -V -B -e "$@" | tee ${JBS_WORKDIR}/logs/maven.log

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ fi
1515

1616
echo "Running SBT command with arguments: $@"
1717

18-
eval "sbt $@" | tee $(workspaces.source.path)/logs/sbt.log
18+
eval "sbt $@" | tee ${JBS_WORKDIR}/logs/sbt.log

0 commit comments

Comments
 (0)