Search in sources :

Example 1 with ArchiverCustomizer

use of org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer 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 2 with ArchiverCustomizer

use of org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer 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

File (java.io.File)2 ArchiverCustomizer (org.eclipse.jkube.kit.build.api.assembly.ArchiverCustomizer)2 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)1 LocalObjectReferenceBuilder (io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder)1 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)1 BuildConfigSpec (io.fabric8.openshift.api.model.BuildConfigSpec)1 BuildOutput (io.fabric8.openshift.api.model.BuildOutput)1 BuildOutputBuilder (io.fabric8.openshift.api.model.BuildOutputBuilder)1 BuildStrategy (io.fabric8.openshift.api.model.BuildStrategy)1 BuildStrategyBuilder (io.fabric8.openshift.api.model.BuildStrategyBuilder)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 StringUtils (org.apache.commons.lang3.StringUtils)1 JKubeBuildTarArchiver (org.eclipse.jkube.kit.build.api.assembly.JKubeBuildTarArchiver)1