diff --git a/templates/jlink/Dockerfile b/templates/jlink/Dockerfile deleted file mode 100644 index e73acebf..00000000 --- a/templates/jlink/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -#multi-stage build for jlinked application JAR and JRE - -#Stage-1: ubi9-jlinked-image is builder image + application + jlinked JVM -# install additional system dependencies (for ubi-micro) to /mnt/jrootfs -FROM ubi9-jlinked-image AS ubi9-jlinked-image -USER 0 -RUN mkdir -p /mnt/jrootfs -RUN microdnf install --installroot /mnt/jrootfs --releasever 9 --setopt install_weak_deps=0 --nodocs -y \ - --config=/etc/dnf/dnf.conf \ - --noplugins \ - --setopt=cachedir=/var/cache \ - --setopt=reposdir=/etc/yum.repos.d \ - --setopt=varsdir=/etc/dnf/vars \ - grep gawk -RUN rm -rf /mnt/jrootfs/var/cache/* /mnt/jrootfs/var/lib/rpm /mnt/jrootfs/var/lib/dnf - -#Stage-2:copy application JAR and jlinked JRE to runtime image -FROM registry.access.redhat.com/ubi9/ubi-micro AS lean-runtime -ARG JAVA_HOME=/usr/lib/jvm/java - -COPY --from=ubi9-jlinked-image /mnt/jrootfs/ / -COPY --from=ubi9-jlinked-image /deployments /deployments -COPY --from=ubi9-jlinked-image /tmp/jre ${JAVA_HOME} -COPY --from=ubi9-jlinked-image /opt/jboss/container/ /opt/jboss/container/ -# these are in the micro image -RUN rm -rf /var/lib/dnf /var/lib/rpm - -ENV JAVA_HOME="${JAVA_HOME}" PATH="${JAVA_HOME}/bin:$PATH" -USER 185 -CMD /opt/jboss/container/java/run/run-java.sh diff --git a/templates/jlink/README.md b/templates/jlink/README.md index f453d0f7..07c05def 100644 --- a/templates/jlink/README.md +++ b/templates/jlink/README.md @@ -2,55 +2,57 @@ Try it out: -## Stage 1: build and analyse application with OpenShift source-to-image (S2I) +## Stage 1: create ubi9 jlink imagestream and push a ubi9 image with jmods installed to it. You need: -1. Access to an OpenShift instance, or, use [the s2i standalone program](https://github.com/openshift/source-to-image) - * _([you might need to use an old version](https://github.com/openshift/source-to-image/issues/1135))_ -2. The OpenJDK builder image (with the customisations from the `jlink-dev` branch). - There's one at `quay.io/jdowland/jlink:latest` -3. A quickstart ([there's a specially-prepared Quarkus quickstart](https://github.com/jmtd/quarkus-quickstarts/tree/OPENJDK-631-fastjar-layout); - in the future [the mainline Quarkus quickstarts will be suitable](https://github.com/quarkusio/quarkus-quickstarts/pull/1359)) +1. Access to an OpenShift instance, such as crc +2. UBI9 OpenJDK ImageStreams. You can load them from this repository with -Here's a recipe using local `s2i` + oc create -f templates/ubi9-community-image-streams.json -``` -BASEIMG=quay.io/jdowland/jlink:latest -APPSRC=https://github.com/jmtd/quarkus-quickstarts.git -CONTEXTDIR=getting-started -REV=OPENJDK-631-fastjar-layout -OUTIMG=ubi9-jlinked-image +Steps to produce the imagestream and image: -s2i build --pull-policy never --context-dir=${CONTEXTDIR} -r=${REV} \ - -e QUARKUS_PACKAGE_TYPE=uber-jar \ - -e S2I_ENABLE_JLINK=true \ - ${APPSRC} \ - ${BASEIMG} \ - ${OUTIMG} -``` +1. install the template -## Stage 2: multi-stage build to assemble micro runtime + oc create -f templates/jlink/jlink-builder/jlink-builder-template.yaml -You need: +This will create a Template called jlink-builder-template, you should see + + template.template.openshift.io/jlink-builder-template created + +and after running oc get template, it should be in the list as + + jlink-builder-template Template to produce an imagestream and buildconfig for a Jlink builder image 1 (all set) 2 + +2. Set the parameters and create the imagestream and buildconfig from the template. + +The template for now defines a single parameter, JDK_VERSION. Setting this will set the version of the builder image used in the BuildConfig. Currently suppoted values are 11, 17, and 21. By default this will be 11. + + oc process --parameters jlink-builder-template + + NAME DESCRIPTION GENERATOR VALUE + JDK_VERSION JDK version to produce a jmods image for 11 + +In order to set the JDK version, you will need to use the -p flag of oc process. To process the template and create the imagestreams, simply run -1. The output image from the first stage - * _here's one we made earlier: `quay.io/jdowland/jlink:quarkus-getting-started`_ -2. OpenShift, or a container runtime (e.g. Docker) -3. [this Dockerfile](Dockerfile) (In future this is an OpenShift template) + oc process jlink-builder-template -p JDK_VERSION=11 | oc create -f - + + imagestream.image.openshift.io/ubi9-openjdk-11-jlink created + buildconfig.build.openshift.io/jlink-builder-jdk-11 created -With docker, from a clone of this repository, in this directory: +3. Start and observe the build -``` -docker build -t myapp -f . -``` +Start the build using -## Stage 3: try it out! + oc start-build jlink-builder-jdk-11 + + build.build.openshift.io/jlink-builder-jdk-11-1 started -Does it work? +Then observe it by using - docker run --rm -ti -p 8080 myapp + oc logs -f bc/jlink-builder-jdk-11 -How big is it? +## Stage 2: build and analyse application with OpenShift source-to-image (S2I) - docker inspect -f '{{.Size}}' myapp +TODO diff --git a/templates/jlink/jlink-builder/README.md b/templates/jlink/jlink-builder/README.md deleted file mode 100644 index 07c05def..00000000 --- a/templates/jlink/jlink-builder/README.md +++ /dev/null @@ -1,58 +0,0 @@ -# OpenShift-JLink PoC - -Try it out: - -## Stage 1: create ubi9 jlink imagestream and push a ubi9 image with jmods installed to it. - -You need: - -1. Access to an OpenShift instance, such as crc -2. UBI9 OpenJDK ImageStreams. You can load them from this repository with - - oc create -f templates/ubi9-community-image-streams.json - -Steps to produce the imagestream and image: - -1. install the template - - oc create -f templates/jlink/jlink-builder/jlink-builder-template.yaml - -This will create a Template called jlink-builder-template, you should see - - template.template.openshift.io/jlink-builder-template created - -and after running oc get template, it should be in the list as - - jlink-builder-template Template to produce an imagestream and buildconfig for a Jlink builder image 1 (all set) 2 - -2. Set the parameters and create the imagestream and buildconfig from the template. - -The template for now defines a single parameter, JDK_VERSION. Setting this will set the version of the builder image used in the BuildConfig. Currently suppoted values are 11, 17, and 21. By default this will be 11. - - oc process --parameters jlink-builder-template - - NAME DESCRIPTION GENERATOR VALUE - JDK_VERSION JDK version to produce a jmods image for 11 - -In order to set the JDK version, you will need to use the -p flag of oc process. To process the template and create the imagestreams, simply run - - oc process jlink-builder-template -p JDK_VERSION=11 | oc create -f - - - imagestream.image.openshift.io/ubi9-openjdk-11-jlink created - buildconfig.build.openshift.io/jlink-builder-jdk-11 created - -3. Start and observe the build - -Start the build using - - oc start-build jlink-builder-jdk-11 - - build.build.openshift.io/jlink-builder-jdk-11-1 started - -Then observe it by using - - oc logs -f bc/jlink-builder-jdk-11 - -## Stage 2: build and analyse application with OpenShift source-to-image (S2I) - -TODO diff --git a/templates/jlink/jlink-builder/jlink-builder-template.yaml b/templates/jlink/jlink-builder/jlink-builder-template.yaml deleted file mode 100644 index c122e2ea..00000000 --- a/templates/jlink/jlink-builder/jlink-builder-template.yaml +++ /dev/null @@ -1,95 +0,0 @@ ---- -apiVersion: template.openshift.io/v1 -kind: Template -metadata: - annotations: - description: Template to produce an imagestream and buildconfig for a Jlink builder image - name: jlink-builder-template -parameters: -- description: JDK version to produce a jmods image and imagestream for - name: JDK_VERSION - value: "11" - required: true -- description: Application to run the jlink workflow on - name: APPLICATION - required: true -- description: Git Ref to run the jlink workflow on - name: REF - required: true -- description: Context Dir to use for the jlink workflow - name: CONTEXT_DIR - required: true -objects: -- apiVersion: image.openshift.io/v1 - kind: ImageStream - metadata: - name: ubi9-openjdk-${JDK_VERSION}-jlink - spec: - lookupPolicy: - local: false -- apiVersion: build.openshift.io/v1 - kind: BuildConfig - metadata: - name: jlink-builder-jdk-${JDK_VERSION} - labels: - app: jlink-builder-jdk-${JDK_VERSION} - spec: - source: - dockerfile: | - FROM - - USER 0 - RUN microdnf --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install -y java-${JDK_VERSION}-openjdk-jmods - RUN mkdir -p /mnt/jrootfs - RUN microdnf install --installroot /mnt/jrootfs --releasever 9 --setopt install_weak_deps=0 --nodocs -y \ - --config=/etc/dnf/dnf.conf \ - --noplugins \ - --setopt=cachedir=/var/cache \ - --setopt=reposdir=/etc/yum.repos.d \ - --setopt=varsdir=/etc/dnf/vars \ - grep gawk - RUN rm -rf /mnt/jrootfs/var/cache/* /mnt/jrootfs/var/lib/rpm /mnt/jrootfs/var/lib/dnf - USER 185 - strategy: - dockerStrategy: - from: - kind: ImageStreamTag - name: ubi9-openjdk-${JDK_VERSION}:1.18 - output: - to: - kind: ImageStreamTag - name: ubi9-openjdk-${JDK_VERSION}-jlink:latest -- apiVersion: image.openshift.io/v1 - kind: ImageStream - metadata: - name: intermediate - spec: - lookupPolicy: - local: false -- apiVersion: build.openshift.io/v1 - kind: BuildConfig - metadata: - name: jlink-s2i-jdk-${JDK_VERSION} - labels: - app: jlink-s2i-jdk-${JDK_VERSION} - spec: - source: - type: Git - git: - uri: ${APPLICATION} - ref: ${REF} - contextDir: ${CONTEXT_DIR} - strategy: - sourceStrategy: - from: - kind: ImageStreamTag - name: ubi9-openjdk-${JDK_VERSION}-jlink:latest # Output Imagestream for Stage 1 - pullPolicy: Always - env: - - name: S2I_ENABLE_JLINK - value: "true" - - name: LOGGING_SCRIPT_DEBUG - value: "true" - output: - to: - kind: ImageStreamTag - name: intermediate:latest diff --git a/templates/jlink/jlinked-app.yaml b/templates/jlink/jlinked-app.yaml new file mode 100644 index 00000000..7f041a72 --- /dev/null +++ b/templates/jlink/jlinked-app.yaml @@ -0,0 +1,190 @@ +--- +apiVersion: template.openshift.io/v1 +kind: Template +metadata: + annotations: + description: Template to produce imagestreams and buildconfigs for jlinked application + name: jlink-app-template +############################################################################## +# List of parameters required to create template +parameters: +- description: JDK version to produce a jmods image and imagestream for + name: JDK_VERSION + value: "11" + required: true +- description: Application to run the jlink workflow on + name: APP_URI + required: true +- description: Git Ref to run the jlink workflow on + name: REF + required: true +- description: Context Dir to use for the jlink workflow + name: CONTEXT_DIR + required: true +############################################################################## +# Following are the objects(imagestream and buildconfigs) for all the 3-stages +objects: +############################################################################## +# stage-1: Output ImageStream +- apiVersion: image.openshift.io/v1 + kind: ImageStream + metadata: + name: ubi9-openjdk-${JDK_VERSION}-jlink + spec: + lookupPolicy: + local: false +############################################################################## +# stage-1: BuildConfig +- apiVersion: build.openshift.io/v1 + kind: BuildConfig + metadata: + name: jlink-builder-jdk-${JDK_VERSION} + labels: + app: jlink-builder-jdk-${JDK_VERSION} + spec: + source: + dockerfile: | + FROM - + USER 0 + RUN microdnf --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install -y java-${JDK_VERSION}-openjdk-jmods + RUN mkdir -p /mnt/jrootfs + RUN microdnf install --installroot /mnt/jrootfs --releasever 9 --setopt install_weak_deps=0 --nodocs -y \ + --config=/etc/dnf/dnf.conf \ + --noplugins \ + --setopt=cachedir=/var/cache \ + --setopt=reposdir=/etc/yum.repos.d \ + --setopt=varsdir=/etc/dnf/vars \ + grep gawk + RUN rm -rf /mnt/jrootfs/var/cache/* /mnt/jrootfs/var/lib/rpm /mnt/jrootfs/var/lib/dnf + USER 185 + strategy: + dockerStrategy: + from: + kind: ImageStreamTag + name: ubi9-openjdk-${JDK_VERSION}:1.18 # Refer README.md to create this ImageStream + output: + to: + kind: ImageStreamTag + name: ubi9-openjdk-${JDK_VERSION}-jlink:latest +############################################################################## +# stage-2: Output ImageStream +- apiVersion: image.openshift.io/v1 + kind: ImageStream + metadata: + name: intermediate + spec: + lookupPolicy: + local: false +############################################################################## +# stage-2: BuildConfig +- apiVersion: build.openshift.io/v1 + kind: BuildConfig + metadata: + name: jlink-s2i-jdk-${JDK_VERSION} + labels: + app: jlink-s2i-jdk-${JDK_VERSION} + spec: + source: + type: Git + git: + uri: ${APP_URI} + ref: ${REF} + contextDir: ${CONTEXT_DIR} + strategy: + sourceStrategy: + from: + kind: ImageStreamTag + name: ubi9-openjdk-${JDK_VERSION}-jlink:latest # Output Imagestream from stage-1 + pullPolicy: Always + env: + - name: S2I_ENABLE_JLINK + value: "true" + - name: LOGGING_SCRIPT_DEBUG + value: "true" + output: + to: + kind: ImageStreamTag + name: intermediate:latest +############################################################################## +# stage-3: The ubi-micro ImageStream +- apiVersion: image.openshift.io/v1 + kind: ImageStream + metadata: + name: ubimicro + spec: + lookupPolicy: + local: true + tags: + - from: + kind: DockerImage + name: registry.access.redhat.com/ubi9/ubi-micro + name: latest + referencePolicy: + type: Local +############################################################################## +# stage-3: Output ImageStream +- apiVersion: image.openshift.io/v1 + kind: ImageStream + metadata: + name: lightweight-image + spec: + lookupPolicy: + local: false +############################################################################## +# stage-3: BuildConfig +- apiVersion: build.openshift.io/v1 + kind: BuildConfig + metadata: + name: multistage-buildconfig + spec: + source: + images: + - from: + kind: ImageStreamTag + name: intermediate:latest + paths: + - sourcePath: /mnt/jrootfs + destinationDir: jrootfs + - sourcePath: /deployments + destinationDir: deployments + - sourcePath: /tmp/jre/. + destinationDir: customJVM + - sourcePath: /opt/jboss/container/. + destinationDir: runScripts + type: Dockerfile + dockerfile: | + FROM - + ARG JAVA_HOME=/usr/lib/jvm/java + + COPY jrootfs/* / + COPY deployments / + COPY customJVM ${JAVA_HOME} + COPY runScripts /opt/jboss/container/ + # these are in the micro image + RUN rm -rf /var/lib/dnf /var/lib/rpm + + ENV JAVA_HOME="${JAVA_HOME}" PATH="${JAVA_HOME}/bin:$PATH" + USER 185 + CMD /opt/jboss/container/java/run/run-java.sh + strategy: + type: Docker + dockerStrategy: + from: + kind: ImageStreamTag + name: ubimicro:latest + output: + to: + kind: ImageStreamTag + name: lightweight-image:latest # Tag for the final output image + triggers: + - type: ConfigChange + - type: ImageChange + imageChange: + from: + kind: ImageStreamTag + name: intermediate:latest # output of stage-2 + - type: ImageChange + imageChange: + from: + kind: ImageStreamTag + name: ubimicro:latest # ImageStreamTag for registry.access.redhat.com/ubi9/ubi-micro diff --git a/templates/multistage-dockerfile-buildconfig.yaml b/templates/multistage-dockerfile-buildconfig.yaml deleted file mode 100644 index 56c019f3..00000000 --- a/templates/multistage-dockerfile-buildconfig.yaml +++ /dev/null @@ -1,106 +0,0 @@ ---- -apiVersion: template.openshift.io/v1 -kind: Template -metadata: - annotations: - description: Template to produce a light weight imagestream and buildconfig for a multistage build - name: multistage-build-template -objects: -############################################################################## -# the INPUT ImageStream (from phase 2) -- apiVersion: image.openshift.io/v1 - kind: ImageStream - metadata: - name: intermediate - spec: - lookupPolicy: - local: true - tags: - - from: - kind: DockerImage - name: quay.io/jdowland/jlink:ubi9-jlinked-image - name: latest - referencePolicy: - type: Local -############################################################################## -# the ubi-micro ImageStream -- apiVersion: image.openshift.io/v1 - kind: ImageStream - metadata: - name: ubimicro - spec: - lookupPolicy: - local: true - tags: - - from: - kind: DockerImage - name: registry.access.redhat.com/ubi9/ubi-micro - name: latest - referencePolicy: - type: Local -############################################################################## -# the OUTPUT ImageStream -- apiVersion: image.openshift.io/v1 - kind: ImageStream - metadata: - name: lightweight-image - spec: - lookupPolicy: - local: false -############################################################################## -- apiVersion: build.openshift.io/v1 - kind: BuildConfig - metadata: - name: multistage-buildconfig - spec: - source: - images: - - from: - kind: ImageStreamTag - name: intermediate:latest - paths: - - sourcePath: /mnt/jrootfs - destinationDir: jrootfs - - sourcePath: /deployments - destinationDir: deployments - - sourcePath: /tmp/jre/. - destinationDir: customJVM - - sourcePath: /opt/jboss/container/. - destinationDir: runScripts - type: Dockerfile - dockerfile: | - FROM - - ARG JAVA_HOME=/usr/lib/jvm/java - - COPY jrootfs/* / - COPY deployments / - COPY customJVM ${JAVA_HOME} - COPY runScripts /opt/jboss/container/ - # these are in the micro image - RUN rm -rf /var/lib/dnf /var/lib/rpm - - ENV JAVA_HOME="${JAVA_HOME}" PATH="${JAVA_HOME}/bin:$PATH" - USER 185 - CMD /opt/jboss/container/java/run/run-java.sh - strategy: - type: Docker - dockerStrategy: - from: - kind: ImageStreamTag - name: ubimicro:latest - output: - to: - kind: ImageStreamTag - name: lightweight-image:latest # Tag for the final output image - triggers: - - type: ConfigChange - - type: ImageChange - imageChange: - from: - kind: ImageStreamTag - name: intermediate:latest # ImageStreamTag for phase-2 output - - type: ImageChange - imageChange: - from: - kind: ImageStreamTag - name: ubimicro:latest # ImageStreamTag for registry.access.redhat.com/ubi9/ubi-micro