Skip to content

Commit

Permalink
Update JDK Quickstarters (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisVQ committed Feb 19, 2024
1 parent d8e5d14 commit 11dee81
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Update gateway-Nginx quickstarter ([#983](https://github.com/opendevstack/ods-quickstarters/pull/983))
- Added secret scanning in docker plain ([#963](https://github.com/opendevstack/ods-quickstarters/pull/963))
- Added Nodejs20 agent ([#962](https://github.com/opendevstack/ods-quickstarters/issues/962))
- Added java 21 to jdk agent, updated Springboot and Spock quickstarters ([#962](https://github.com/opendevstack/ods-quickstarters/issues/962))
- Update release manager readme ([#969](https://github.com/opendevstack/ods-quickstarters/issues/969))
- Update Streamlit and Python quickstarters and agent ([#968](https://github.com/opendevstack/ods-quickstarters/issues/968))

Expand Down
4 changes: 2 additions & 2 deletions be-java-springboot/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ odsQuickstarterPipeline(

stage('Build spring project') {
dir(context.targetDir) {
def springBootVersion = '3.0.5'
def springBootVersion = '3.2.0'
echo "--- create spring boot (v${springBootVersion}) project via spring initializr ---"

sh "curl https://start.spring.io/starter.tgz \
Expand All @@ -29,7 +29,7 @@ odsQuickstarterPipeline(
-d dependencies='web,data-rest,data-jpa,h2,security,devtools' \
-d platformVersion=${springBootVersion} \
-d packaging=jar \
-d jvmVersion=17 \
-d jvmVersion=21 \
-d groupId=${context.projectId} \
-d artifactId=${context.componentId} \
-d name=${context.componentId} \
Expand Down
2 changes: 1 addition & 1 deletion be-java-springboot/Jenkinsfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def stageBuild(def context) {
}
stage('Build and Unit Test') {
withEnv(["TAGVERSION=${context.tagversion}", "NEXUS_HOST=${context.nexusHost}", "NEXUS_USERNAME=${context.nexusUsername}", "NEXUS_PASSWORD=${context.nexusPassword}", "JAVA_OPTS=${javaOpts}","GRADLE_TEST_OPTS=${gradleTestOpts}","ENVIRONMENT=${springBootEnv}"]) {
def status = sh(script: "source use-j17.sh && ./gradlew clean build --stacktrace --no-daemon && source use-j11.sh", returnStatus: true)
def status = sh(script: "source use-j21.sh && ./gradlew clean build --stacktrace --no-daemon && source use-j11.sh", returnStatus: true)
if (status != 0) {
error "Build failed!"
}
Expand Down
2 changes: 1 addition & 1 deletion be-java-springboot/files/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.access.redhat.com/ubi9/openjdk-17
FROM registry.access.redhat.com/ubi9/openjdk-21

# Enforce runtime protection for log4j2 CVE-2021-44228 (affected version from 2.0 to 2.14.1) in the affected vesion is used.
# This applies for version from 2.10 and not below.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion be-java-springboot/files/metadata.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: OpenJDK
description: "OpenJDK is a free and open-source implementation of the Java Platform, Standard Edition. Technologies: Spring Boot 2.1, OpenJDK 17"
description: "OpenJDK is a free and open-source implementation of the Java Platform, Standard Edition. Technologies: Spring Boot 3.2.0, OpenJDK 21"
supplier: https://openjdk.java.net/
version: 4.x
type: ods
14 changes: 8 additions & 6 deletions common/jenkins-agents/jdk/docker/Dockerfile.ubi8
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LABEL com.redhat.component="jenkins-agent-jdk-35-rhel7-container" \
name="openshift4/jenkins-agent-jdk-35-rhel7" \
architecture="x86_64" \
io.k8s.display-name="Jenkins Agent JDK" \
io.k8s.description="The jenkins agent jdk image has java 11 and 17 installed on top of the jenkins agent base image." \
io.k8s.description="The jenkins agent jdk image has java 11, 17 and 21 installed on top of the jenkins agent base image." \
io.openshift.tags="openshift,jenkins,agent,jdk" \
maintainer="[email protected]"

Expand All @@ -31,11 +31,12 @@ RUN sh -c "echo 'rhel' > /etc/yum/vars/osname" && \
sed -i 's@^\s*enabled\s*=.*$@enabled = 0@g' /etc/yum.repos.d/adoptium-temurin.repo && \
grep -ri '^\s*\(name\|enabled\)\s*=' /etc/yum.repos.d/*

# Install Java 11, 17 and binutils
# Note: use java scripts are executed to test the scripts but also use-j11.sh in called 2nd place to set is as default version
# Install Java 11, 17, 21 and binutils
# Note: use java scripts are executed to test the scripts but also use-j11.sh in called 3nd place to set is as default version
RUN yum -y --nobest --skip-broken update && \
yum install -y java-11-openjdk-devel && \
yum install -y --enablerepo Adoptium temurin-17-jdk && \
yum install -y --enablerepo Adoptium temurin-21-jdk && \
yum install -y binutils && \
yum updateinfo -y && \
yum repolist -y && \
Expand All @@ -48,10 +49,11 @@ RUN chmod +x /usr/local/bin/use-j*.sh && \
chmod ugo+s /usr/local/bin/use-j*.sh && \
sh -c 'chmod ugo+s $(which alternatives)' && \
ls -la /usr/local/bin/use-j*.sh && \
echo "--- STARTS JDK 11/17 TESTS ---" && \
echo "--- STARTS JDK 11/17/21 TESTS ---" && \
use-j21.sh && \
use-j17.sh && \
use-j11.sh && \
echo "--- ENDS JDK 11/17 TESTS ---" && \
echo "--- ENDS JDK 11/17/21 TESTS ---" && \
## Needed in case base and jdk agents has a mismatch in java versions
rm -fv /etc/profile.d/set-default-java.sh && \
echo "export JAVA_HOME=/usr/lib/jvm/$(ls -lah /usr/lib/jvm | grep "java-11-openjdk-11.*\.x86_64" | awk '{print $NF}' | head -1)" >> /etc/profile.d/set-default-java.sh && \
Expand Down Expand Up @@ -89,7 +91,7 @@ RUN chown -R 1001:0 $HOME && \
chmod -c 666 /etc/pki/ca-trust/extracted/java/cacerts && \
ls -la /etc/pki/ca-trust/extracted/java/cacerts

# temporary java17 switch bugfix
# temporary java version switch bugfix
USER root
RUN chgrp -R 0 /var/lib/alternatives && \
chmod -R g=u /var/lib/alternatives && \
Expand Down
38 changes: 38 additions & 0 deletions common/jenkins-agents/jdk/docker/use-j21.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

JAVA_HOME_FOLDER=$(ls -lah /usr/lib/jvm | grep "temurin-21" | awk '{print $NF}' | head -1)
JAVA_VERSION="21"

function msg_and_exit() {
echo "ERROR: ${1}"
exit 1
}

echo "Switching to java ${JAVA_VERSION}:"
JAVA_HOME="/usr/lib/jvm/${JAVA_HOME_FOLDER}"

alternatives --set java ${JAVA_HOME}/bin/java || \
msg_and_exit "Cannot configure java ${JAVA_VERSION} as the alternative to use for java."
java -version 2>&1 | grep -q "\s\+${JAVA_VERSION}" || msg_and_exit "Java version is not ${JAVA_VERSION}."

if [ -x ${JAVA_HOME}/bin/javac ]; then
alternatives --set javac ${JAVA_HOME}/bin/javac || \
msg_and_exit "Cannot configure javac ${JAVA_VERSION} as the alternative to use for javac."
javac -version 2>&1 | grep -q "\s\+${JAVA_VERSION}" || msg_and_exit "Javac version is not ${JAVA_VERSION}."
else
echo "WARNING: Not found binary for javac in path ${JAVA_HOME}/bin/javac "
fi

java -version 2>&1
if which 'javac'; then
javac -version 2>&1
else
echo "WARNING: Binary javac is not available."
fi

if [ -d ${JAVA_HOME}/bin/ ]; then
export JAVA_HOME
else
msg_and_exit "Cannot configure JAVA_HOME environment variable to ${JAVA_HOME}"
fi
echo "JAVA_HOME: $JAVA_HOME"
8 changes: 5 additions & 3 deletions docs/modules/jenkins-agents/pages/jdk.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ It can be referenced in a `Jenkinsfile` with `ods/jenkins-agent-jdk`.
. Nexus and HTTP proxy configuration for Maven & Gradle

== Supported Java Versions
This agent provides 2 JDKs: `java 11` and `java 17`.
This agent provides 3 JDKs: `java 11`, `java 17` and `java 21`.

For backwards compatibility `java 11` is the default version. Java projects migrating from previous ODS version will not require any change. A migration to `java 17` can be done afterwards.
For backwards compatibility `java 11` is the default version. Java projects migrating from previous ODS version will not require any change. A migration to `java 17` and `java 21` can be done afterwards.

To switch the environment to `java 17` the script `use-j17.sh` is provided at the jenkins home folder.
To switch the environment to `java 21` the script `use-j21.sh` is provided at the jenkins home folder.
Following command shows how the jenkins build script from the springboot quickstarter switches the java version before calling the gradle wrapper:
```
def status = sh(script: "$HOME/use-j17.sh && ./gradlew clean build --stacktrace --no-daemon && $HOME/use-j11.sh", returnStatus: true)
def status = sh(script: "$HOME/use-j21.sh && ./gradlew clean build --stacktrace --no-daemon && $HOME/use-j11.sh", returnStatus: true)
```
NOTE: like this example, you will need to switch back to `java 11` after running the gradlew build. This is required because the jdk agent environment still does not support the latest java version. E.g. the `sonar scanner` is not compatible with the latest java version.

== Installed packages

Dockerfile.ubi8 installs:
- java-21-openjdk-devel & java-21-openjdk-jmods
- java-17-openjdk-devel & java-17-openjdk-jmods
- java-11-openjdk-devel & java-11-openjdk-jmods

Expand Down
28 changes: 14 additions & 14 deletions docs/modules/quickstarters/pages/be-java-springboot.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

Use this quickstarter to generate a https://www.tutorialspoint.com/spring_boot/index.htm[spring boot] based project.

It will provide a java 17 project with preconfigured gradle build and CI/CD integration (Jenkinsfile).
It will provide a java 21 project with preconfigured gradle build and CI/CD integration (Jenkinsfile).

== What files / architecture is generated?

The quickstarter uses the spring boot project generator service hosted by Spring (https://start.spring.io) to generate the spring boot project.

This is implemented in the quickstarter jenkins build script called `Jenkinsfile` (open it to understand the internal of the code generation of this quickstarter).

When provisioning this quickstarter in the provisioning app a spring boot project based on version `3.0.5` will be generated and pushed to your git repository.
When provisioning this quickstarter in the provisioning app a spring boot project based on version `3.2.0` will be generated and pushed to your git repository.

The generated project requires `java 17` and includes the required gradle build and wrapper artifact based on gradle version `8.0.2`.
The generated project requires `java 21` and includes the required gradle build and wrapper artifact based on gradle version `8.5`.

== Project Structure

Expand Down Expand Up @@ -96,7 +96,7 @@ This git repository contains the generated project artifacts as describe above i
To start working with it you´ll need to clone the git repository in your local development environment.
After cloning it use `./gradlew build` to verify that the project compiles and test runs.

NOTE: java 17 or later version is required to run gradlew and compile java classes.
NOTE: java 21 or later version is required to run gradlew and compile java classes.

=== Metadata

Expand All @@ -111,7 +111,7 @@ version: 1.0.1
type: ods
role: backend
runtime: spring-boot
runtimeVersion: 3.0.5
runtimeVersion: 3.2.0
```

== How this quickstarter is built thru jenkins
Expand Down Expand Up @@ -139,17 +139,17 @@ This file is copied to the `docker` folder to be included in the docker image wh
This quickstarter uses the
https://github.com/opendevstack/ods-quickstarters/tree/master/common/jenkins-agents/jdk[jdk] Jenkins builder agent.

== Migration to Java 17
== Migration to Java 21

The https://github.com/opendevstack/ods-quickstarters/tree/master/common/jenkins-agents/jdk[jdk builder agent] Jenkins builder agent has installed 2 JDK: `java 11` and `java 17`.
The https://github.com/opendevstack/ods-quickstarters/tree/master/common/jenkins-agents/jdk[jdk builder agent] Jenkins builder agent has installed 3 JDK: `java 11`, `java 17` and `java 21`.
The default version is `java 11`. This makes the agent backwards compatible.

If you are migrating an ODS-based spring boot project to `java 17` following instructions provide a some guidance about the typical steps to achieve this:
If you are migrating an ODS-based spring boot project to `java 21` following instructions provide a some guidance about the typical steps to achieve this:

- change the agent version as indicated in https://github.com/opendevstack/ods-quickstarters/tree/master/common/jenkins-agents/jdk[jdk builder agent]
- upgrade the gradle wrapper to version `8.0.2` running this gradle command at the root folder of your spring project:
- upgrade the gradle wrapper to version `8.5` running this gradle command at the root folder of your spring project:
```
gradle wrapper --gradle-version 8.0.2 --distribution-type bin
gradle wrapper --gradle-version 8.5 --distribution-type bin
```
NOTE: this command use just `gradle` instead of the wrapper.

Expand All @@ -162,11 +162,11 @@ Following files are expected to be included in the change:

```
- verify that the jenkins build pipeline run successful. Fix any error if is not the case.
- change your local runtime to `java 17` and compile your project with the gradle wrapper.
- update in your `build.gradle` file the source compatibility to `sourceCompatibility = JavaVersion.VERSION_17` and compile again.
- update the project `Jenkinfile` by adding in the stage `Build and Unit Test` a call to the `use-j17.sh` before the gradle wrapper. This will set the runtime to `java 17. It would look like this:
- change your local runtime to `java 21` and compile your project with the gradle wrapper.
- update in your `build.gradle` file the source compatibility to `sourceCompatibility = JavaVersion.VERSION_21` and compile again.
- update the project `Jenkinfile` by adding in the stage `Build and Unit Test` a call to the `use-j21.sh` before the gradle wrapper. This will set the runtime to `java 21. It would look like this:
```
def status = sh(script: "use-j17.sh && ./gradlew clean build --stacktrace --no-daemon", returnStatus: true)
def status = sh(script: "use-j21.sh && ./gradlew clean build --stacktrace --no-daemon", returnStatus: true)
```
- commit and push the changes to the remote git project repository.
- verify that the jenkins build pipeline run successful. Fix any error if is not the case.
Expand Down
2 changes: 1 addition & 1 deletion e2e-spock-geb/Jenkinsfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def stageTest(def context) {
stage('Integration Test') {
sh (script: "chmod a+x gradle*", label : "allow gradle to execute")
withEnv(["TAGVERSION=${context.tagversion}", "NEXUS_HOST=${context.nexusHost}", "NEXUS_USERNAME=${context.nexusUsername}", "NEXUS_PASSWORD=${context.nexusPassword}", "JAVA_OPTS=${javaOpts}","GRADLE_TEST_OPTS=${gradleTestOpts}","ENVIRONMENT=${springBootEnv}","OPENSHIFT_PROJECT=${context.targetProject}","OPENSHIFT_APP_DOMAIN=${context.getOpenshiftApplicationDomain()}"]) {
def status = sh(script: "./gradlew clean test --stacktrace --no-daemon", returnStatus: true)
def status = sh(script: "source use-j17.sh && ./gradlew clean test --stacktrace --no-daemon && source use-j11.sh", returnStatus: true)
junit(testResults:"build/test-results/installation*/*.xml, build/test-results/integration*/*.xml, build/test-results/acceptance*/*.xml", allowEmptyResults:true)
stash(name: "installation-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/installation*/*.xml', allowEmpty: true)
stash(name: "integration-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/integration*/*.xml', allowEmpty: true)
Expand Down
8 changes: 4 additions & 4 deletions e2e-spock-geb/files/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ repositories {
}

ext {
junitVersion = "5.9.2"
junitVersion = "5.10.1"
spockVersion = "2.3-groovy-4.0"
gebVersion = "7.0"
seleniumVersion = "4.8.3"
htmlunitVersion = "4.8.1.1"
unirestVersion = "3.14.2"
seleniumVersion = "4.15.0"
htmlunitVersion = "4.13.0"
unirestVersion = "3.14.5"
// When a test fail we can continue or fail the stage
CONTINUE_WHEN_TEST_FAIL = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion e2e-spock-geb/files/metadata.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: e2e-spock-geb
description: "Spock is a highly expressive testing and specification framework for Java and Groovy. Geb is a browser automation solution for functional/web/acceptance testing. Technologies: Spock 1.3, Geb 3.2, Selenium 3.141"
description: "Spock is a highly expressive testing and specification framework for Java and Groovy. Geb is a browser automation solution for functional/web/acceptance testing. Technologies: Spock 2.3-groovy-4.0, Geb 7.0, Selenium 4.15.0"
supplier: http://spockframework.org
version: 4.x
type: ods-test

0 comments on commit 11dee81

Please sign in to comment.