Search in sources :

Example 1 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class DockerFileUtilTest method testCreateSimpleDockerfileConfig.

@Test
public void testCreateSimpleDockerfileConfig() throws IOException {
    // Given
    File dockerFile = File.createTempFile("Dockerfile", "-test");
    // When
    ImageConfiguration imageConfiguration1 = DockerFileUtil.createSimpleDockerfileConfig(dockerFile, null);
    ImageConfiguration imageConfiguration2 = DockerFileUtil.createSimpleDockerfileConfig(dockerFile, "someImage:0.0.1");
    // Then
    assertNotNull(imageConfiguration1);
    assertEquals("%g/%a:%l", imageConfiguration1.getName());
    assertEquals(dockerFile.getPath(), imageConfiguration1.getBuild().getDockerFileRaw());
    assertNotNull(imageConfiguration2);
    assertEquals("someImage:0.0.1", imageConfiguration2.getName());
    assertEquals(dockerFile.getPath(), imageConfiguration2.getBuild().getDockerFileRaw());
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) File(java.io.File) Test(org.junit.Test)

Example 2 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class DockerFileUtilTest method testAddSimpleDockerfileConfig.

@Test
public void testAddSimpleDockerfileConfig() throws IOException {
    // Given
    ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("test-image").build();
    File dockerFile = File.createTempFile("Dockerfile", "-test");
    // When
    ImageConfiguration result = DockerFileUtil.addSimpleDockerfileConfig(imageConfiguration, dockerFile);
    // Then
    assertNotNull(result.getBuild());
    assertEquals(dockerFile.getPath(), result.getBuild().getDockerFileRaw());
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) File(java.io.File) Test(org.junit.Test)

Example 3 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class WatchService method createCopyWatchTask.

private Runnable createCopyWatchTask(final ImageWatcher watcher, final JKubeConfiguration jKubeConfiguration) throws IOException {
    final ImageConfiguration imageConfig = watcher.getImageConfiguration();
    final AssemblyFiles files = archiveService.getAssemblyFiles(imageConfig, jKubeConfiguration);
    return () -> {
        List<AssemblyFileEntry> entries = files.getUpdatedEntriesAndRefresh();
        if (!entries.isEmpty()) {
            try {
                log.info("%s: Assembly changed. Copying changed files to container...", imageConfig.getDescription());
                File changedFilesArchive = archiveService.createChangedFilesArchive(entries, files.getAssemblyDirectory(), imageConfig.getName(), jKubeConfiguration);
                copyFilesToContainer(changedFilesArchive, watcher);
                callPostExec(watcher);
            } catch (IOException | WatchException e) {
                log.error("%s: Error when copying files to container %s: %s", imageConfig.getDescription(), watcher.getContainerId(), e.getMessage());
            }
        }
    };
}
Also used : AssemblyFiles(org.eclipse.jkube.kit.build.api.assembly.AssemblyFiles) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) WatchImageConfiguration(org.eclipse.jkube.kit.config.image.WatchImageConfiguration) RunImageConfiguration(org.eclipse.jkube.kit.config.image.RunImageConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 4 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class OpenShiftResourceTaskTest method runTask_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected.

@Test
public void runTask_resolvesGroupInImageNameToNamespaceSetViaConfiguration_whenNoNamespaceDetected() {
    try (MockedStatic<KubernetesHelper> kubernetesHelper = Mockito.mockStatic(KubernetesHelper.class)) {
        // Given
        kubernetesHelper.when(KubernetesHelper::getDefaultNamespace).thenReturn("test-custom-namespace");
        kubernetesHelper.when(() -> KubernetesHelper.getKind(any())).thenReturn("DeploymentConfig");
        kubernetesHelper.when(() -> KubernetesHelper.getName((HasMetadata) any())).thenReturn("test-project");
        ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("%g/%a").build(BuildConfiguration.builder().from("test-base-image:latest").build()).build();
        extension.images = Collections.singletonList(imageConfiguration);
        OpenShiftResourceTask resourceTask = new OpenShiftResourceTask(OpenShiftExtension.class);
        // When
        resourceTask.runTask();
        // Then
        assertThat(resourceTask.resolvedImages).hasSize(1).singleElement().hasFieldOrPropertyWithValue("name", "test-custom-namespace/test-project");
    }
}
Also used : ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) KubernetesHelper(org.eclipse.jkube.kit.common.util.KubernetesHelper) Test(org.junit.Test)

Example 5 with ImageConfiguration

use of org.eclipse.jkube.kit.config.image.ImageConfiguration in project jkube by eclipse.

the class OpenshiftBuildService method checkOrCreatePullSecret.

private boolean checkOrCreatePullSecret(OpenShiftClient client, KubernetesListBuilder builder, String pullSecretName, ImageConfiguration imageConfig) throws Exception {
    BuildConfiguration buildConfig = imageConfig.getBuildConfiguration();
    String fromImage;
    if (buildConfig.isDockerFileMode()) {
        fromImage = extractBaseFromDockerfile(jKubeConfiguration, buildConfig);
    } else {
        fromImage = extractBaseFromConfiguration(buildConfig);
    }
    String pullRegistry = EnvUtil.firstRegistryOf(new ImageName(fromImage).getRegistry(), jKubeConfiguration.getRegistryConfig().getRegistry(), jKubeConfiguration.getRegistryConfig().getRegistry());
    if (pullRegistry != null) {
        RegistryConfig registryConfig = jKubeConfiguration.getRegistryConfig();
        final AuthConfig authConfig = new AuthConfigFactory(log).createAuthConfig(false, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, pullRegistry, registryConfig.getPasswordDecryptionMethod());
        final Secret secret = Optional.ofNullable(pullSecretName).map(psn -> client.secrets().inNamespace(applicableOpenShiftNamespace).withName(psn).get()).orElse(null);
        if (secret != null) {
            log.info("Adding to Secret %s", pullSecretName);
            return updateSecret(client, pullSecretName, secret.getData());
        }
        if (authConfig != null) {
            JsonObject auths = new JsonObject();
            JsonObject auth = new JsonObject();
            JsonObject item = new JsonObject();
            String authString = authConfig.getUsername() + ":" + authConfig.getPassword();
            item.add("auth", new JsonPrimitive(Base64.encodeBase64String(authString.getBytes(StandardCharsets.UTF_8))));
            auth.add(pullRegistry, item);
            auths.add("auths", auth);
            String credentials = Base64.encodeBase64String(auths.toString().getBytes(StandardCharsets.UTF_8));
            Map<String, String> data = new HashMap<>();
            data.put(".dockerconfigjson", credentials);
            log.info("Creating Secret");
            builder.addNewSecretItem().withNewMetadata().withName(pullSecretName).endMetadata().withData(data).withType("kubernetes.io/dockerconfigjson").endSecretItem();
            return true;
        }
    }
    return false;
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) RegistryConfig(org.eclipse.jkube.kit.common.RegistryConfig) Secret(io.fabric8.kubernetes.api.model.Secret) BuildServiceConfig(org.eclipse.jkube.kit.config.service.BuildServiceConfig) Quantity(io.fabric8.kubernetes.api.model.Quantity) JsonObject(com.google.gson.JsonObject) ImageConfiguration(org.eclipse.jkube.kit.config.image.ImageConfiguration) OpenShiftBuildServiceUtils.createBuildArchive(org.eclipse.jkube.kit.config.service.openshift.OpenShiftBuildServiceUtils.createBuildArchive) Watcher(io.fabric8.kubernetes.client.Watcher) BuildConfigSpec(io.fabric8.openshift.api.model.BuildConfigSpec) AuthConfig(org.eclipse.jkube.kit.build.api.auth.AuthConfig) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) Base64(org.apache.commons.codec.binary.Base64) ImageName(org.eclipse.jkube.kit.config.image.ImageName) EnvUtil(org.eclipse.jkube.kit.common.util.EnvUtil) Map(java.util.Map) Status(io.fabric8.kubernetes.api.model.Status) Build(io.fabric8.openshift.api.model.Build) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) AbstractImageBuildService(org.eclipse.jkube.kit.config.service.AbstractImageBuildService) RegistryConfig(org.eclipse.jkube.kit.common.RegistryConfig) RuntimeMode(org.eclipse.jkube.kit.config.resource.RuntimeMode) ResourceFileType(org.eclipse.jkube.kit.common.ResourceFileType) BuildUtil.extractBaseFromConfiguration(org.eclipse.jkube.kit.build.api.helper.BuildUtil.extractBaseFromConfiguration) BuildStrategy(io.fabric8.openshift.api.model.BuildStrategy) StandardCharsets(java.nio.charset.StandardCharsets) BuildConfigSpecBuilder(io.fabric8.openshift.api.model.BuildConfigSpecBuilder) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) JKubeServiceHub(org.eclipse.jkube.kit.config.service.JKubeServiceHub) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) ClusterConfiguration(org.eclipse.jkube.kit.config.access.ClusterConfiguration) JKubeServiceException(org.eclipse.jkube.kit.config.service.JKubeServiceException) OpenShiftBuildServiceUtils.createBuildOutput(org.eclipse.jkube.kit.config.service.openshift.OpenShiftBuildServiceUtils.createBuildOutput) BuildUtil.extractBaseFromDockerfile(org.eclipse.jkube.kit.build.api.helper.BuildUtil.extractBaseFromDockerfile) OpenShiftBuildServiceUtils.computeS2IBuildName(org.eclipse.jkube.kit.config.service.openshift.OpenShiftBuildServiceUtils.computeS2IBuildName) OpenshiftHelper(org.eclipse.jkube.kit.common.util.OpenshiftHelper) ClusterAccess(org.eclipse.jkube.kit.config.access.ClusterAccess) BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) BuildSource(io.fabric8.openshift.api.model.BuildSource) HashMap(java.util.HashMap) Watch(io.fabric8.kubernetes.client.Watch) AtomicReference(java.util.concurrent.atomic.AtomicReference) OpenshiftHelper.isOpenShift(org.eclipse.jkube.kit.common.util.OpenshiftHelper.isOpenShift) WatcherException(io.fabric8.kubernetes.client.WatcherException) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) AuthConfigFactory(org.eclipse.jkube.kit.build.service.docker.auth.AuthConfigFactory) JsonPrimitive(com.google.gson.JsonPrimitive) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) BuildOutput(io.fabric8.openshift.api.model.BuildOutput) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ObjectReference(io.fabric8.kubernetes.api.model.ObjectReference) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) KubernetesHelper(org.eclipse.jkube.kit.common.util.KubernetesHelper) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) File(java.io.File) ImageStreamService.resolveImageStreamName(org.eclipse.jkube.kit.config.service.openshift.ImageStreamService.resolveImageStreamName) TimeUnit(java.util.concurrent.TimeUnit) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) KitLogger(org.eclipse.jkube.kit.common.KitLogger) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ImageStreamBuilder(io.fabric8.openshift.api.model.ImageStreamBuilder) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder) OpenShiftBuildServiceUtils.createBuildStrategy(org.eclipse.jkube.kit.config.service.openshift.OpenShiftBuildServiceUtils.createBuildStrategy) ImageName(org.eclipse.jkube.kit.config.image.ImageName) JsonPrimitive(com.google.gson.JsonPrimitive) HashMap(java.util.HashMap) AuthConfigFactory(org.eclipse.jkube.kit.build.service.docker.auth.AuthConfigFactory) JsonObject(com.google.gson.JsonObject) AuthConfig(org.eclipse.jkube.kit.build.api.auth.AuthConfig)

Aggregations

ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)109 Test (org.junit.Test)75 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)29 RunImageConfiguration (org.eclipse.jkube.kit.config.image.RunImageConfiguration)28 File (java.io.File)26 ArrayList (java.util.ArrayList)19 Expectations (mockit.Expectations)15 GroupArtifactVersion (org.eclipse.jkube.kit.config.resource.GroupArtifactVersion)11 Before (org.junit.Before)11 IOException (java.io.IOException)9 Properties (java.util.Properties)8 KitLogger (org.eclipse.jkube.kit.common.KitLogger)8 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)7 JKubeServiceException (org.eclipse.jkube.kit.config.service.JKubeServiceException)7 WatchImageConfiguration (org.eclipse.jkube.kit.config.image.WatchImageConfiguration)6 ResourceConfig (org.eclipse.jkube.kit.config.resource.ResourceConfig)6 List (java.util.List)5 JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)5 VolumeConfig (org.eclipse.jkube.kit.config.resource.VolumeConfig)5 Container (io.fabric8.kubernetes.api.model.Container)4