From 936abb9be3d6d1c592faae10562b55ef8d8b052c Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Thu, 23 May 2024 10:00:33 +0200 Subject: [PATCH] feat(jib): support building images from scratch Signed-off-by: Marc Nuri --- .../jkube/kit/service/jib/JibServiceUtil.java | 15 +++++++++++---- .../jkube/kit/service/jib/JibServiceTest.java | 9 --------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/jkube-kit/build/service/jib/src/main/java/org/eclipse/jkube/kit/service/jib/JibServiceUtil.java b/jkube-kit/build/service/jib/src/main/java/org/eclipse/jkube/kit/service/jib/JibServiceUtil.java index b7f49445ca..6d63b2803f 100644 --- a/jkube-kit/build/service/jib/src/main/java/org/eclipse/jkube/kit/service/jib/JibServiceUtil.java +++ b/jkube-kit/build/service/jib/src/main/java/org/eclipse/jkube/kit/service/jib/JibServiceUtil.java @@ -22,6 +22,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import com.google.cloud.tools.jib.api.ImageReference; import org.eclipse.jkube.kit.build.api.assembly.BuildDirs; import org.eclipse.jkube.kit.common.Assembly; import org.eclipse.jkube.kit.common.AssemblyFileEntry; @@ -54,10 +55,16 @@ private JibServiceUtil() { private static final String BUSYBOX = "busybox:latest"; public static JibContainerBuilder containerFromImageConfiguration( - ImageConfiguration imageConfiguration, String pullRegistry, Credential pullRegistryCredential) { - final JibContainerBuilder containerBuilder = Jib - .from(toRegistryImage(getBaseImage(imageConfiguration, pullRegistry), pullRegistryCredential)) - .setFormat(ImageFormat.Docker); + ImageConfiguration imageConfiguration, String pullRegistry, Credential pullRegistryCredential + ) { + final String baseImage = getBaseImage(imageConfiguration, pullRegistry); + final JibContainerBuilder containerBuilder; + if (baseImage.equals(ImageReference.scratch().toString() + ":latest")) { + containerBuilder = Jib.fromScratch(); + } else { + containerBuilder = Jib.from(toRegistryImage(baseImage, pullRegistryCredential)); + } + containerBuilder.setFormat(ImageFormat.Docker); if (imageConfiguration.getBuildConfiguration() != null) { final BuildConfiguration bic = imageConfiguration.getBuildConfiguration(); Optional.ofNullable(bic.getEntryPoint()) diff --git a/jkube-kit/build/service/jib/src/test/java/org/eclipse/jkube/kit/service/jib/JibServiceTest.java b/jkube-kit/build/service/jib/src/test/java/org/eclipse/jkube/kit/service/jib/JibServiceTest.java index 736660128a..eaf1a708e8 100644 --- a/jkube-kit/build/service/jib/src/test/java/org/eclipse/jkube/kit/service/jib/JibServiceTest.java +++ b/jkube-kit/build/service/jib/src/test/java/org/eclipse/jkube/kit/service/jib/JibServiceTest.java @@ -114,15 +114,6 @@ void prependsRegistryWhenNotConfiguredInName() throws Exception { @DisplayName("build") class Build { - @BeforeEach - void setUp() { - imageConfiguration = imageConfiguration.toBuilder() - .build(imageConfiguration.getBuild().toBuilder() - .from("gcr.io/distroless/base@sha256:8267a5d9fa15a538227a8850e81cf6c548a78de73458e99a67e8799bbffb1ba0") - .build()) - .build(); - } - @Test void build() throws Exception { try (JibService jibService = new JibService(jibLogger, testAuthConfigFactory, configuration, imageConfiguration)) {