Search in sources :

Example 61 with ImageConfiguration

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

the class DockerImageWatcher method restartContainer.

protected void restartContainer(WatchService.ImageWatcher watcher, Collection<HasMetadata> resources) {
    ImageConfiguration imageConfig = watcher.getImageConfiguration();
    String imageName = imageConfig.getName();
    ClusterAccess clusterAccess = getContext().getJKubeServiceHub().getClusterAccess();
    try (KubernetesClient client = clusterAccess.createDefaultClient()) {
        String namespace = clusterAccess.getNamespace();
        String imagePrefix = getImagePrefix(imageName);
        for (HasMetadata entity : resources) {
            updateImageName(client, namespace, entity, imagePrefix, imageName);
        }
    } catch (KubernetesClientException e) {
        KubernetesHelper.handleKubernetesClientException(e, this.log);
    } catch (IllegalStateException e) {
        throw e;
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException) WatchException(org.eclipse.jkube.kit.build.service.docker.watch.WatchException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 62 with ImageConfiguration

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

the class JibBuildServiceBuildIntegrationTest method build_dockerFileMode_shouldThrowException.

@Test
public void build_dockerFileMode_shouldThrowException() {
    // Given
    final ImageConfiguration ic = imageConfiguration.toBuilder().build(imageConfiguration.getBuild().toBuilder().dockerFile("Dockerfile").build()).build();
    // When
    final JKubeServiceException result = assertThrows(JKubeServiceException.class, () -> jibBuildService.build(ic));
    // Then
    assertThat(result).hasMessage("Error when building JIB image").getCause().hasMessage("Dockerfile mode is not supported with JIB build strategy");
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Test(org.junit.Test)

Example 63 with ImageConfiguration

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

the class JibBuildServiceBuildIntegrationTest method build_withLayersAndArtifact_shouldPerformJibBuild.

@Test
public void build_withLayersAndArtifact_shouldPerformJibBuild() throws Exception {
    // Given
    FileUtils.touch(new File(targetDirectory, "final-artifact.jar"));
    final File dlFile = new File(targetDirectory, "to-deployments.txt");
    FileUtils.touch(dlFile);
    final File otherFile = new File(targetDirectory, "to-other.txt");
    FileUtils.touch(otherFile);
    final ImageConfiguration ic = imageConfiguration.toBuilder().build(BuildConfiguration.builder().assembly(AssemblyConfiguration.builder().name("custom").targetDir("/deployments").layer(Assembly.builder().id("deployments-layer").file(AssemblyFile.builder().outputDirectory(new File(".")).source(dlFile).destName(dlFile.getName()).build()).build()).layer(Assembly.builder().id("other-layer").file(AssemblyFile.builder().outputDirectory(new File("other")).source(otherFile).destName(otherFile.getName()).build()).build()).build()).build()).build();
    // When
    jibBuildService.build(ic);
    // Then
    assertDockerFile().hasContent("FROM busybox\n" + "COPY /deployments-layer/deployments /deployments/\n" + "COPY /other-layer/deployments /deployments/\n" + "COPY /jkube-generated-layer-final-artifact/deployments /deployments/\n" + "VOLUME [\"/deployments\"]");
    FileAssertions.assertThat(resolveDockerBuildDirs().resolve("build").toFile()).fileTree().containsExactlyInAnyOrder("Dockerfile", "deployments-layer", "deployments-layer/deployments", "deployments-layer/deployments/to-deployments.txt", "other-layer", "other-layer/deployments", "other-layer/deployments/other", "other-layer/deployments/other/to-other.txt", "jkube-generated-layer-final-artifact", "jkube-generated-layer-final-artifact/deployments", "jkube-generated-layer-final-artifact/deployments/final-artifact.jar", "deployments");
    ArchiveAssertions.assertThat(resolveDockerBuildDirs().resolve("tmp").resolve("docker-build.tar").toFile()).fileTree().hasSize(6).contains("config.json", "manifest.json").haveExactly(4, new Condition<>(s -> s.endsWith(".tar.gz"), "Tar File layers"));
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) FileAssertions(org.eclipse.jkube.kit.common.assertj.FileAssertions) Expectations(mockit.Expectations) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assert.assertThrows(org.junit.Assert.assertThrows) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) Path(java.nio.file.Path) JavaProject(org.eclipse.jkube.kit.common.JavaProject) Before(org.junit.Before) ArchiveAssertions(org.eclipse.jkube.kit.common.assertj.ArchiveAssertions) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) Properties(java.util.Properties) RegistryConfig(org.eclipse.jkube.kit.common.RegistryConfig) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) AbstractFileAssert(org.assertj.core.api.AbstractFileAssert) File(java.io.File) KitLogger(org.eclipse.jkube.kit.common.KitLogger) Rule(org.junit.Rule) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) Assembly(org.eclipse.jkube.kit.common.Assembly) Condition(org.assertj.core.api.Condition) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Collections(java.util.Collections) Mocked(mockit.Mocked) TemporaryFolder(org.junit.rules.TemporaryFolder) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Test(org.junit.Test)

Example 64 with ImageConfiguration

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

the class OpenShiftBuildServiceUtilsTest method checkTarPackage.

@Test
public void checkTarPackage() throws Exception {
    final JKubeBuildTarArchiver tarArchiver = mock(JKubeBuildTarArchiver.class);
    createBuildArchive(jKubeServiceHub, imageConfiguration);
    final ArgumentCaptor<ArchiverCustomizer> customizer = ArgumentCaptor.forClass(ArchiverCustomizer.class);
    verify(jKubeServiceHub.getDockerServiceHub().getArchiveService(), times(1)).createDockerBuildArchive(any(ImageConfiguration.class), any(JKubeConfiguration.class), customizer.capture());
    customizer.getValue().customize(tarArchiver);
    final ArgumentCaptor<String> path = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<File> file = ArgumentCaptor.forClass(File.class);
    verify(tarArchiver, times(1)).includeFile(file.capture(), path.capture());
    assertThat(path.getAllValues()).singleElement().isEqualTo(".s2i/environment");
    assertThat(file.getAllValues()).singleElement().satisfies(f -> assertThat(f).hasContent("FOO=BAR"));
}
Also used : JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) ArchiverCustomizer(org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) JKubeBuildTarArchiver(org.eclipse.jkube.kit.build.api.assembly.JKubeBuildTarArchiver) File(java.io.File) Test(org.junit.Test)

Example 65 with ImageConfiguration

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

the class OpenShiftBuildServiceUtils method createS2IArchiveCustomizer.

private static ArchiverCustomizer createS2IArchiveCustomizer(BuildServiceConfig buildServiceConfig, ImageConfiguration imageConfiguration) throws JKubeServiceException {
    try {
        if (imageConfiguration.getBuildConfiguration() != null && imageConfiguration.getBuildConfiguration().getEnv() != null) {
            String fileName = IoUtil.sanitizeFileName("s2i-env-" + imageConfiguration.getName());
            final File environmentFile = new File(buildServiceConfig.getBuildDirectory(), fileName);
            try (PrintWriter out = new PrintWriter(new FileWriter(environmentFile))) {
                for (Map.Entry<String, String> e : imageConfiguration.getBuildConfiguration().getEnv().entrySet()) {
                    out.println(e.getKey() + "=" + e.getValue());
                }
            }
            return tarArchiver -> {
                tarArchiver.includeFile(environmentFile, ".s2i/environment");
                return tarArchiver;
            };
        } else {
            return null;
        }
    } catch (IOException e) {
        throw new JKubeServiceException("Unable to add environment variables to the S2I build archive", e);
    }
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) BuildStrategyBuilder(io.fabric8.openshift.api.model.BuildStrategyBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) JKubeBuildStrategy(org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) BuildConfigSpec(io.fabric8.openshift.api.model.BuildConfigSpec) StringUtils(org.apache.commons.lang3.StringUtils) ImageName(org.eclipse.jkube.kit.config.image.ImageName) Map(java.util.Map) DOCKER_IMAGE(org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService.DOCKER_IMAGE) DEFAULT_S2I_BUILD_SUFFIX(org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService.DEFAULT_S2I_BUILD_SUFFIX) ArchiverCustomizer(org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer) PrintWriter(java.io.PrintWriter) BuildOutput(io.fabric8.openshift.api.model.BuildOutput) FileWriter(java.io.FileWriter) DEFAULT_BUILD_OUTPUT_KIND(org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService.DEFAULT_BUILD_OUTPUT_KIND) KubernetesHelper(org.eclipse.jkube.kit.common.util.KubernetesHelper) IOException(java.io.IOException) BuildStrategy(io.fabric8.openshift.api.model.BuildStrategy) File(java.io.File) ImageStreamService.resolveImageStreamName(org.eclipse.jkube.kit.config.service.openshift.ImageStreamService.resolveImageStreamName) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) BuildOutputBuilder(io.fabric8.openshift.api.model.BuildOutputBuilder) List(java.util.List) IMAGE_STREAM_TAG(org.eclipse.jkube.kit.config.service.openshift.OpenshiftBuildService.IMAGE_STREAM_TAG) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) IoUtil(org.eclipse.jkube.kit.common.util.IoUtil) Optional(java.util.Optional) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Collections(java.util.Collections) BuildUtil.extractBaseFromDockerfile(org.eclipse.jkube.kit.build.api.helper.BuildUtil.extractBaseFromDockerfile) FileWriter(java.io.FileWriter) IOException(java.io.IOException) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) File(java.io.File) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

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