Closed friedeas closed 11 months ago
I've created #2413 that should not flatten Spring Boot image layers when in docker
build strategy. However, while testing it I'm not able to see any kind of caching by docker host inside OpenShift.
We're correctly passing noCache: false
inside the BuildConfig's build strategy. There is no difference in Dockerfile generated in consecutive builds either. Not sure if this is something specific to OpenShift.
Okay, this seems to change in behavior from OpenShift 3 to OpenShift 4 as specified in this OpenShift blogpost
With OpenShift 4 we undertook a fundamental redesign of how images are built on the platform. Instead of relying on a daemon on the host to manage containers, image creation, and image pushing, we are leveraging Buildah running inside our build pods. This aligns with the general OpenShift 4 theme of making everything “just another pod.” The image cache is no longer shared. When using the host’s docker daemon, images and layers that had been pulled to the host previously could be reused by a subsequent build on that same host. Since builds no longer have access to the host, each build must pull any layers it requires each time the build is run. This helps improve the security posture of builds by providing an additional level of isolation, however it will also increase the time required to execute a build. We will be looking to reintroduce a shared image cache in the future.
When building the project against OpenShift 3.11.0 (minishift 1.34.3), I'm able to see docker cache getting used :
jkube-spring-boot3-openshift-docker-image-push : $ gradle ocBuild
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.6.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build
> Task :ocBuild
oc: Running generator spring-boot
oc: spring-boot: Using Docker image quay.io/jkube/jkube-java:0.0.19 as base / builder
oc: Spring Boot layered jar detected
oc: Using OpenShift build with strategy Docker
oc: [docker.io/testuser/jkube-spring-boot3-openshift-docker-image-push:0.0.1] "spring-boot": Created docker source tar /home/rokumar/work/repos/jkube-testing/jkube-spring-boot3-openshift-docker-image-push/build/docker/docker.io/testuser/jkube-spring-boot3-openshift-docker-image-push/0.0.1/tmp/docker-build.tar
oc: Creating BuildServiceConfig jkube-spring-boot3-openshift-docker-image-push-s2i for Docker build
oc: Starting Build jkube-spring-boot3-openshift-docker-image-push-s2i
oc: Waiting for build jkube-spring-boot3-openshift-docker-image-push-s2i-1 to complete...
oc: Step 1/11 : FROM quay.io/jkube/jkube-java:0.0.19
oc: ---> d03f69fe626d
oc: Step 2/11 : ENV JAVA_MAIN_CLASS org.springframework.boot.loader.JarLauncher JAVA_APP_DIR /deployments
oc: ---> Using cache
oc: ---> 534191c61048
oc: Step 3/11 : LABEL org.label-schema.description "" org.label-schema.version 0.0.1 org.label-schema.schema-version 1.0 org.label-schema.build-date 2023-10-06 org.label-schema.name jkube-spring-boot3-openshift-docker-image-push org.label-schema.vcs-ref 706fa97b06efd6ac6c048b0ade461b764eb91a66 org.label-schema.vcs-url git@github.com:rohankanojia-forks/jkube-testing.git
oc: ---> Running in 9d9037b9cad2
oc: ---> dee416cb53e4
oc: Removing intermediate container 9d9037b9cad2
oc: Step 4/11 : EXPOSE 8080 8778 9779
oc: ---> Running in 4a6c9335db0c
oc: ---> 4d01dcebed03CUTING [13s]
oc: Removing intermediate container 4a6c9335db0c
oc: Step 5/11 : COPY /dependencies/deployments /deployments/
oc: ---> 1e48316c126aCUTING [13s]
oc: Removing intermediate container 4106c273dae8
oc: Step 6/11 : COPY /spring-boot-loader/deployments /deployments/
oc: ---> b019b1dc6a80CUTING [13s]
oc: Removing intermediate container ff1b7eb6a4a0
oc: Step 7/11 : COPY /application/deployments /deployments/
oc: ---> 30a2e03788bbCUTING [14s]
oc: Removing intermediate container 1c3e5fbdf135
oc: Step 8/11 : WORKDIR /deployments
oc: ---> 3179904561f2CUTING [14s]
oc: Removing intermediate container 04b1f34e3700
oc: Step 9/11 : ENTRYPOINT java org.springframework.boot.loader.JarLauncher
oc: ---> Running in d200ef9cae87
oc: ---> 163e7be19769CUTING [14s]
oc: Removing intermediate container d200ef9cae87
oc: Step 10/11 : ENV "OPENSHIFT_BUILD_NAME" "jkube-spring-boot3-openshift-docker-image-push-s2i-1" "OPENSHIFT_BUILD_NAMESPACE" "myproject"
oc: ---> Running in 0354276924d1]
oc: ---> 7a42ef023f3eCUTING [14s]
oc: Removing intermediate container 0354276924d1
oc: Step 11/11 : LABEL "io.openshift.build.name" "jkube-spring-boot3-openshift-docker-image-push-s2i-1" "io.openshift.build.namespace" "myproject"
oc: ---> Running in a2215e45ec9f]
oc: ---> b39d8814f1b1
oc: Removing intermediate container a2215e45ec9f
oc: Successfully built b39d8814f1b1
oc: Pushing image docker.io/testuser/jkube-spring-boot3-openshift-docker-image-push:0.0.1 ...
oc: Pushed 2/5 layers, 43% complete
oc: Pushed 3/5 layers, 97% complete
oc: Pushed 4/5 layers, 100% complete
oc: Pushed 5/5 layers, 100% complete
oc: Push successful
oc: Build jkube-spring-boot3-openshift-docker-image-push-s2i-1 in status Complete
BUILD SUCCESSFUL in 36s
1 actionable task: 1 executed
jkube-spring-boot3-openshift-docker-image-push : $ gradle ocBuild
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.6.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build
> Task :ocBuild
oc: Running generator spring-boot
oc: spring-boot: Using Docker image quay.io/jkube/jkube-java:0.0.19 as base / builder
oc: Spring Boot layered jar detected
oc: Using OpenShift build with strategy Docker
oc: [docker.io/testuser/jkube-spring-boot3-openshift-docker-image-push:0.0.1] "spring-boot": Created docker source tar /home/rokumar/work/repos/jkube-testing/jkube-spring-boot3-openshift-docker-image-push/build/docker/docker.io/testuser/jkube-spring-boot3-openshift-docker-image-push/0.0.1/tmp/docker-build.tar
oc: Updating BuildServiceConfig jkube-spring-boot3-openshift-docker-image-push-s2i for Docker strategy:ocBuild
oc: Starting Build jkube-spring-boot3-openshift-docker-image-push-s2i
oc: Waiting for build jkube-spring-boot3-openshift-docker-image-push-s2i-2 to complete...
oc: Step 1/11 : FROM quay.io/jkube/jkube-java:0.0.19
oc: ---> d03f69fe626d
oc: Step 2/11 : ENV JAVA_MAIN_CLASS org.springframework.boot.loader.JarLauncher JAVA_APP_DIR /deployments
oc: ---> Using cache
oc: ---> 534191c61048
oc: Step 3/11 : LABEL org.label-schema.description "" org.label-schema.version 0.0.1 org.label-schema.schema-version 1.0 org.label-schema.build-date 2023-10-06 org.label-schema.name jkube-spring-boot3-openshift-docker-image-push org.label-schema.vcs-ref 706fa97b06efd6ac6c048b0ade461b764eb91a66 org.label-schema.vcs-url git@github.com:rohankanojia-forks/jkube-testing.git
oc: ---> Using cache
oc: ---> dee416cb53e4
oc: Step 4/11 : EXPOSE 8080 8778 9779
oc: ---> Using cache
oc: ---> 4d01dcebed03
oc: Step 5/11 : COPY /dependencies/deployments /deployments/
oc: ---> Using cache
oc: ---> 1e48316c126a
oc: Step 6/11 : COPY /spring-boot-loader/deployments /deployments/
oc: ---> Using cache
oc: ---> b019b1dc6a80
oc: Step 7/11 : COPY /application/deployments /deployments/
oc: ---> Using cache
oc: ---> 30a2e03788bb
oc: Step 8/11 : WORKDIR /deployments
oc: ---> Using cache
oc: ---> 3179904561f2
oc: Step 9/11 : ENTRYPOINT java org.springframework.boot.loader.JarLauncher
oc: ---> Using cache
oc: ---> 163e7be19769
oc: Step 10/11 : ENV "OPENSHIFT_BUILD_NAME" "jkube-spring-boot3-openshift-docker-image-push-s2i-2" "OPENSHIFT_BUILD_NAMESPACE" "myproject"
oc: ---> Running in 84381f68f2d7
oc: ---> 4e11ce6a7b7a
oc: Removing intermediate container 84381f68f2d7
oc: Step 11/11 : LABEL "io.openshift.build.name" "jkube-spring-boot3-openshift-docker-image-push-s2i-2" "io.openshift.build.namespace" "myproject"
oc: ---> Running in 464510916c4b
oc: ---> 342e40203bff
oc: Removing intermediate container 464510916c4b
oc: Successfully built 342e40203bff
oc: Pushing image docker.io/testuser/jkube-spring-boot3-openshift-docker-image-push:0.0.1 ...
oc: Push successful
oc: Build jkube-spring-boot3-openshift-docker-image-push-s2i-2 in status Complete
BUILD SUCCESSFUL in 26s
1 actionable task: 1 executed
jkube-spring-boot3-openshift-docker-image-push : $
I think we can provide individual layers in container image as extracted by spring boot, but it won't provide caching benefits on OpenShift 4 due to no shared docker cache.
Describe the bug
Should be tackled after #2393
Requires at least an integration test (e2e) for OpenShift build in Docker mode.
The enhancement (Fix #1674) introduced in version 1.14.0 doesn't have the expected effect if the OpenShift plugins are used with the build strategy Docker. This applies for both plugins Maven and Gradle. If the Spring Boot Generator is used the Spring Boot layered jar is detected, but the following image generation only contains one
COPY STEP
for the complete Spring Boot Application. So the extracted layers are not used.Eclipse JKube version
1.14.0
Component
OpenShift Gradle Plugin
Apache Maven version
3.8.4
Gradle version
other (please specify in additional context)
Steps to reproduce
id 'org.eclipse.jkube.openshift' version '1.14.0'
buildStrategy = 'docker'
includes = ['spring-boot']
clean build
ocBuild ocResource ocApply
(requires a configured OpenShift runtime)STEP 5/9: COPY /deployments /deployments/
Expected behavior
Depending on the Spring Boot layered jar content several
COPY STEP
s for the included layers, like application, dependencies, snapshot-dependencies and spring-boot-loader, should be executed during the image creation.Runtime
OpenShift
Kubernetes API Server version
other (please specify in additional context)
Environment
Windows
Eclipse JKube Logs
Sample Reproducer Project
No response
Additional context
Gradle version 8.3 Kubernetes API Server version v1.23.17+16bcd69