diff --git a/templates/jlink/README.md b/templates/jlink/README.md index 5532e65c..c8d43dd6 100644 --- a/templates/jlink/README.md +++ b/templates/jlink/README.md @@ -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 @@ -16,13 +18,17 @@ prepare UBI9 OpenJDK ImageStreams with `jlink-dev` support. repository](https://github.com/jboss-container-images/openjdk), branch `jlink-dev`. e.g. - cekit --descriptor ubi9-openjdk-21.yaml build docker + cekit --descriptor ubi9-openjdk-21.yaml build podman + +2. Create an OpenShift project + + oc new-project $PROJECT -2. Within your OpenShift project, +3. Within your OpenShift project, - oc create imagestream openjdk-${JDK_VERSION}-jlink-tech-preview + oc create imagestream openjdk-21-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: @@ -30,15 +36,15 @@ prepare UBI9 OpenJDK ImageStreams with `jlink-dev` support. "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 openjdk-tech-preview/openjdk-21-jlink-rhel9:latest default-route-openshift-image-registry.apps-crc.testing/jlink1/openjdk-21-jlink-tech-preview:latest - docker push default-route-openshift-image-registry.apps-crc.testing/jlink1/openjdk-21-jlink-tech-preview:latest + podman tag openjdk-tech-preview/openjdk-21-jlink-rhel9:latest default-route-openshift-image-registry.apps-crc.testing/$PROJECT/openjdk-21-jlink-tech-preview:latest + podman push default-route-openshift-image-registry.apps-crc.testing/$PROJECT/openjdk-21-jlink-tech-preview:latest ## Stage 1: Load the template into OpenShift and instantiate it @@ -57,6 +63,8 @@ Some suitable test values for the parameters are * 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=21 \ @@ -64,6 +72,8 @@ Some suitable test values for the parameters are -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 - diff --git a/templates/jlink/jlinked-app.yaml b/templates/jlink/jlinked-app.yaml index bb45c18e..1b65467a 100644 --- a/templates/jlink/jlinked-app.yaml +++ b/templates/jlink/jlinked-app.yaml @@ -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 @@ -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 @@ -96,6 +104,9 @@ objects: kind: ImageStream metadata: name: ${APPNAME}-intermediate + labels: + app: ${APPNAME} + app.kubernetes.io/part-of: ${APPNAME} spec: lookupPolicy: local: false @@ -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 @@ -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}}