Search in sources :

Example 1 with BuildRecreateMode

use of org.eclipse.jkube.kit.config.resource.BuildRecreateMode 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);
    });
}
Also used : ResourceUtil(org.eclipse.jkube.kit.common.util.ResourceUtil) ProcessorConfig(org.eclipse.jkube.kit.config.resource.ProcessorConfig) BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) Ansi(org.fusesource.jansi.Ansi) ProfileUtil(org.eclipse.jkube.kit.profile.ProfileUtil) Enumeration(java.util.Enumeration) URL(java.net.URL) DEFAULT_MAX_CONNECTIONS(org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory.DockerAccessContext.DEFAULT_MAX_CONNECTIONS) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Parameter(org.apache.maven.plugins.annotations.Parameter) KitLoggerProvider(org.eclipse.jkube.maven.plugin.mojo.KitLoggerProvider) ImageConfigResolver(org.eclipse.jkube.kit.build.service.docker.config.handler.ImageConfigResolver) Settings(org.apache.maven.settings.Settings) DockerMachineConfiguration(org.eclipse.jkube.kit.build.service.docker.config.DockerMachineConfiguration) MavenProject(org.apache.maven.project.MavenProject) AnsiLogger(org.eclipse.jkube.kit.common.util.AnsiLogger) EnvUtil(org.eclipse.jkube.kit.common.util.EnvUtil) Map(java.util.Map) ConfigHelper(org.eclipse.jkube.kit.build.service.docker.helper.ConfigHelper) Method(java.lang.reflect.Method) WatchMode(org.eclipse.jkube.kit.config.image.WatchMode) BuildRecreateMode(org.eclipse.jkube.kit.config.resource.BuildRecreateMode) RegistryConfig(org.eclipse.jkube.kit.common.RegistryConfig) RuntimeMode(org.eclipse.jkube.kit.config.resource.RuntimeMode) MojoExecution(org.apache.maven.plugin.MojoExecution) ImagePullManager(org.eclipse.jkube.kit.build.service.docker.ImagePullManager) JKubeEnricherContext(org.eclipse.jkube.kit.enricher.api.JKubeEnricherContext) LineNumberReader(java.io.LineNumberReader) ContainerNamingUtil(org.eclipse.jkube.kit.build.service.docker.helper.ContainerNamingUtil) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageUtils(org.apache.maven.shared.utils.logging.MessageUtils) DockerServiceHub(org.eclipse.jkube.kit.build.service.docker.DockerServiceHub) List(java.util.List) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) Optional(java.util.Optional) LogOutputSpecFactory(org.eclipse.jkube.kit.build.service.docker.access.log.LogOutputSpecFactory) ClusterConfiguration(org.eclipse.jkube.kit.config.access.ClusterConfiguration) DockerAccess(org.eclipse.jkube.kit.build.service.docker.access.DockerAccess) DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) Context(org.codehaus.plexus.context.Context) AbstractMojo(org.apache.maven.plugin.AbstractMojo) JKubeBuildStrategy(org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy) ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) MavenProjectHelper(org.apache.maven.project.MavenProjectHelper) GeneratorManager(org.eclipse.jkube.generator.api.GeneratorManager) SecDispatcher(org.sonatype.plexus.components.sec.dispatcher.SecDispatcher) BuildReferenceDateUtil.getBuildTimestamp(org.eclipse.jkube.kit.common.util.BuildReferenceDateUtil.getBuildTimestamp) LogDispatcher(org.eclipse.jkube.kit.build.service.docker.access.log.LogDispatcher) Component(org.apache.maven.plugins.annotations.Component) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) RegistryAuthConfiguration(org.eclipse.jkube.kit.config.image.build.RegistryAuthConfiguration) GeneratorContext(org.eclipse.jkube.generator.api.GeneratorContext) PlatformMode(org.eclipse.jkube.kit.config.resource.PlatformMode) GavLabel(org.eclipse.jkube.kit.build.core.GavLabel) PlexusConstants(org.codehaus.plexus.PlexusConstants) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) AuthConfigFactory(org.eclipse.jkube.kit.build.service.docker.auth.AuthConfigFactory) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) Contextualizable(org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable) ContextException(org.codehaus.plexus.context.ContextException) DEFAULT_LOG_PREFIX(org.eclipse.jkube.maven.plugin.mojo.build.AbstractJKubeMojo.DEFAULT_LOG_PREFIX) JavaProject(org.eclipse.jkube.kit.common.JavaProject) MavenSession(org.apache.maven.execution.MavenSession) DockerAccessFactory(org.eclipse.jkube.kit.build.service.docker.DockerAccessFactory) MavenUtil(org.eclipse.jkube.kit.common.util.MavenUtil) KubernetesClientUtil.updateResourceConfigNamespace(org.eclipse.jkube.kit.config.service.kubernetes.KubernetesClientUtil.updateResourceConfigNamespace) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InputStreamReader(java.io.InputStreamReader) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) BuildReferenceDateUtil.getBuildTimestampFile(org.eclipse.jkube.kit.common.util.BuildReferenceDateUtil.getBuildTimestampFile) KitLogger(org.eclipse.jkube.kit.common.KitLogger) PlexusContainer(org.codehaus.plexus.PlexusContainer) DefaultEnricherManager(org.eclipse.jkube.kit.enricher.api.DefaultEnricherManager) EnricherContext(org.eclipse.jkube.kit.enricher.api.EnricherContext) Collections(java.util.Collections) DefaultEnricherManager(org.eclipse.jkube.kit.enricher.api.DefaultEnricherManager)

Example 2 with BuildRecreateMode

use of org.eclipse.jkube.kit.config.resource.BuildRecreateMode 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);
}
Also used : BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) Quantity(io.fabric8.kubernetes.api.model.Quantity) BuildStrategyBuilder(io.fabric8.openshift.api.model.BuildStrategyBuilder) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NamedTagEventListBuilder(io.fabric8.openshift.api.model.NamedTagEventListBuilder) AssemblyManager(org.eclipse.jkube.kit.build.api.assembly.AssemblyManager) Map(java.util.Map) After(org.junit.After) Mockito.mockConstruction(org.mockito.Mockito.mockConstruction) Build(io.fabric8.openshift.api.model.Build) MockedConstruction(org.mockito.MockedConstruction) ArchiveCompression(org.eclipse.jkube.kit.common.archive.ArchiveCompression) ImmutableMap(com.google.common.collect.ImmutableMap) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) BuildRecreateMode(org.eclipse.jkube.kit.config.resource.BuildRecreateMode) RegistryConfig(org.eclipse.jkube.kit.common.RegistryConfig) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) StandardCharsets(java.nio.charset.StandardCharsets) MockedStatic(org.mockito.MockedStatic) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) OpenshiftHelper(org.eclipse.jkube.kit.common.util.OpenshiftHelper) JKubeBuildStrategy(org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy) ImageStreamStatusBuilder(io.fabric8.openshift.api.model.ImageStreamStatusBuilder) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) Assert.assertThrows(org.junit.Assert.assertThrows) Mockito.mockStatic(org.mockito.Mockito.mockStatic) HashMap(java.util.HashMap) BuildBuilder(io.fabric8.openshift.api.model.BuildBuilder) Serialization(io.fabric8.kubernetes.client.utils.Serialization) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) RETURNS_DEEP_STUBS(org.mockito.Mockito.RETURNS_DEEP_STUBS) JavaProject(org.eclipse.jkube.kit.common.JavaProject) ImageStream(io.fabric8.openshift.api.model.ImageStream) Before(org.junit.Before) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) JKubeBuildTarArchiver(org.eclipse.jkube.kit.build.api.assembly.JKubeBuildTarArchiver) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) WatchEvent(io.fabric8.kubernetes.api.model.WatchEvent) Assert.assertTrue(org.junit.Assert.assertTrue) ArchiveService(org.eclipse.jkube.kit.build.service.docker.ArchiveService) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BuildDirs(org.eclipse.jkube.kit.build.api.assembly.BuildDirs) File(java.io.File) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) KitLogger(org.eclipse.jkube.kit.common.KitLogger) Rule(org.junit.Rule) OpenShiftServer(io.fabric8.openshift.client.server.mock.OpenShiftServer) Assembly(org.eclipse.jkube.kit.common.Assembly) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) OpenshiftBuildConfig(org.eclipse.jkube.kit.config.resource.OpenshiftBuildConfig) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) KitLogger(org.eclipse.jkube.kit.common.KitLogger) ArchiveService(org.eclipse.jkube.kit.build.service.docker.ArchiveService) OpenshiftHelper(org.eclipse.jkube.kit.common.util.OpenshiftHelper) JKubeBuildTarArchiver(org.eclipse.jkube.kit.build.api.assembly.JKubeBuildTarArchiver) ResourceConfig(org.eclipse.jkube.kit.config.resource.ResourceConfig) File(java.io.File) BuildDirs(org.eclipse.jkube.kit.build.api.assembly.BuildDirs) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) Before(org.junit.Before)

Aggregations

File (java.io.File)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Map (java.util.Map)2 Optional (java.util.Optional)2 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)2 JavaProject (org.eclipse.jkube.kit.common.JavaProject)2 KitLogger (org.eclipse.jkube.kit.common.KitLogger)2 RegistryConfig (org.eclipse.jkube.kit.common.RegistryConfig)2 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)2 JKubeBuildStrategy (org.eclipse.jkube.kit.config.image.build.JKubeBuildStrategy)2 BuildRecreateMode (org.eclipse.jkube.kit.config.resource.BuildRecreateMode)2 ResourceConfig (org.eclipse.jkube.kit.config.resource.ResourceConfig)2 BuildServiceConfig (org.eclipse.jkube.kit.config.service.BuildServiceConfig)2 JKubeServiceHub (org.eclipse.jkube.kit.config.service.JKubeServiceHub)2 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 WatchEvent (io.fabric8.kubernetes.api.model.WatchEvent)1