Search in sources :

Example 81 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class ConfigHelperTest method initImageConfiguration_withSimpleDockerFileModeEnabledAndImageConfigurationWithNoBuild_shouldModifyExistingImageConfiguration.

@Test
public void initImageConfiguration_withSimpleDockerFileModeEnabledAndImageConfigurationWithNoBuild_shouldModifyExistingImageConfiguration() {
    ImageConfiguration dummyImageConfiguration = ImageConfiguration.builder().name("imageconfiguration-no-build:latest").build();
    List<ImageConfiguration> images = new ArrayList<>();
    images.add(dummyImageConfiguration);
    File dockerFile = new File(getClass().getResource("/dummy-javaproject/Dockerfile").getFile());
    when(imageConfigResolver.resolve(dummyImageConfiguration, javaProject)).thenReturn(images);
    when(jKubeConfiguration.getBasedir()).thenReturn(dockerFile.getParentFile());
    when(javaProject.getProperties()).thenReturn(new Properties());
    // When
    List<ImageConfiguration> resolvedImages = ConfigHelper.initImageConfiguration("1.12", new Date(), images, imageConfigResolver, logger, null, configs -> configs, jKubeConfiguration);
    // Then
    assertThat(resolvedImages).isNotNull().hasSize(1).element(0).hasFieldOrPropertyWithValue("name", "imageconfiguration-no-build:latest").hasFieldOrPropertyWithValue("build.dockerFile", dockerFile).hasFieldOrPropertyWithValue("build.ports", Collections.singletonList("8080"));
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 82 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class WatchServiceTest method testCopyFilesToContainer.

@Test
public void testCopyFilesToContainer() throws Exception {
    // Given
    AtomicBoolean fileCopied = new AtomicBoolean(false);
    WatchContext watchContext = WatchContext.builder().watchMode(WatchMode.copy).containerCopyTask(f -> fileCopied.compareAndSet(false, true)).build();
    File fileToCopy = Files.createTempFile("test-changed-files", "tar").toFile();
    WatchService.ImageWatcher imageWatcher = new WatchService.ImageWatcher(imageConfiguration, watchContext, "test-img", "efe1234");
    WatchService watchService = new WatchService(archiveService, buildService, queryService, runService, logger);
    // When
    watchService.copyFilesToContainer(fileToCopy, imageWatcher);
    // Then
    assertTrue(fileCopied.get());
}
Also used : WatchMode(org.eclipse.jkube.kit.config.image.WatchMode) Files(java.nio.file.Files) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) WatchContext(org.eclipse.jkube.kit.build.service.docker.watch.WatchContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) File(java.io.File) WatchImageConfiguration(org.eclipse.jkube.kit.config.image.WatchImageConfiguration) KitLogger(org.eclipse.jkube.kit.common.KitLogger) Mocked(mockit.Mocked) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) File(java.io.File) WatchContext(org.eclipse.jkube.kit.build.service.docker.watch.WatchContext) Test(org.junit.Test)

Example 83 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class WatchServiceTest method testCallPostExec.

@Test
public void testCallPostExec() throws Exception {
    // Given
    AtomicBoolean postExecCommandExecuted = new AtomicBoolean(false);
    WatchContext watchContext = WatchContext.builder().watchMode(WatchMode.copy).containerCommandExecutor(imageWatcher -> {
        postExecCommandExecuted.set(true);
        return "Some Output";
    }).build();
    WatchService.ImageWatcher imageWatcher = new WatchService.ImageWatcher(imageConfiguration, watchContext, "test-img", "efe1234");
    WatchService watchService = new WatchService(archiveService, buildService, queryService, runService, logger);
    // When
    watchService.callPostExec(imageWatcher);
    // Then
    assertTrue(postExecCommandExecuted.get());
}
Also used : WatchMode(org.eclipse.jkube.kit.config.image.WatchMode) Files(java.nio.file.Files) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) WatchContext(org.eclipse.jkube.kit.build.service.docker.watch.WatchContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) File(java.io.File) WatchImageConfiguration(org.eclipse.jkube.kit.config.image.WatchImageConfiguration) KitLogger(org.eclipse.jkube.kit.common.KitLogger) Mocked(mockit.Mocked) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WatchContext(org.eclipse.jkube.kit.build.service.docker.watch.WatchContext) Test(org.junit.Test)

Example 84 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class StartOrderResolver method resolve.

// Check images for volume / link dependencies and return it in the right order.
// Only return images which should be run
// Images references via volumes but with no run configuration are started once to create
// an appropriate container which can be linked into the image
private List<ImageConfiguration> resolve(List<ImageConfiguration> images) {
    List<ImageConfiguration> resolved = new ArrayList<>();
    // First pass: Pick all data images and all without dependencies
    for (ImageConfiguration config : images) {
        List<String> volumesOrLinks = extractDependentImagesFor(config);
        if (volumesOrLinks == null) {
            // A data image only or no dependency. Add it to the list of data image which can be always
            // created first.
            updateProcessedImages(config);
            resolved.add(config);
        } else {
            secondPass.add(config);
        }
    }
    // Next passes: Those with dependencies are checked whether they already have been visited.
    return secondPass.isEmpty() ? resolved : resolveRemaining(resolved);
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) ArrayList(java.util.ArrayList)

Example 85 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class StartOrderResolver method remainingImagesDescription.

private String remainingImagesDescription() {
    StringBuilder ret = new StringBuilder();
    ret.append("Unresolved images:\n");
    for (ImageConfiguration config : secondPass) {
        ret.append("* ").append(config.getAlias()).append(" depends on ").append(String.join(",", config.getDependencies().toArray(new String[0]))).append("\n");
    }
    return ret.toString();
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration)

Aggregations

ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)109 Test (org.junit.Test)75 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)29 RunImageConfiguration (org.eclipse.jkube.kit.config.image.RunImageConfiguration)28 File (java.io.File)26 ArrayList (java.util.ArrayList)19 Expectations (mockit.Expectations)15 GroupArtifactVersion (org.eclipse.jkube.kit.config.resource.GroupArtifactVersion)11 Before (org.junit.Before)11 IOException (java.io.IOException)9 Properties (java.util.Properties)8 KitLogger (org.eclipse.jkube.kit.common.KitLogger)8 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)7 JKubeServiceException (org.eclipse.jkube.kit.config.service.JKubeServiceException)7 WatchImageConfiguration (org.eclipse.jkube.kit.config.image.WatchImageConfiguration)6 ResourceConfig (org.eclipse.jkube.kit.config.resource.ResourceConfig)6 List (java.util.List)5 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)5 VolumeConfig (org.eclipse.jkube.kit.config.resource.VolumeConfig)5 Container (io.fabric8.kubernetes.api.model.Container)4