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);
}
}
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);
}
}
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"));
}
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");
}
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");
}
Aggregations