use of org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy in project jkube by eclipse.
the class AbstractDockerMojo method buildServiceConfigBuilder.
protected BuildServiceConfig.BuildServiceConfigBuilder buildServiceConfigBuilder() {
return BuildServiceConfig.builder().buildRecreateMode(BuildRecreateMode.fromParameter(buildRecreate)).jKubeBuildStrategy(getJKubeBuildStrategy()).forcePull(forcePull).imagePullManager(ImagePullManager.createImagePullManager(imagePullPolicy, autoPull, project.getProperties())).buildDirectory(project.getBuild().getDirectory()).resourceConfig(resources).resourceDir(resourceDir).attacher((classifier, destFile) -> {
if (destFile.exists()) {
projectHelper.attachArtifact(project, "yml", classifier, destFile);
}
}).enricherTask(builder -> {
DefaultEnricherManager enricherManager = new DefaultEnricherManager(getEnricherContext(), useProjectClasspath ? javaProject.getCompileClassPathElements() : Collections.emptyList());
enricherManager.enrich(PlatformMode.kubernetes, builder);
enricherManager.enrich(PlatformMode.openshift, builder);
});
}
use of org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy in project jkube by eclipse.
the class OpenshiftBuildServiceIntegrationTest method init.
@Before
public void init() throws Exception {
final KitLogger logger = new KitLogger.StdoutLogger();
baseDirectory = temporaryFolder.newFolder("openshift-build-service");
target = temporaryFolder.newFolder("openshift-build-service", "target");
final File emptyDockerBuildTar = new File(target, "docker-build.tar");
FileUtils.touch(emptyDockerBuildTar);
baseDir = baseDirectory.getAbsolutePath();
projectName = "myapp";
FileUtils.deleteDirectory(new File(baseDir, projectName));
final File dockerFile = new File(baseDir, "Docker.tar");
FileUtils.touch(dockerFile);
openshiftHelper = mockStatic(OpenshiftHelper.class);
openshiftHelper.when(() -> OpenshiftHelper.isOpenShift(eq(mockServer.getOpenshiftClient()))).thenReturn(true);
jKubeBuildTarArchiver = mockConstruction(JKubeBuildTarArchiver.class, (mock, ctx) -> when(mock.createArchive(any(File.class), any(BuildDirs.class), eq(ArchiveCompression.none))).thenReturn(emptyDockerBuildTar));
mockedResourceConfig = mock(ResourceConfig.class, RETURNS_DEEP_STUBS);
when(mockedResourceConfig.getNamespace()).thenReturn("ns1");
jKubeServiceHub = mock(JKubeServiceHub.class, RETURNS_DEEP_STUBS);
when(jKubeServiceHub.getClusterAccess().createDefaultClient()).thenReturn(mockServer.getOpenshiftClient());
when(jKubeServiceHub.getLog()).thenReturn(logger);
when(jKubeServiceHub.getDockerServiceHub().getArchiveService()).thenReturn(new ArchiveService(AssemblyManager.getInstance(), logger));
when(jKubeServiceHub.getBuildServiceConfig().getBuildDirectory()).thenReturn(target.getAbsolutePath());
when(jKubeServiceHub.getConfiguration()).thenReturn(JKubeConfiguration.builder().outputDirectory(target.getAbsolutePath()).project(JavaProject.builder().baseDirectory(baseDirectory).buildDirectory(target).build()).registryConfig(RegistryConfig.builder().build()).build());
image = ImageConfiguration.builder().name(projectName).build(BuildConfiguration.builder().from(projectName).build()).build();
defaultConfig = BuildServiceConfig.builder().buildDirectory(baseDir).buildRecreateMode(BuildRecreateMode.none).s2iBuildNameSuffix("-s2i-suffix2").resourceConfig(mockedResourceConfig).jKubeBuildStrategy(JKubeBuildStrategy.s2i);
defaultConfigSecret = defaultConfig.build().toBuilder().openshiftPullSecret("pullsecret-fabric8");
dockerImageConfig = defaultConfig.build().toBuilder().buildOutputKind("DockerImage");
dockerImageConfigSecret = defaultConfig.build().toBuilder().openshiftPullSecret("pullsecret-fabric8").openshiftPushSecret("pushsecret-fabric8").buildOutputKind("DockerImage");
Serialization.jsonMapper().disable(SerializationFeature.INDENT_OUTPUT);
}
use of org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy 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.image.build.JKubeBuildStrategy in project jkube by eclipse.
the class FromSelector method getFrom.
public String getFrom() {
RuntimeMode mode = context.getRuntimeMode();
JKubeBuildStrategy strategy = context.getStrategy();
if (mode == RuntimeMode.OPENSHIFT && strategy == JKubeBuildStrategy.s2i) {
return getS2iBuildFrom();
} else {
return getDockerBuildFrom();
}
}
Aggregations