Skip to content

Commit

Permalink
refactor: rename JibBuildService to JibImageBuildService
Browse files Browse the repository at this point in the history
Allows for a new JibService generic service class that wraps JibServiceUtil

Signed-off-by: Marc Nuri <marc@marcnuri.com>
  • Loading branch information
manusa committed May 16, 2024
1 parent f93b33b commit 3e81a19
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,25 @@
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.
* <p>
* Relies on Jib to perform the build and push operations.
*/
public class JibImageBuildService extends AbstractImageBuildService {

private final KitLogger kitLogger;
private final JibLogger jibLogger;
private final AuthConfigFactory authConfigFactory;
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
org.eclipse.jkube.kit.config.service.kubernetes.DockerBuildService,9999
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,12 +42,12 @@ static Stream<Arguments> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,7 +148,7 @@ void getJibBuildServiceInKubernetes() {
// Then
assertThat(buildService)
.isNotNull()
.isInstanceOf(JibBuildService.class);
.isInstanceOf(JibImageBuildService.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,",
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class JibBuildServiceTest {
class JibImageBuildServiceTest {

@TempDir
Path temporaryFolder;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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();
}
Expand All @@ -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));
Expand Down

0 comments on commit 3e81a19

Please sign in to comment.