Skip to content

Commit

Permalink
Refactor scripts. Add proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Oct 14, 2024
1 parent 9b28685 commit 53e4626
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,34 @@ public void run() {
set -eu
set -o pipefail
echo "Using PROXY_URL : $PROXY_URL"
#fix this when we no longer need to run as root
export HOME=${HOME:=/root}
# Custom base working directory.
export JBS_WORKDIR=${JBS_WORKDIR:=/var/workdir/workspace}
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export JAVA_HOME=%s
export GRADLE_USER_HOME="/var/workdir/software/settings/.gradle"
export JAVA_HOME=${JAVA_HOME:=%s}
# This might get overridden by the tool home configuration below. This is
# useful if Gradle/Ant also requires Maven configured.
export MAVEN_HOME=/opt/maven/3.8.8
export MAVEN_HOME=${MAVEN_HOME:=/opt/maven/3.8.8}
# If we run out of memory we want the JVM to die with error code 134
export MAVEN_OPTS="-XX:+CrashOnOutOfMemoryError"
# If we run out of memory we want the JVM to die with error code 134
export JAVA_OPTS="-XX:+CrashOnOutOfMemoryError"
export %s_HOME=/opt/%s/%s
export %s_HOME=${%s_HOME:=/opt/%s/%s}
export GRADLE_USER_HOME="${JBS_WORKDIR}/software/settings/.gradle"
mkdir -p /var/workdir/workspace/logs /var/workdir/workspace/packages ${HOME}/.sbt/1.0 ${GRADLE_USER_HOME} ${HOME}/.m2
cd /var/workdir/workspace/source
mkdir -p ${JBS_WORKDIR}/logs ${JBS_WORKDIR}/packages ${HOME}/.sbt/1.0 ${GRADLE_USER_HOME} ${HOME}/.m2
cd ${JBS_WORKDIR}/source
if [ ! -z ${JAVA_HOME+x} ]; then
echo "JAVA_HOME:$JAVA_HOME"
PATH="${JAVA_HOME}/bin:$PATH"
fi
if [ ! -z ${MAVEN_HOME+x} ]; then
""".formatted(javaHome, type.name(), type, buildToolVersion);
""".formatted(javaHome, type.name(), type.name(), type, buildToolVersion);

runBuild += getMavenSetup();

Expand Down Expand Up @@ -178,7 +178,7 @@ private String getContainerFile() {
COPY .jbs/run-build.sh /var/workdir
COPY . /var/workdir/workspace/source/
RUN /var/workdir/run-build.sh
""".formatted(recipeImage);;
""".formatted(recipeImage);

if (type == ToolType.ANT) {
// Don't think we need to mess with keystore as copy-artifacts is simply calling copy commands.
Expand Down Expand Up @@ -208,7 +208,7 @@ private String getContainerFile() {
* altDeploymentDirectory to be used by default.
*/
private String getMavenSetup() {
return """
String result = """
echo "MAVEN_HOME:$MAVEN_HOME"
PATH="${MAVEN_HOME}/bin:$PATH"
Expand Down Expand Up @@ -244,7 +244,7 @@ private String getMavenSetup() {
<repositories>
<repository>
<id>artifacts</id>
<url>file:///var/workdir/workspace/artifacts</url>
<url>file://${JBS_WORKDIR}/artifacts</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
Expand All @@ -254,7 +254,7 @@ private String getMavenSetup() {
<pluginRepositories>
<pluginRepository>
<id>artifacts</id>
<url>file:///var/workdir/workspace/artifacts</url>
<url>file://${JBS_WORKDIR}/artifacts</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
Expand All @@ -269,13 +269,45 @@ private String getMavenSetup() {
</activation>
<properties>
<altDeploymentRepository>
local::file:///var/workdir/workspace/artifacts
local::file://${JBS_WORKDIR}/artifacts
</altDeploymentRepository>
</properties>
</profile>
</profiles>
<interactiveMode>false</interactiveMode>
""";

// This block is only needed when running outside of JBS
if (isEmpty(System.getenv("jvm-build-service"))) {
result += """
<proxies>
<proxy>
<id>indy-http</id>
<active>true</active>
<protocol>http</protocol>
<host>indy-generic-proxy</host>
<port>80</port>
<!-- <username>build-ADDTW3JAGHYAA+tracking</username> -->
<username>${BUILD_ID}+tracking</username>
<password>${MVN_TOKEN}</password>
<nonProxyHosts>indy|localhost</nonProxyHosts>
</proxy>
<proxy>
<id>indy-https</id>
<active>true</active>
<protocol>https</protocol>
<host>indy-generic-proxy</host>
<port>80</port>
<username>${BUILD_ID}+tracking</username>
<password>${MVN_TOKEN}</password>
<nonProxyHosts>indy|localhost</nonProxyHosts>
</proxy>
</proxies>
""";
}

result += """
</settings>
EOF
Expand Down Expand Up @@ -312,6 +344,8 @@ private String getMavenSetup() {
</toolchains>
EOF
""".formatted(javaVersion);

return result;
}


Expand All @@ -335,7 +369,7 @@ private String getGradleSetup() {
systemProp.http.connectionTimeout=600000
# Settings for <https://github.com/vanniktech/gradle-maven-publish-plugin>
RELEASE_REPOSITORY_URL=file:///var/workdir/workspace/artifacts
RELEASE_REPOSITORY_URL=file://${JBS_WORKDIR}/artifacts
RELEASE_SIGNING_ENABLED=false
mavenCentralUsername=
mavenCentralPassword=
Expand All @@ -346,7 +380,7 @@ private String getGradleSetup() {
# Default deployment target
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_system_properties
systemProp.maven.repo.local=/var/workdir/workspace/artifacts
systemProp.maven.repo.local=${JBS_WORKDIR}/artifacts
EOF
""";
}
Expand Down Expand Up @@ -405,7 +439,7 @@ private String getSbtSetup() {
fi
# TODO: we may need .allowInsecureProtocols here for minikube based tests that don't have access to SSL
cat >"$HOME/.sbt/1.0/global.sbt" <<EOF
publishTo := Some(("MavenRepo" at s"file:/var/workdir/workspace/artifacts")),
publishTo := Some(("MavenRepo" at s"file:${JBS_WORKDIR}/artifacts")),
EOF
""";
}
Expand Down
1 change: 0 additions & 1 deletion pkg/reconciler/dependencybuild/buildrecipeyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,6 @@ func doSubstitution(script string, paramValues []tektonpipeline.Param, commitTim
}
}
script = strings.ReplaceAll(script, "$(params."+PipelineParamProxyUrl+")", "http://localhost:8080/v2/cache/rebuild"+buildRepos+"/"+strconv.FormatInt(commitTime, 10)+"/")
// script = strings.ReplaceAll(script, "$(workspaces.build-settings.path)", "/var/workdir/software/settings")
script = strings.ReplaceAll(script, "$(workspaces.source.path)", "/var/workdir/workspace")
script = strings.ReplaceAll(script, "$(workspaces.tls.path)", "/var/workdir/software/tls/service-ca.crt")
return script
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/dependencybuild/scripts/ant-build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
echo "Running $(which ant) with arguments: $@"
eval "ant $@" | tee $(workspaces.source.path)/logs/ant.log
eval "ant $@" | tee ${JBS_WORKDIR}/logs/ant.log
2 changes: 0 additions & 2 deletions pkg/reconciler/dependencybuild/scripts/build-entry.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash

cd $(workspaces.source.path)/source

if [ -n "$(params.CONTEXT_DIR)" ]
then
cd $(params.CONTEXT_DIR)
Expand Down
3 changes: 1 addition & 2 deletions pkg/reconciler/dependencybuild/scripts/gradle-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ rm -f gradle/verification-metadata.xml

echo "Running Gradle command with arguments: $@"

gradle --info --stacktrace "$@" | tee $(workspaces.source.path)/logs/gradle.log
#gradle -Dmaven.repo.local=$(workspaces.source.path)/artifacts --info --stacktrace "$@" | tee $(workspaces.source.path)/logs/gradle.log
gradle --info --stacktrace "$@" | tee ${JBS_WORKDIR}/logs/gradle.log
4 changes: 2 additions & 2 deletions pkg/reconciler/dependencybuild/scripts/maven-build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
if [ ! -z ${ENFORCE_VERSION+x} ]; then
echo "Setting version to ${PROJECT_VERSION} to match enforced version"
mvn -B -e org.codehaus.mojo:versions-maven-plugin:2.8.1:set -DnewVersion="${PROJECT_VERSION}" | tee $(workspaces.source.path)/logs/enforce-version.log
mvn -B -e org.codehaus.mojo:versions-maven-plugin:2.8.1:set -DnewVersion="${PROJECT_VERSION}" | tee ${JBS_WORKDIR}/logs/enforce-version.log
fi

echo "Running Maven command with arguments: $@"

mvn -V -B -e "$@" | tee $(workspaces.source.path)/logs/maven.log
mvn -V -B -e "$@" | tee ${JBS_WORKDIR}/logs/maven.log
2 changes: 1 addition & 1 deletion pkg/reconciler/dependencybuild/scripts/sbt-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fi

echo "Running SBT command with arguments: $@"

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

0 comments on commit 53e4626

Please sign in to comment.