Search in sources :

Example 16 with BuildServiceConfig

use of org.eclipse.jkube.kit.config.service.BuildServiceConfig 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)

Example 17 with BuildServiceConfig

use of org.eclipse.jkube.kit.config.service.BuildServiceConfig in project jkube by eclipse.

the class OpenShiftBuildServiceUtils method createBuildStrategy.

protected static BuildStrategy createBuildStrategy(JKubeServiceHub jKubeServiceHub, ImageConfiguration imageConfig, String openshiftPullSecret) {
    final BuildServiceConfig config = jKubeServiceHub.getBuildServiceConfig();
    final JKubeBuildStrategy osBuildStrategy = config.getJKubeBuildStrategy();
    final BuildConfiguration buildConfig = imageConfig.getBuildConfiguration();
    final Map<String, String> fromExt = buildConfig.getFromExt();
    final String fromName;
    if (buildConfig.isDockerFileMode()) {
        fromName = extractBaseFromDockerfile(jKubeServiceHub.getConfiguration(), buildConfig);
    } else {
        fromName = getMapValueWithDefault(fromExt, JKubeBuildStrategy.SourceStrategy.name, buildConfig.getFrom());
    }
    final String fromKind = getMapValueWithDefault(fromExt, JKubeBuildStrategy.SourceStrategy.kind, DOCKER_IMAGE);
    final String fromNamespace = getMapValueWithDefault(fromExt, JKubeBuildStrategy.SourceStrategy.namespace, IMAGE_STREAM_TAG.equals(fromKind) ? "openshift" : null);
    if (osBuildStrategy == JKubeBuildStrategy.docker) {
        BuildStrategy buildStrategy = new BuildStrategyBuilder().withType("Docker").withNewDockerStrategy().withNewFrom().withKind(fromKind).withName(fromName).withNamespace(StringUtils.isEmpty(fromNamespace) ? null : fromNamespace).endFrom().withEnv(checkForEnv(imageConfig)).withNoCache(checkForNocache(imageConfig)).endDockerStrategy().build();
        if (openshiftPullSecret != null) {
            buildStrategy.getDockerStrategy().setPullSecret(new LocalObjectReferenceBuilder().withName(openshiftPullSecret).build());
        }
        return buildStrategy;
    } else if (osBuildStrategy == JKubeBuildStrategy.s2i) {
        BuildStrategy buildStrategy = new BuildStrategyBuilder().withType("Source").withNewSourceStrategy().withNewFrom().withKind(fromKind).withName(fromName).withNamespace(StringUtils.isEmpty(fromNamespace) ? null : fromNamespace).endFrom().withForcePull(config.isForcePull()).endSourceStrategy().build();
        if (openshiftPullSecret != null) {
            buildStrategy.getSourceStrategy().setPullSecret(new LocalObjectReferenceBuilder().withName(openshiftPullSecret).build());
        }
        return buildStrategy;
    } else {
        throw new IllegalArgumentException("Unsupported BuildStrategy " + osBuildStrategy);
    }
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) BuildStrategyBuilder(io.fabric8.openshift.api.model.BuildStrategyBuilder) JKubeBuildStrategy(org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy) JKubeBuildStrategy(org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy) BuildStrategy(io.fabric8.openshift.api.model.BuildStrategy) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder)

Example 18 with BuildServiceConfig

use of org.eclipse.jkube.kit.config.service.BuildServiceConfig in project jkube by eclipse.

the class OpenshiftBuildServiceIntegrationTest method testSuccessfulBuild.

@Test
public void testSuccessfulBuild() throws Exception {
    final BuildServiceConfig config = withBuildServiceConfig(defaultConfig.build());
    final WebServerEventCollector collector = prepareMockServer(config, true, false, false);
    new OpenshiftBuildService(jKubeServiceHub).build(image);
    // we should find a better way to assert that a certain call has been made
    assertTrue(mockServer.getOpenShiftMockServer().getRequestCount() > 8);
    collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
    assertEquals("{\"apiVersion\":\"build.openshift.io/v1\",\"kind\":\"BuildConfig\",\"metadata\":{\"name\":\"myapp-s2i-suffix2\"},\"spec\":{\"output\":{\"to\":{\"kind\":\"ImageStreamTag\",\"name\":\"myapp:latest\"}},\"source\":{\"type\":\"Binary\"},\"strategy\":{\"sourceStrategy\":{\"forcePull\":false,\"from\":{\"kind\":\"DockerImage\",\"name\":\"myapp\"}},\"type\":\"Source\"}}}", collector.getBodies().get(1));
    collector.assertEventsNotRecorded("patch-build-config");
    assertTrue(containsRequest("imagestreams"));
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) Test(org.junit.Test)

Example 19 with BuildServiceConfig

use of org.eclipse.jkube.kit.config.service.BuildServiceConfig in project jkube by eclipse.

the class OpenshiftBuildServiceIntegrationTest method testSuccessfulBuildSecret.

@Test
public void testSuccessfulBuildSecret() throws Exception {
    final BuildServiceConfig config = withBuildServiceConfig(defaultConfigSecret.build());
    final WebServerEventCollector collector = prepareMockServer(config, true, false, false);
    new OpenshiftBuildService(jKubeServiceHub).build(image);
    // we should find a better way to assert that a certain call has been made
    assertTrue(mockServer.getOpenShiftMockServer().getRequestCount() > 8);
    collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
    collector.assertEventsNotRecorded("patch-build-config");
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) Test(org.junit.Test)

Example 20 with BuildServiceConfig

use of org.eclipse.jkube.kit.config.service.BuildServiceConfig in project jkube by eclipse.

the class OpenshiftBuildServiceIntegrationTest method testDockerBuildWithMultiComponentImageName.

@Test
public void testDockerBuildWithMultiComponentImageName() throws Exception {
    final BuildServiceConfig dockerConfig = withBuildServiceConfig(BuildServiceConfig.builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-docker").jKubeBuildStrategy(JKubeBuildStrategy.docker).resourceConfig(mockedResourceConfig).build());
    image.setName("docker.io/registry/component1/component2/name:tag");
    final WebServerEventCollector collector = prepareMockServer("component1-component2-name", dockerConfig, true, false, false);
    new OpenshiftBuildService(jKubeServiceHub).build(image);
    assertTrue(mockServer.getOpenShiftMockServer().getRequestCount() > 8);
    collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed");
    assertEquals("{\"apiVersion\":\"build.openshift.io/v1\",\"kind\":\"BuildConfig\",\"metadata\":{\"name\":\"component1-component2-name-docker\"},\"spec\":{\"output\":{\"to\":{\"kind\":\"ImageStreamTag\",\"name\":\"component1-component2-name:tag\"}},\"source\":{\"type\":\"Binary\"},\"strategy\":{\"dockerStrategy\":{\"from\":{\"kind\":\"DockerImage\",\"name\":\"myapp\"},\"noCache\":false},\"type\":\"Docker\"}}}", collector.getBodies().get(1));
    collector.assertEventsNotRecorded("patch-build-config");
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) Test(org.junit.Test)

Aggregations

BuildServiceConfig (org.eclipse.jkube.kit.config.service.BuildServiceConfig)24 Test (org.junit.Test)20 ImageName (org.eclipse.jkube.kit.config.image.ImageName)6 BuildOutput (io.fabric8.openshift.api.model.BuildOutput)3 File (java.io.File)3 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)3 JKubeServiceHub (org.eclipse.jkube.kit.config.service.JKubeServiceHub)3 LocalObjectReferenceBuilder (io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder)2 BuildStrategy (io.fabric8.openshift.api.model.BuildStrategy)2 BuildStrategyBuilder (io.fabric8.openshift.api.model.BuildStrategyBuilder)2 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)2 KitLogger (org.eclipse.jkube.kit.common.KitLogger)2 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)2 JKubeBuildStrategy (org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy)2 OpenShiftBuildServiceUtils.createBuildOutput (org.eclipse.jkube.kit.config.service.openshift.OpenShiftBuildServiceUtils.createBuildOutput)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)1 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)1 BuildConfigSpec (io.fabric8.openshift.api.model.BuildConfigSpec)1 BuildOutputBuilder (io.fabric8.openshift.api.model.BuildOutputBuilder)1 FileWriter (java.io.FileWriter)1