Search in sources :

Example 6 with JKubeConfiguration

use of org.eclipse.jkube.kit.common.JKubeConfiguration in project jkube by eclipse.

the class AssemblyManagerCreateDockerTarArchiveTest method withDockerfileInBaseDirectoryAndAssemblyFile.

@Test
public void withDockerfileInBaseDirectoryAndAssemblyFile() throws IOException {
    // Given
    final File dockerFile = new File(baseDirectory, "Dockerfile");
    writeLineToFile(dockerFile, "FROM busybox");
    final File assemblyFile = temporaryFolder.newFile("extra-file-1.txt");
    writeLineToFile(assemblyFile, "HELLO");
    AssemblyConfiguration assemblyConfig = AssemblyConfiguration.builder().inline(Assembly.builder().file(AssemblyFile.builder().source(assemblyFile).outputDirectory(new File(".")).build()).build()).build();
    final JKubeConfiguration configuration = createJKubeConfiguration();
    final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder().dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).assembly(assemblyConfig).build();
    // When
    final File dockerArchiveFile = assemblyManager.createDockerTarArchive("dockerfile-and-assembly-file", configuration, jKubeBuildConfiguration, prefixedLogger, null);
    // Then
    assertTargetHasDockerDirectories("dockerfile-and-assembly-file");
    ArchiveAssertions.assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSameContentAsDirectory(getExpectedDirectory("with-dockerfile-in-base-directory-and-assembly-file"));
    assertDockerFile("dockerfile-and-assembly-file").hasContent("FROM busybox\n");
    assertBuildDirectoryFileTree("dockerfile-and-assembly-file").containsExactlyInAnyOrder("Dockerfile", "maven", "maven/Dockerfile", "maven/test-0.1.0.jar", "maven/extra-file-1.txt", "maven/target", "maven/target/test-0.1.0.jar");
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) AssemblyConfiguration(org.eclipse.jkube.kit.common.AssemblyConfiguration) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) AssemblyFile(org.eclipse.jkube.kit.common.AssemblyFile) File(java.io.File) Test(org.junit.Test)

Example 7 with JKubeConfiguration

use of org.eclipse.jkube.kit.common.JKubeConfiguration 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)

Example 8 with JKubeConfiguration

use of org.eclipse.jkube.kit.common.JKubeConfiguration in project jkube by eclipse.

the class HelmServiceIT method setUp.

@Before
public void setUp() throws Exception {
    mapper = new ObjectMapper(new YAMLFactory());
    helmService = new HelmService(new JKubeConfiguration(), new KitLogger.SilentLogger());
    helmOutputDir = temporaryFolder.newFolder("helm-output");
    helmConfig = new HelmConfig();
    helmConfig.setSourceDir(new File(HelmServiceIT.class.getResource("/it/sources").toURI()).getAbsolutePath());
    helmConfig.setOutputDir(helmOutputDir.getAbsolutePath());
    helmConfig.setTarballOutputDir(helmOutputDir.getAbsolutePath());
    helmConfig.setChartExtension("tar");
}
Also used : JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 9 with JKubeConfiguration

use of org.eclipse.jkube.kit.common.JKubeConfiguration in project jkube by eclipse.

the class AssemblyConfigurationSourceTest method testOutputDirHasImage.

@Test
public void testOutputDirHasImage() {
    String image = "image";
    JKubeConfiguration context = buildBuildContext("src/docker", "output/docker");
    AssemblyConfigurationSource source = new AssemblyConfigurationSource(context, new BuildDirs(image, context), assemblyConfig);
    assertTrue(containsDir(image, source.getOutputDirectory()));
    assertTrue(containsDir(image, source.getWorkingDirectory()));
    assertTrue(containsDir(image, source.getTemporaryRootDirectory()));
}
Also used : JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) Test(org.junit.Test)

Example 10 with JKubeConfiguration

use of org.eclipse.jkube.kit.common.JKubeConfiguration in project jkube by eclipse.

the class AssemblyConfigurationSourceTest method testReactorProjects.

@Test
public void testReactorProjects() {
    JavaProject project1 = JavaProject.builder().build();
    JavaProject project2 = JavaProject.builder().build();
    JKubeConfiguration buildContext = JKubeConfiguration.builder().sourceDirectory("/src/docker").outputDirectory("/output/docker").reactorProjects(Arrays.asList(project1, project2)).build();
    AssemblyConfigurationSource source = new AssemblyConfigurationSource(buildContext, null, null);
    assertEquals(2, source.getReactorProjects().size());
}
Also used : JavaProject(org.eclipse.jkube.kit.common.JavaProject) JKubeConfiguration(org.eclipse.jkube.kit.common.JKubeConfiguration) Test(org.junit.Test)

Aggregations

JKubeConfiguration (org.eclipse.jkube.kit.common.JKubeConfiguration)23 File (java.io.File)15 Test (org.junit.Test)13 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)12 AssemblyFile (org.eclipse.jkube.kit.common.AssemblyFile)11 KitLogger (org.eclipse.jkube.kit.common.KitLogger)6 IOException (java.io.IOException)5 List (java.util.List)5 ArrayList (java.util.ArrayList)4 AssemblyConfiguration (org.eclipse.jkube.kit.common.AssemblyConfiguration)4 AssemblyFileEntry (org.eclipse.jkube.kit.common.AssemblyFileEntry)4 JavaProject (org.eclipse.jkube.kit.common.JavaProject)4 ImageConfiguration (org.eclipse.jkube.kit.config.image.ImageConfiguration)4 Map (java.util.Map)3 Optional (java.util.Optional)3 Properties (java.util.Properties)3 Assembly (org.eclipse.jkube.kit.common.Assembly)3 Before (org.junit.Before)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2