Skip to content

Commit 52f0951

Browse files
author
Jan Lieskovsky
committed
[CIAM-2881] Add a demo on how to rebuild the standard Red Hat Single Sign-On
7.5 container image to start using the latest version of IBM Semeru 11 Open Edition JDK (OpenJ9 JVM) instead of the default Red Hat OpenJDK 11 one. Also add a helper script to (re)generate the existing templates to start using the newly built image stream Signed-off-by: Jan Lieskovsky <[email protected]>
1 parent 1471cc8 commit 52f0951

File tree

4 files changed

+378
-0
lines changed

4 files changed

+378
-0
lines changed

jdk/README.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
## Using Red Hat Single Sign-On 7.5 container images with alternative JDK
2+
3+
The Red Hat Single Sign-On 7.5 for OpenJDK container images use the [Red Hat OpenJDK 11](https://access.redhat.com/documentation/en-us/openjdk/11/html-single/getting_started_with_openjdk_11/index#openjdk-overview), a free and open source implementation of the Java Platform, Standard Edition (Java SE) by default.
4+
5+
To provide an illustrative example on how to install an alternative JDK and instruct the Red Hat Single Sign-On 7.5 container images to use it, the 'ibm-semeru-open-11-jdk' subdirectory contains a definition of Red Hat Single Sign-On 7.5 container file switching the JDK runtime to the latest available release of [IBM Semeru Runtime Open Edition Java 11 (LTS)](https://github.com/ibmruntimes/semeru11-binaries/releases/latest).
6+
7+
## Building the Red Hat Single Sign-On 7.5 container image with latest release of IBM Semeru 11 JDK Open Edition
8+
9+
You can build this example by creating a new build using OpenShift CLI (oc) tool. Specify:
10+
* The vanilla `rh-sso-7/sso75-openshift-rhel8` image stream to use as the builder,
11+
* The Docker build strategy to use for build execution, and
12+
* The Git repository, branch name and particular context directory within the repository as the source of the build
13+
14+
**Prerequisites**
15+
16+
* Ensure you have [OpenShift CLI (oc) installed](https://docs.openshift.com/container-platform/latest/cli_reference/openshift_cli/getting-started-cli.html#installing-openshift-cli)
17+
18+
**Procedure**
19+
20+
1. Ensure that you are logged in as a cluster administrator or a user with project administrator access to the global `openshift` project. Choose the following command based on your version of OpenShift Container Platform:
21+
22+
* If you are running an OpenShift Container Platform v3 based cluster instance on (some) of your master host(s), perform the following:
23+
24+
```
25+
$ oc login -u system:admin
26+
```
27+
28+
* If you are running an OpenShift Container Platform v4 based cluster instance, [log in to the CLI](https://docs.openshift.com/container-platform/latest/cli_reference/openshift_cli/getting-started-cli.html#cli-logging-in_cli-developer-commands) as the [kubeadmin](https://docs.openshift.com/container-platform/latest/authentication/remove-kubeadmin.html#understanding-kubeadmin_removing-kubeadmin) user:
29+
30+
```
31+
$ oc login -u kubeadmin -p password https://openshift.example.com:6443
32+
```
33+
34+
2. Execute the following command:
35+
36+
```
37+
$ oc new-build \
38+
--context-dir=jdk/ibm-semeru-open-11-jdk \
39+
--image-stream=sso75-openshift-rhel8 \
40+
--name=sso75-openshift-rhel8-ibm-semeru-11-jdk \
41+
--namespace=openshift \
42+
--strategy=docker \
43+
https://github.com/jboss-container-images/redhat-sso-7-openshift-image.git#sso75-dev
44+
```
45+
46+
When submitted, this command creates a new `sso75-openshift-rhel8-ibm-semeru-11-jdk` BuildConfig definition in the global `openshift` project and launches a build from it. Moreover, a new `sso75-openshift-rhel8-ibm-semeru-11-jdk` ImageStream is also created in the global `openshift` project.
47+
48+
## Acquiring OpenShift templates for the new Red Hat Single Sign-On 7.5 container `sso75-openshift-rhel8-ibm-semeru-11-jdk` image stream
49+
50+
You can obtain OpenShift templates for the newly produced `sso75-openshift-rhel8-ibm-semeru-11-jdk` image stream by performing the following modifications [to the standard templates available for the Red Hat Single Sign-On 7.5 container image](https://github.com/jboss-container-images/redhat-sso-7-openshift-image/tree/sso75-dev/templates):
51+
52+
* Change the default image stream name and image tag from `"sso75-openshift-rhel8:7.5"` to `"sso75-openshift-rhel8-ibm-semeru-11-jdk"`,
53+
54+
* Optinally add a custom suffix to the name of the original template later better to distinguish the newly created templates for IBM Semeru 11 JDK Open Edition from the original one. Alternatively, if **you just want to modify** [**the default Red Hat Single Sign-On 7.5 container image OpenShift templates**](https://access.redhat.com/documentation/en-us/red_hat_single_sign-on/7.5/html-single/red_hat_single_sign-on_for_openshift#sso-templates) to start using the new `sso75-openshift-rhel8-ibm-semeru-11-jdk` image stream, then **define the custom suffix to be empty string**.
55+
56+
### Modifying the default Red Hat Single Sign-On 7.5 container image templates to use `"sso75-openshift-rhel8-ibm-semeru-11-jdk"` image stream
57+
58+
Use this option if you want to continue using the [**the default Red Hat Single Sign-On 7.5 container image OpenShift templates**](https://access.redhat.com/documentation/en-us/red_hat_single_sign-on/7.5/html-single/red_hat_single_sign-on_for_openshift#sso-templates) with the new `sso75-openshift-rhel8-ibm-semeru-11-jdk` image stream.
59+
60+
**Prerequisites**
61+
62+
* Ensure you have [the default OpenShift templates for Red Hat Single Sign-On 7.5 container image installed](https://access.redhat.com/documentation/en-us/red_hat_single_sign-on/7.5/html-single/red_hat_single_sign-on_for_openshift/index#image-streams-applications-templates).
63+
64+
**Procedure**
65+
66+
1. Set TEMPLATE\_SUFFIX environment variable to empty string and run the `acquire-ibm-semeru-open-11-jdk-rh-sso-templates.sh` helper script as follows:
67+
68+
```
69+
$ TEMPLATE_SUFFIX="" ./ibm-semeru-open-11-jdk/scripts/templates/acquire-ibm-semeru-open-11-jdk-rh-sso-templates.sh
70+
```
71+
72+
In this case the `./ibm-semeru-open-11-jdk/scripts/templates/acquire-ibm-semeru-open-11-jdk-rh-sso-templates.sh` script will just change the image stream name from `"sso75-openshift-rhel8:7.5"` to `"sso75-openshift-rhel8-ibm-semeru-11-jdk"` for each of the default Red Hat Single Sign-On 7.5 container image templates.
73+
74+
As a result, the output of the script looks as follows:
75+
76+
```
77+
$ TEMPLATE_SUFFIX="" ./ibm-semeru-open-11-jdk/scripts/templates/acquire-ibm-semeru-open-11-jdk-rh-sso-templates.sh
78+
template.template.openshift.io "sso75-https" deleted
79+
template.template.openshift.io/sso75-https replaced
80+
template.template.openshift.io "sso75-postgresql" deleted
81+
template.template.openshift.io/sso75-postgresql replaced
82+
template.template.openshift.io "sso75-postgresql-persistent" deleted
83+
template.template.openshift.io/sso75-postgresql-persistent replaced
84+
template.template.openshift.io "sso75-x509-https" deleted
85+
template.template.openshift.io/sso75-x509-https replaced
86+
template.template.openshift.io "sso75-x509-postgresql" deleted
87+
template.template.openshift.io/sso75-x509-postgresql-persistent replaced
88+
```
89+
90+
### Generating IBM Semeru 11 JDK Open Edition specific Red Hat Single Sign-On 7.5 container image templates
91+
92+
Use this option if you want a new template with custom suffix in its name to be created for each of the default RH-SSO templates using the `sso75-openshift-rhel8-ibm-semeru-11-jdk` image stream.
93+
94+
**Prerequisites**
95+
96+
* Ensure you have [the default OpenShift templates for Red Hat Single Sign-On 7.5 container image installed](https://access.redhat.com/documentation/en-us/red_hat_single_sign-on/7.5/html-single/red_hat_single_sign-on_for_openshift/index#image-streams-applications-templates).
97+
98+
99+
**Procedure**
100+
101+
1. Set TEMPLATE\_SUFFIX environment variable to contain the desired suffix for newly generated templates, for example `"-ibm-semeru-11-jdk"`. Then run the `acquire-ibm-semeru-open-11-jdk-rh-sso-templates.sh` helper script as follows:
102+
103+
104+
```
105+
$ TEMPLATE_SUFFIX="-ibm-semeru-11-jdk" ./ibm-semeru-open-11-jdk/scripts/templates/acquire-ibm-semeru-open-11-jdk-rh-sso-templates.sh
106+
```
107+
108+
In this case the `./ibm-semeru-open-11-jdk/scripts/templates/acquire-ibm-semeru-open-11-jdk-rh-sso-templates.sh` script:
109+
110+
1. First creates a Semeru JDK 11 counterpart copy of the particular default template with specified template suffix appended to the file name of the original template,
111+
2. Updates the `.metadata.name` field of that template copy to match the new name of the template,
112+
3. Replaces the name of the default image stream in the `sso` DeploymentConfig definition of the template with `sso75-openshift-rhel8-ibm-semeru-11-jdk` image stream,
113+
4. Finally, recreates the template with the new name using the updated image stream in the global `openshift` project.
114+
115+
As a result, the output of the script looks as follows:
116+
117+
```
118+
$ TEMPLATE_SUFFIX="-ibm-semeru-11-jdk" ./ibm-semeru-open-11-jdk/scripts/templates/acquire-ibm-semeru-open-11-jdk-rh-sso-templates.sh
119+
template.template.openshift.io "sso75-https-ibm-semeru-11-jdk" deleted
120+
template.template.openshift.io/sso75-https-ibm-semeru-11-jdk replaced
121+
template.template.openshift.io "sso75-postgresql-ibm-semeru-11-jdk" deleted
122+
template.template.openshift.io/sso75-postgresql-ibm-semeru-11-jdk replaced
123+
template.template.openshift.io "sso75-postgresql-persistent-ibm-semeru-11-jdk" deleted
124+
template.template.openshift.io/sso75-postgresql-persistent-ibm-semeru-11-jdk replaced
125+
template.template.openshift.io "sso75-x509-https-ibm-semeru-11-jdk" deleted
126+
template.template.openshift.io/sso75-x509-https-ibm-semeru-11-jdk replaced
127+
template.template.openshift.io "sso75-x509-postgresql-persistent-ibm-semeru-11-jdk" deleted
128+
template.template.openshift.io/sso75-x509-postgresql-persistent-ibm-semeru-11-jdk replaced
129+
```
130+
131+
## Deploying Red Hat Single Sign-On 7.5 container image with latest release of IBM Semeru 11 JDK Open Edition
132+
133+
You can deploy Red Hat Single Sign-On 7.5 container image using latest IBM Semeru 11 JDK Open Edition as usual. The only differing step is the name of the template to use depending if default templates were overwritten, or new ones were generated.
134+
135+
**Procedure**
136+
137+
1. Create a `semeru-demo` project:
138+
139+
```
140+
$ oc new-project semeru-demo
141+
```
142+
143+
2. Create a new application, using the Red Hat Single Sign-On 7.5 container image with latest release of IBM Semeru 11 JDK Open Edition as usual. For example, run:
144+
145+
```
146+
$ oc new-app --template=sso75-x509-https
147+
```
148+
149+
if you previously modified the default `sso75-x509-https` template to start using the `sso75-openshift-rhel8-ibm-semeru-11-jdk`, or run
150+
151+
```
152+
$ oc new-app --template=sso75-x509-https-ibm-semeru-11-jdk
153+
```
154+
155+
if you previously generated IBM Semeru 11 JDK Open Edition templates using the `-ibm-semeru-11-jdk` suffix and want to deploy the IBM Semeru counterpart of `sso75-x509-https` template.
156+
157+
## References
158+
159+
* [IBM Semeru Runtimes Open Edition for Java 11 binaries GitHub repository](https://github.com/ibmruntimes/semeru11-binaries)
160+
* [IBM Semeru Runtimes main GitHub repository](https://github.com/ibmruntimes/Semeru-Runtimes)
161+
* [IBM Semeru Runtimes website](https://developer.ibm.com/languages/java/semeru-runtimes)
162+
* [IBM Semeru Runtimes support page](https://www.ibm.com/support/pages/semeru-runtimes-support/)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM registry.redhat.io/rh-sso-7/sso75-openshift-rhel8:latest
2+
# Define the (buildtime) user
3+
USER root
4+
# Copy the helper container image script
5+
COPY scripts/image /tmp/scripts
6+
# Make IBM Semeru 11 JDK the default JDK
7+
RUN [ "sh", "-x", "/tmp/scripts/make-ibm-semeru-open-11-jdk-the-default-jdk.sh" ]
8+
# Remove helper scripts
9+
RUN [ ! -d "/tmp/scripts" ] || rm -rf "/tmp/scripts"
10+
# Define the (runtime) user
11+
USER jboss
12+
# Define the (runtime) working directory
13+
WORKDIR /home/jboss
14+
# Define the default run cmd
15+
CMD ["/opt/eap/bin/openshift-launch.sh"]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
# Install the 'dejavu-sans-fonts' IBM Semeru 11 JDK RPM dependency first
6+
# Moreover, install also 'jq' later to parse the release info JSON file of
7+
# latest IBM Semeru 11 JDK GitHub tag (release)
8+
microdnf -y install dejavu-sans-fonts jq && microdnf clean all
9+
10+
# Given the architecture
11+
# shellcheck disable=SC2155
12+
readonly ARCH=$(uname -i)
13+
14+
# Get the release info JSON file for latest IBM Semeru 11 JDK tag from GitHub
15+
# shellcheck disable=SC2155
16+
readonly LATEST_SEMERU_11_JDK_RELEASE_JSON=$(
17+
curl --header "Accept: application/vnd.github.v3+json" --show-error --silent \
18+
"https://api.github.com/repos/ibmruntimes/semeru11-binaries/releases/latest"
19+
)
20+
21+
# Out of all assets published for latest IBM Semeru 11 JDK release select just
22+
# the download URL of RPM package specific for this architecture
23+
# shellcheck disable=SC2155
24+
readonly LATEST_SEMERU_11_JDK_RPM=$(
25+
# Return URL of that asset from release info, having 'content_type' set to
26+
# 'application/x-rpm', ending with '${ARCH}.rpm}' and not being a JRE RPM
27+
jq '.assets[]
28+
| select(.content_type == "application/x-rpm")
29+
| .browser_download_url
30+
| select(endswith("'"${ARCH}"'.rpm") and (contains("jre") | not))' \
31+
<<< "${LATEST_SEMERU_11_JDK_RELEASE_JSON[@]}" | tr -d '"'
32+
)
33+
34+
# Import the IBM Semeru Runtimes public GPG key
35+
# URL below from https://www.ibm.com/support/pages/semeru-runtimes-verification/
36+
# section "RPM Package Manager packages (.rpm)"
37+
rpm --import "https://public.dhe.ibm.com/ibmdl/export/pub/systems/cloud/runtimes/java/certificates/ibm-semeru-public-GPGkey.pgp"
38+
39+
# Download the latest IBM Semeru 11 JDK Open Edition RPM
40+
curl -OLJ --show-error --silent "${LATEST_SEMERU_11_JDK_RPM}"
41+
42+
# Verify the signatures & digests of the downloaded RPM are correct
43+
rpmkeys -Kv "./$(basename "${LATEST_SEMERU_11_JDK_RPM}")"
44+
45+
# If so, install the RPM
46+
rpm -i "./$(basename "${LATEST_SEMERU_11_JDK_RPM}")"
47+
48+
# Make latest IBM Semeru 11 JDK the default JDK
49+
alternatives --set java /usr/lib/jvm/ibm-semeru-open-11-jdk/bin/java
50+
alternatives --set javac /usr/lib/jvm/ibm-semeru-open-11-jdk/bin/javac
51+
export JAVA_SECURITY_FILE=/usr/lib/jvm/ibm-semeru-open-11-jdk/conf/security/java.security
52+
export JAVA_HOME=/usr/lib/jvm/ibm-semeru-open-11-jdk
53+
54+
# Remove the (formerly default) OpenJDK 11 RPM packages
55+
microdnf remove java-11-openjdk{,-devel,-headless}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
# About:
6+
#
7+
# Helper script to generate OpenShift templates for Red Hat Single Sign-On 7.5
8+
# container image using non-default IBM Semeru 11 Open Edition JDK. It can:
9+
#
10+
# * Either modify the default RH-SSO templates to start using the newly created
11+
# "sso75-openshift-rhel8-ibm-semeru-11-jdk" image stream,
12+
#
13+
# * Or keep the default RH-SSO templates unchanged, and for each of them
14+
# generate a counterpart IBM Semeru 11 Open Edition JDK specific template
15+
# with custom name depending on specified TEMPLATE_SUFFIX environment
16+
# variable
17+
#
18+
# Run the script without arguments for additional usage details
19+
20+
21+
# Define constants to hold the default (original) and the new image stream
22+
# name for the RH-SSO templates
23+
readonly ORIGINAL_RH_SSO_IMAGE_STREAM_AND_TAG="sso75-openshift-rhel8:7.5"
24+
readonly UPDATED_RH_SSO_IMAGE_STREAM_AND_TAG="sso75-openshift-rhel8-ibm-semeru-11-jdk:latest"
25+
26+
# Describe the two possible ways of using template suffix
27+
# shellcheck disable=SC2155
28+
readonly TEMPLATE_SUFFIX_HEREDOC=$(cat << EOTSHD
29+
TEMPLATE_SUFFIX variable is not set. Please set it to:
30+
31+
a) The empty string, if you want to start using the default RH-SSO templates
32+
with the new "sso75-openshift-rhel8-ibm-semeru-11-jdk" image stream:
33+
34+
$ TEMPLATE_SUFFIX="" $0
35+
36+
In this case each of the installed default RH-SSO templates will be
37+
modified to start using the new "sso75-openshift-rhel8-ibm-semeru-11-jdk"
38+
image stream.
39+
40+
b) The desired string, if you want to derive new OpenShift templates for the
41+
"sso75-openshift-rhel8-ibm-semeru-11-jdk" image stream from the default
42+
RH-SSO templates. For example:
43+
44+
$ TEMPLATE_SUFFIX="-ibm-semeru-11-jdk" $0
45+
46+
In this case the default RH-SSO templates will remain unchanged. Instead
47+
for each of the installed default RH-SSO templates, a new template with a
48+
name of '<original-template><template-suffix>' will be created for the
49+
"sso75-openshift-rhel8-ibm-semeru-11-jdk" image stream.
50+
51+
For example, for TEMPLATE_SUFFIX matching "-ibm-semeru-11-jdk" the
52+
counterpart IBM Semeru 11 JDK template of the default "sso75-x509-https"
53+
RH-SSO template will have the name of "sso75-x509-https-ibm-semeru-11-jdk"
54+
etc.
55+
EOTSHD
56+
)
57+
58+
# TEMPLATE_SUFFIX environment variable has to be set. If not, that's an error
59+
if [ -z "${TEMPLATE_SUFFIX+set}" ]
60+
then
61+
echo -e "\n${TEMPLATE_SUFFIX_HEREDOC}\n"
62+
exit 1
63+
fi
64+
65+
# Ensure OpenShift CLI (oc) tool is installed. If not, that's en error
66+
if ! oc version --client >& /dev/null
67+
then
68+
# shellcheck disable=SC2155
69+
readonly ocErrorMessage=$(cat << EOOCEM
70+
Please ensure you have the OpenShift CLI (oc) tool installed:
71+
* https://docs.openshift.com/container-platform/latest/cli_reference/openshift_cli/getting-started-cli.html#installing-openshift-cli
72+
EOOCEM
73+
)
74+
echo -e "\n${ocErrorMessage}\n"
75+
exit 1
76+
fi
77+
78+
# Ensure the user is logged in
79+
if ! oc whoami >& /dev/null
80+
then
81+
# shellcheck disable=SC2155
82+
readonly ocLoginRequiredMessage=$(cat << EOOCLRM
83+
Please log in as a cluster administrator or a user with project administrator access to the global "openshift" project.
84+
EOOCLRM
85+
)
86+
echo -e "\n${ocLoginRequiredMessage}\n"
87+
exit 1
88+
fi
89+
90+
# Array of all RH-SSO templates existing in the OpenShift cluster. It's a sum
91+
# of the default ones together with those generated by previous runs of this
92+
# script
93+
mapfile -t ALL_RH_SSO_TEMPLATES< <(
94+
oc get templates -n openshift | grep sso75 | cut -d ' ' -f 1
95+
)
96+
# Such array has to be non-empty. If not, that's an error
97+
if [ "${#ALL_RH_SSO_TEMPLATES[@]}" -eq "0" ]
98+
then
99+
echo "Please install the standard OpenShift RH-SSO image templates first."
100+
exit 1
101+
fi
102+
103+
# Array of various template suffixes specified by previous runs of the script
104+
#
105+
# Since there can be multiple existing template suffixes thanks to multiple
106+
# previous runs of the script using the different suffix, identify these
107+
# suffixes by filtering all the templates for one specific default template
108+
# name and subsequently removing this default template name from them
109+
# shellcheck disable=SC2207
110+
declare -a PREVIOUSLY_USED_TEMPLATE_SUFFIXES=(
111+
$(
112+
echo "${ALL_RH_SSO_TEMPLATES[*]}" | tr $' ' $'\n' |
113+
grep -P '^sso75-x509-https' | grep -Pv '^$' |
114+
sed -e 's/^sso75-x509-https//g'
115+
)
116+
)
117+
118+
# Array of default RH-SSO template names is a subset of all RH-SSO templates
119+
declare -a DEFAULT_RH_SSO_TEMPLATES=( "${ALL_RH_SSO_TEMPLATES[@]}" )
120+
# Except those containing some of previously used suffixes in their name
121+
for previousSuffix in "${PREVIOUSLY_USED_TEMPLATE_SUFFIXES[@]}"
122+
do
123+
# Globbing is actually intentional in the following statement
124+
# shellcheck disable=SC2206
125+
DEFAULT_RH_SSO_TEMPLATES=(
126+
${DEFAULT_RH_SSO_TEMPLATES[@]/*${previousSuffix}/}
127+
)
128+
done
129+
130+
# Generate the RH-SSO templates for the latest release of IBM Semeru 11 JDK
131+
# Open Edition based on specified template suffix -- either overwrite the
132+
# default ones, or generate new ones with custom names
133+
for tmplName in "${DEFAULT_RH_SSO_TEMPLATES[@]}"
134+
do
135+
SEMERU_TEMPLATE_PATH="/tmp/${tmplName}${TEMPLATE_SUFFIX}.json"
136+
# Get the code of particular template in JSON format
137+
oc get template "${tmplName}" -n openshift -o json > "${SEMERU_TEMPLATE_PATH}"
138+
# Update template name within template code
139+
sed -i "s/${tmplName}/${tmplName}${TEMPLATE_SUFFIX}/g" "${SEMERU_TEMPLATE_PATH}"
140+
# Update image stream name and tag within template code
141+
sed -i "s/${ORIGINAL_RH_SSO_IMAGE_STREAM_AND_TAG}/${UPDATED_RH_SSO_IMAGE_STREAM_AND_TAG}/g" "${SEMERU_TEMPLATE_PATH}"
142+
# Recreate the updated template with template suffix in global 'openshift' project
143+
oc replace --force -f "${SEMERU_TEMPLATE_PATH}"
144+
# Remove the intermediary template file
145+
rm -f "${SEMERU_TEMPLATE_PATH}"
146+
done

0 commit comments

Comments
 (0)