From 91cef562389e0a29f1c6c4ed3c700179c0e26640 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Thu, 16 May 2024 18:30:04 +0200 Subject: [PATCH] refactor: rename JibBuildService to JibImageBuildService Allows for a new JibService generic service class that wraps JibServiceUtil Signed-off-by: Marc Nuri --- ...Service.java => JibImageBuildService.java} | 11 ++++++-- .../resources/META-INF/jkube/build-service | 4 +-- .../JKubeServiceHubBuildServiceTest.java | 6 ++-- .../config/service/JKubeServiceHubTest.java | 4 +-- ...uildServiceGetApplicableRegistryTest.java} | 18 ++++++------ ... JibImageBuildServiceIntegrationTest.java} | 8 +++--- ...est.java => JibImageBuildServiceTest.java} | 28 +++++++++---------- 7 files changed, 42 insertions(+), 37 deletions(-) rename jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/{JibBuildService.java => JibImageBuildService.java} (96%) rename jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/{JibBuildServiceGetApplicableRegistryTest.java => JibImageBuildServiceGetApplicableRegistryTest.java} (89%) rename jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/{JibBuildServiceBuildIntegrationTest.java => JibImageBuildServiceIntegrationTest.java} (97%) rename jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/{JibBuildServiceTest.java => JibImageBuildServiceTest.java} (88%) diff --git a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildService.java b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildService.java similarity index 96% rename from jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildService.java rename to jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildService.java index 1efe34d86e..36d36e305f 100644 --- a/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildService.java +++ b/jkube-kit/config/service/src/main/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildService.java @@ -48,7 +48,12 @@ import static org.eclipse.jkube.kit.service.jib.JibServiceUtil.containerFromImageConfiguration; import static org.eclipse.jkube.kit.service.jib.JibServiceUtil.getBaseImage; -public class JibBuildService extends AbstractImageBuildService { +/** + * AbstractImageBuildService implementation for JIB build strategy. + *

+ * Relies on Jib to perform the build and push operations. + */ +public class JibImageBuildService extends AbstractImageBuildService { private final KitLogger kitLogger; private final JibLogger jibLogger; @@ -56,12 +61,12 @@ public class JibBuildService extends AbstractImageBuildService { private final BuildServiceConfig buildServiceConfig; private final JKubeConfiguration configuration; - public JibBuildService(JKubeServiceHub jKubeServiceHub) { + public JibImageBuildService(JKubeServiceHub jKubeServiceHub) { this(jKubeServiceHub, new JibLogger(Objects.requireNonNull(jKubeServiceHub.getLog(), "Log is required"))); } - public JibBuildService(JKubeServiceHub jKubeServiceHub, JibLogger jibLogger) { + public JibImageBuildService(JKubeServiceHub jKubeServiceHub, JibLogger jibLogger) { super(jKubeServiceHub); this.jibLogger = jibLogger; kitLogger = jKubeServiceHub.getLog(); diff --git a/jkube-kit/config/service/src/main/resources/META-INF/jkube/build-service b/jkube-kit/config/service/src/main/resources/META-INF/jkube/build-service index cb5f809098..61f01de473 100644 --- a/jkube-kit/config/service/src/main/resources/META-INF/jkube/build-service +++ b/jkube-kit/config/service/src/main/resources/META-INF/jkube/build-service @@ -1,4 +1,4 @@ -org.eclipse.jkube.kit.config.service.kubernetes.JibBuildService,100 +org.eclipse.jkube.kit.config.service.kubernetes.JibImageBuildService,100 org.eclipse.jkube.kit.config.service.kubernetes.BuildPackBuildService,110 org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService,200 -org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService,9999 \ No newline at end of file +org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService,9999 diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubBuildServiceTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubBuildServiceTest.java index 9df6805012..d98f2d47ae 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubBuildServiceTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubBuildServiceTest.java @@ -23,7 +23,7 @@ import org.eclipse.jkube.kit.config.resource.RuntimeMode; import org.eclipse.jkube.kit.config.service.kubernetes.BuildPackBuildService; import org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService; -import org.eclipse.jkube.kit.config.service.kubernetes.JibBuildService; +import org.eclipse.jkube.kit.config.service.kubernetes.JibImageBuildService; import org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; @@ -42,12 +42,12 @@ static Stream data() { arguments(RuntimeMode.KUBERNETES, null, DockerBuildService.class), arguments(RuntimeMode.KUBERNETES, JKubeBuildStrategy.docker, DockerBuildService.class), arguments(RuntimeMode.KUBERNETES, JKubeBuildStrategy.s2i, DockerBuildService.class), - arguments(RuntimeMode.KUBERNETES, JKubeBuildStrategy.jib, JibBuildService.class), + arguments(RuntimeMode.KUBERNETES, JKubeBuildStrategy.jib, JibImageBuildService.class), arguments(RuntimeMode.KUBERNETES, JKubeBuildStrategy.buildpacks, BuildPackBuildService.class), arguments(RuntimeMode.OPENSHIFT, null, OpenshiftBuildService.class), arguments(RuntimeMode.OPENSHIFT, JKubeBuildStrategy.docker, OpenshiftBuildService.class), arguments(RuntimeMode.OPENSHIFT, JKubeBuildStrategy.s2i, OpenshiftBuildService.class), - arguments(RuntimeMode.OPENSHIFT, JKubeBuildStrategy.jib, JibBuildService.class)); + arguments(RuntimeMode.OPENSHIFT, JKubeBuildStrategy.jib, JibImageBuildService.class)); } @DisplayName("get build service") diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubTest.java index c061727b71..b1f065524c 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/JKubeServiceHubTest.java @@ -23,7 +23,7 @@ import org.eclipse.jkube.kit.config.resource.ResourceService; import org.eclipse.jkube.kit.config.resource.RuntimeMode; import org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService; -import org.eclipse.jkube.kit.config.service.kubernetes.JibBuildService; +import org.eclipse.jkube.kit.config.service.kubernetes.JibImageBuildService; import org.eclipse.jkube.kit.config.service.kubernetes.KubernetesUndeployService; import org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService; import org.eclipse.jkube.kit.config.service.openshift.OpenshiftUndeployService; @@ -148,7 +148,7 @@ void getJibBuildServiceInKubernetes() { // Then assertThat(buildService) .isNotNull() - .isInstanceOf(JibBuildService.class); + .isInstanceOf(JibImageBuildService.class); } } diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceGetApplicableRegistryTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServiceGetApplicableRegistryTest.java similarity index 89% rename from jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceGetApplicableRegistryTest.java rename to jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServiceGetApplicableRegistryTest.java index a9c33d75b0..25adf988b1 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceGetApplicableRegistryTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServiceGetApplicableRegistryTest.java @@ -20,7 +20,7 @@ import org.junit.jupiter.params.provider.CsvSource; import static org.assertj.core.api.Assertions.assertThat; -class JibBuildServiceGetApplicableRegistryTest { +class JibImageBuildServiceGetApplicableRegistryTest { @ParameterizedTest(name = "pull {0}, when no registry from any source, then pull registry {1}") @CsvSource({ "word:word,", @@ -39,7 +39,7 @@ void pull_whenRegistryNotPresentFromAnySource_thenReturnRegistryFromImageName(St RegistryConfig registryConfig = RegistryConfig.builder().build(); // When - String pullRegistry = JibBuildService.getPullRegistry(imageConfiguration, registryConfig); + String pullRegistry = JibImageBuildService.getPullRegistry(imageConfiguration, registryConfig); // Then assertThat(pullRegistry).isEqualTo(expectedPullRegistry); @@ -59,7 +59,7 @@ void pull_whenRegistryPresentInBothImageNameAndRegistryConfig_thenReturnRegistry RegistryConfig registryConfig = RegistryConfig.builder().registry("quay.io").build(); // When - String pullRegistry = JibBuildService.getPullRegistry(imageConfiguration, registryConfig); + String pullRegistry = JibImageBuildService.getPullRegistry(imageConfiguration, registryConfig); // Then assertThat(pullRegistry).isEqualTo(expectedPullRegistry); @@ -77,7 +77,7 @@ void pull_whenRegistryFromRegistryConfig_thenReturnRegistryFromRegistryConfig(St RegistryConfig registryConfig = RegistryConfig.builder().registry("quay.io").build(); // When - String pullRegistry = JibBuildService.getPullRegistry(imageConfiguration, registryConfig); + String pullRegistry = JibImageBuildService.getPullRegistry(imageConfiguration, registryConfig); // Then assertThat(pullRegistry).isEqualTo(expectedPullRegistry); @@ -101,7 +101,7 @@ void push_whenRegistryNotPresentFromAnySource_thenReturnRegistryFromImageName(St RegistryConfig registryConfig = RegistryConfig.builder().build(); // When - String pullRegistry = JibBuildService.getPushRegistry(imageConfiguration, registryConfig); + String pullRegistry = JibImageBuildService.getPushRegistry(imageConfiguration, registryConfig); // Then assertThat(pullRegistry).isEqualTo(expectedPushRegistry); @@ -121,7 +121,7 @@ void push_whenRegistryInBothImageNameAndRegistryConfig_thenUseRegistryFromImageN RegistryConfig registryConfig = RegistryConfig.builder().registry("quay.io").build(); // When - String pullRegistry = JibBuildService.getPushRegistry(imageConfiguration, registryConfig); + String pullRegistry = JibImageBuildService.getPushRegistry(imageConfiguration, registryConfig); // Then assertThat(pullRegistry).isEqualTo(expectedPushRegistry); @@ -141,7 +141,7 @@ void push_whenRegistryPresentInBothImageNameAndImageConfig_thenUseRegistryFromIm RegistryConfig registryConfig = RegistryConfig.builder().build(); // When - String pullRegistry = JibBuildService.getPushRegistry(imageConfiguration, registryConfig); + String pullRegistry = JibImageBuildService.getPushRegistry(imageConfiguration, registryConfig); // Then assertThat(pullRegistry).isEqualTo(expectedPushRegistry); @@ -159,7 +159,7 @@ void push_whenRegistryFromImageConfig_thenReturnRegistryFromImageConfig(String i RegistryConfig registryConfig = RegistryConfig.builder().build(); // When - String pullRegistry = JibBuildService.getPushRegistry(imageConfiguration, registryConfig); + String pullRegistry = JibImageBuildService.getPushRegistry(imageConfiguration, registryConfig); // Then assertThat(pullRegistry).isEqualTo(expectedPushRegistry); @@ -177,7 +177,7 @@ void push_whenRegistryFromRegistryConfig_thenReturnRegistryFromRegistryConfig(St RegistryConfig registryConfig = RegistryConfig.builder().registry("quay.io").build(); // When - String pullRegistry = JibBuildService.getPushRegistry(imageConfiguration, registryConfig); + String pullRegistry = JibImageBuildService.getPushRegistry(imageConfiguration, registryConfig); // Then assertThat(pullRegistry).isEqualTo(expectedPushRegistry); diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceBuildIntegrationTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServiceIntegrationTest.java similarity index 97% rename from jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceBuildIntegrationTest.java rename to jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServiceIntegrationTest.java index 77bcff78b1..8f3db63bf9 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceBuildIntegrationTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServiceIntegrationTest.java @@ -59,13 +59,13 @@ import static org.mockito.Mockito.verify; @SuppressWarnings({"unused"}) -class JibBuildServiceBuildIntegrationTest { +class JibImageBuildServiceIntegrationTest { private File projectRoot; private Path targetDirectory; private Path dockerOutput; private JKubeServiceHub hub; - private JibBuildService jibBuildService; + private JibImageBuildService jibBuildService; @BeforeEach void setUp(@TempDir Path projectRoot) throws IOException { @@ -88,7 +88,7 @@ void setUp(@TempDir Path projectRoot) throws IOException { .registryConfig(RegistryConfig.builder().settings(Collections.emptyList()).build()) .build()) .build(); - jibBuildService = new JibBuildService(hub); + jibBuildService = new JibImageBuildService(hub); } @Test @@ -196,7 +196,7 @@ void setUp() { .build()) .build(); out = spy(System.out); - jibBuildService = new JibBuildService(hub, new JibLogger(hub.getLog(), out)); + jibBuildService = new JibImageBuildService(hub, new JibLogger(hub.getLog(), out)); } @Test diff --git a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceTest.java b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServiceTest.java similarity index 88% rename from jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceTest.java rename to jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServiceTest.java index fa3b633336..10e84072f3 100644 --- a/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibBuildServiceTest.java +++ b/jkube-kit/config/service/src/test/java/org/eclipse/jkube/kit/config/service/kubernetes/JibImageBuildServiceTest.java @@ -52,7 +52,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -class JibBuildServiceTest { +class JibImageBuildServiceTest { @TempDir Path temporaryFolder; @@ -97,7 +97,7 @@ void close() { @Test void isApplicable_withNoBuildStrategy_shouldReturnFalse() { // When - final boolean result = new JibBuildService(mockedServiceHub).isApplicable(); + final boolean result = new JibImageBuildService(mockedServiceHub).isApplicable(); // Then assertThat(result).isFalse(); } @@ -107,7 +107,7 @@ void isApplicable_withJibBuildStrategy_shouldReturnTrue() { // Given when(mockedServiceHub.getBuildServiceConfig().getJKubeBuildStrategy()).thenReturn(JKubeBuildStrategy.jib); // When - final boolean result = new JibBuildService(mockedServiceHub).isApplicable(); + final boolean result = new JibImageBuildService(mockedServiceHub).isApplicable(); // Then assertThat(result).isTrue(); } @@ -121,7 +121,7 @@ void getRegistryCredentialsForPush() throws IOException { .passwordDecryptionMethod(s -> s) .build(); // When - Credential credential = new JibBuildService(mockedServiceHub) + Credential credential = new JibImageBuildService(mockedServiceHub) .getRegistryCredentials(registryConfig, true, "test.example.org"); // Then assertThat(credential).isNotNull() @@ -138,7 +138,7 @@ void getRegistryCredentialsForPull() throws IOException { .passwordDecryptionMethod(s -> s) .build(); // When - Credential credential = new JibBuildService(mockedServiceHub) + Credential credential = new JibImageBuildService(mockedServiceHub) .getRegistryCredentials(registryConfig, false, "test.example.org"); // Then assertThat(credential).isNotNull() @@ -151,7 +151,7 @@ void getBuildTarArchive() throws IOException { // Given File projectBaseDir = Files.createDirectory(temporaryFolder.resolve("test")).toFile(); // When - File tarArchive = JibBuildService.getBuildTarArchive(imageConfiguration, createJKubeConfiguration(projectBaseDir)); + File tarArchive = JibImageBuildService.getBuildTarArchive(imageConfiguration, createJKubeConfiguration(projectBaseDir)); // Then assertThat(tarArchive).isNotNull() .isEqualTo(projectBaseDir.toPath().resolve("target").resolve("test").resolve("testimage").resolve("0.0.1") @@ -164,7 +164,7 @@ void getAssemblyTarArchive() throws IOException { // Given File projectBaseDir = Files.createDirectory(temporaryFolder.resolve("test")).toFile(); // When - File tarArchive = JibBuildService.getAssemblyTarArchive(imageConfiguration, createJKubeConfiguration(projectBaseDir), logger); + File tarArchive = JibImageBuildService.getAssemblyTarArchive(imageConfiguration, createJKubeConfiguration(projectBaseDir), logger); // Then assertThat(tarArchive).isNotNull() .isEqualTo(projectBaseDir.toPath().resolve("target").resolve("test").resolve("testimage").resolve("0.0.1") @@ -174,7 +174,7 @@ void getAssemblyTarArchive() throws IOException { @Test void pushWithNoConfigurations() throws Exception { // When - new JibBuildService(mockedServiceHub).push(Collections.emptyList(), 1, null, false); + new JibImageBuildService(mockedServiceHub).push(Collections.emptyList(), 1, null, false); // Then jibServiceUtilMockedStatic.verify(() -> JibServiceUtil.jibPush(any(), any(), any(), any()), times(0)); } @@ -187,7 +187,7 @@ void pushWithConfiguration() throws Exception { .passwordDecryptionMethod(s -> s) .build(); // When - new JibBuildService(mockedServiceHub).push(Collections.singletonList(imageConfiguration), 1, registryConfig, false); + new JibImageBuildService(mockedServiceHub).push(Collections.singletonList(imageConfiguration), 1, registryConfig, false); // Then jibServiceUtilMockedStatic.verify(() -> JibServiceUtil.jibPush(eq(imageConfiguration), eq(Credential.from("testuserpush", "testpass")), any(), any()), times(1)); } @@ -203,7 +203,7 @@ void push_withImageBuildConfigurationSkipTrue_shouldNotPushImage() throws JKubeS .build()) .build(); // When - new JibBuildService(mockedServiceHub).push(Collections.singletonList(imageConfiguration), 1, registryConfig, false); + new JibImageBuildService(mockedServiceHub).push(Collections.singletonList(imageConfiguration), 1, registryConfig, false); // Then jibServiceUtilMockedStatic.verify(() -> JibServiceUtil.jibPush(any(), any(), any(), any()), times(0)); } @@ -215,7 +215,7 @@ void build_withImageMissingBuildConfiguration_shouldNotBuildImage() throws JKube .name("test/foo:latest") .build(); // When - new JibBuildService(mockedServiceHub).build(imageConfiguration); + new JibImageBuildService(mockedServiceHub).build(imageConfiguration); // Then jibServiceUtilMockedStatic.verify(() -> JibServiceUtil.buildContainer(any(), any(), any()), times(0)); } @@ -231,7 +231,7 @@ void build_withImageBuildConfigurationSkipTrue_shouldNotBuildImage() throws JKub .build()) .build(); // When - new JibBuildService(mockedServiceHub).build(imageConfiguration); + new JibImageBuildService(mockedServiceHub).build(imageConfiguration); // Then jibServiceUtilMockedStatic.verify(() -> JibServiceUtil.buildContainer(any(), any(), any()), times(0)); } @@ -243,7 +243,7 @@ void build_shouldCallPluginServiceAddFiles() throws JKubeServiceException { .name("test/foo:latest") .build(); // When - new JibBuildService(mockedServiceHub).build(imageConfiguration); + new JibImageBuildService(mockedServiceHub).build(imageConfiguration); // Then verify(mockedServiceHub.getPluginManager().resolvePluginService(), times(1)).addExtraFiles(); } @@ -256,7 +256,7 @@ void build_withRegistryConfig_shouldPrependRegistryToImageName() throws JKubeSer when(mockedServiceHub.getConfiguration().getProject()) .thenReturn(JavaProject.builder().baseDirectory(temporaryFolder.toFile()).build()); // When - new JibBuildService(mockedServiceHub).build(imageConfiguration); + new JibImageBuildService(mockedServiceHub).build(imageConfiguration); // Then jibServiceUtilMockedStatic.verify(() -> JibServiceUtil .containerFromImageConfiguration(argThat(ic -> ic.getName().equals("quay.io/test/testimage:0.0.1")), any(), any()), times(1));