Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions templates/jlink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ you need:
2. UBI9 OpenJDK ImageStreams that include `jlink-dev` changes (see below)
3. The template [jlinked-app.yaml](jlinked-app.yaml).

DISCLAIMER: This template requires OpenShift to be able to resolve ImageStreams, as such it can only be used in projects where the openshift.io/run-level label set to 0 or 1. This means it cannot be used with default, kube-public, kube-system, openshift, openshift-infra, openshift-node, and other system-created projects.

## Stage 0: UBI9 OpenJDK ImageStreams with jlink-dev changes

Until the `jlink-dev` work is merged, prior to trying out the template, we must first
Expand All @@ -18,26 +20,31 @@ prepare UBI9 OpenJDK ImageStreams with `jlink-dev` support.

cekit --descriptor ubi9-openjdk-17.yaml build docker

2. Within your OpenShift project,
2. Create an OpenShift project and namespace

oc new-project jlink-dev
oc create namespace jlink

3. Within your OpenShift project,

oc create imagestream ubi9-openjdk-17
oc create imagestream openjdk-17-jlink-tech-preview

3. You may need to configure your container engine to not TLS-verify the OpenShift
4. You may need to configure your container engine to not TLS-verify the OpenShift
registry. For Docker, add the following to `/etc/docker/daemon.json` and restart
the daemon:

{
"insecure-registries": [ "default-route-openshift-image-registry.apps-crc.testing" ]
}

4. Log into the OpenShift registry, e.g.
5. Log into the OpenShift registry, e.g.

REGISTRY_AUTH_PREFERENCE=docker oc registry login

5. tag and push the dev image into it. The OpenShift console gives you the
6. tag and push the dev image into it. The OpenShift console gives you the
exact URI for your instance

docker tag ubi9/openjdk-17:1.18 default-route-openshift-image-registry.apps-crc.testing/jlink1/ubi9-openjdk-17:1.18
docker tag openjdk-tech-preview/openjdk-17-jlink-rhel9:1.18 default-route-openshift-image-registry.apps-crc.testing/jlink1/openjdk-17-jlink-tech-preview:1.18
docker push default-route-openshift-image-registry.apps-crc.testing/jlink1/ubi9-openjdk-17:1.18

## Stage 1: Load the template into OpenShift and instantiate it
Expand All @@ -52,18 +59,22 @@ Process it to create the needed objects. You can list the parameters using

Some suitable test values for the parameters are

* JDK_VERSION: 17
* JDK_VERSION: 21
* APP_URI: https://github.com/jboss-container-images/openjdk-test-applications
* REF: master
* CONTEXT_DIR: quarkus-quickstarts/getting-started-3.9.2-uberjar
* APPNAME: quarkus-quickstart
* TARGET_PORT: 8080
* SERVICE_PORT: 8080

oc process \
-p JDK_VERSION=17 \
-p APP_URI=https://github.com/jboss-container-images/openjdk-test-applications \
-p REF=master \
-p CONTEXT_DIR=quarkus-quickstarts/getting-started-3.9.2-uberjar \
-p APPNAME=quarkus-quickstart \
-p TARGET_PORT=8080 \
-p SERVICE_PORT=8080 \
templates/jlink-app-template \
| oc create -f -

Expand Down
89 changes: 81 additions & 8 deletions templates/jlink/jlinked-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
parameters:
- description: JDK version to produce a jmods image and imagestream for
name: JDK_VERSION
value: "11"
value: "21"
required: true
- description: OpenJDK builder image version tag
name: BUILDER_IMAGE_TAG
Expand All @@ -32,6 +32,14 @@ parameters:
generate: expression
from: "[a-zA-Z0-9]{16}"
required: true
- description: Target port for the created Route
name: TARGET_PORT
value: "8080"
required: true
- description: Port for the created Service to listen on
name: SERVICE_PORT
value: "8181"
required: true
message: "... The GitHub webhook secret is ${GITHUB_WEBHOOK_SECRET} ..."
##############################################################################
# Following are the objects(imagestream and buildconfigs) for all the 3-stages
Expand All @@ -41,7 +49,7 @@ objects:
- apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
name: ${APPNAME}-ubi9-openjdk-${JDK_VERSION}-jlink
name: ${APPNAME}-openjdk-${JDK_VERSION}-jlink-tech-preview
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
Expand Down Expand Up @@ -78,24 +86,27 @@ objects:
dockerStrategy:
from:
kind: ImageStreamTag
name: ubi9-openjdk-${JDK_VERSION}:${BUILDER_IMAGE_TAG} # Refer README.md to create this ImageStream
name: openjdk-${JDK_VERSION}-jlink-tech-preview:${BUILDER_IMAGE_TAG} # Refer README.md to create this ImageStream
output:
to:
kind: ImageStreamTag
name: ${APPNAME}-ubi9-openjdk-${JDK_VERSION}-jlink:latest
name: ${APPNAME}-openjdk-${JDK_VERSION}-jlink-tech-preview:latest
triggers:
- type: ConfigChange
- type: ImageChange
imageChange:
from:
kind: ImageStreamTag
name: ubi9-openjdk-${JDK_VERSION}:${BUILDER_IMAGE_TAG}
name: openjdk-${JDK_VERSION}-jlink-tech-preview:${BUILDER_IMAGE_TAG}
##############################################################################
# stage-2: Output ImageStream
- apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
name: ${APPNAME}-intermediate
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
spec:
lookupPolicy:
local: false
Expand All @@ -119,7 +130,7 @@ objects:
sourceStrategy:
from:
kind: ImageStreamTag
name: ${APPNAME}-ubi9-openjdk-${JDK_VERSION}-jlink:latest # Output Imagestream from stage-1
name: ${APPNAME}-openjdk-${JDK_VERSION}-jlink-tech-preview:latest # Output Imagestream from stage-1
pullPolicy: Always
env:
- name: S2I_ENABLE_JLINK
Expand All @@ -136,7 +147,7 @@ objects:
imageChange:
from:
kind: ImageStreamTag
name: ${APPNAME}-ubi9-openjdk-${JDK_VERSION}-jlink:latest # Output of stage-1 which serves as input to stage-2
name: ${APPNAME}-openjdk-${JDK_VERSION}-jlink-tech-preview:latest # Output of stage-1 which serves as input to stage-2
- type: GitHub
github:
secret: ${GITHUB_WEBHOOK_SECRET}
Expand Down Expand Up @@ -171,7 +182,8 @@ objects:
app.kubernetes.io/part-of: ${APPNAME}
spec:
lookupPolicy:
local: false
# Must be true for the Deployment to resolve the ImageStream
local: true
##############################################################################
# stage-3: BuildConfig
- apiVersion: build.openshift.io/v1
Expand Down Expand Up @@ -233,3 +245,64 @@ objects:
from:
kind: ImageStreamTag
name: ${APPNAME}-ubimicro:latest # ImageStreamTag for registry.access.redhat.com/ubi9/ubi-micro
##############################################################################
# DeploymentConfig and Route object specs
# DeploymentConfigs are discouraged, however the documentation sugggests to still
# use them if features are missing from Deployments, which in our case they are.
- apiVersion: apps/v1
kind: Deployment
metadata:
name: ${APPNAME}-jlinked-app-deployment
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
spec:
replicas: 1
selector:
matchLabels:
app: ${APPNAME}
template:
metadata:
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
annotations:
# Allows Deployments to use ImageStreams
alpha.image.policy.openshift.io/resolve-names: '*'
spec:
containers:
- name: ${APPNAME}-jlinked-app-container
image: ${APPNAME}-lightweight-image:latest
ports:
- containerPort: ${{TARGET_PORT}}
protocol: TCP
strategy:
type: RollingUpdate
- apiVersion: v1
kind: Service
metadata:
name: ${APPNAME}-jlinked-app-service
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
spec:
selector:
app: ${APPNAME}
ports:
- protocol: TCP
name: target-${TARGET_PORT}-tcp
port: ${{SERVICE_PORT}}
targetPort: ${{TARGET_PORT}}
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: ${APPNAME}-jlinked-app-route
labels:
app: ${APPNAME}
app.kubernetes.io/part-of: ${APPNAME}
spec:
to:
kind: Service
name: ${APPNAME}-jlinked-app-service
port:
targetPort: ${{TARGET_PORT}}