Search in sources :

Example 1 with ContainerImageConfig

use of io.quarkus.container.image.deployment.ContainerImageConfig in project quarkus by quarkusio.

the class S2iProcessor method s2iBuildFromNative.

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, S2iBuild.class, NativeBuild.class })
public void s2iBuildFromNative(S2iConfig s2iConfig, ContainerImageConfig containerImageConfig, KubernetesClientBuildItem kubernetesClient, ContainerImageInfoBuildItem containerImage, ArchiveRootBuildItem archiveRoot, OutputTargetBuildItem out, PackageConfig packageConfig, List<GeneratedFileSystemResourceBuildItem> generatedResources, Optional<ContainerImageBuildRequestBuildItem> buildRequest, Optional<ContainerImagePushRequestBuildItem> pushRequest, BuildProducer<ArtifactResultBuildItem> artifactResultProducer, BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder, NativeImageBuildItem nativeImage) {
    if (containerImageConfig.isBuildExplicitlyDisabled()) {
        return;
    }
    if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() && !buildRequest.isPresent() && !pushRequest.isPresent()) {
        return;
    }
    String namespace = Optional.ofNullable(kubernetesClient.getClient().getNamespace()).orElse("default");
    LOG.info("Performing s2i binary build with native image on server: " + kubernetesClient.getClient().getMasterUrl() + " in namespace:" + namespace + ".");
    Optional<GeneratedFileSystemResourceBuildItem> openshiftYml = generatedResources.stream().filter(r -> r.getName().endsWith("kubernetes" + File.separator + "openshift.yml")).findFirst();
    if (openshiftYml.isEmpty()) {
        LOG.warn("No Openshift manifests were generated so no s2i process will be taking place");
        return;
    }
    createContainerImage(kubernetesClient, openshiftYml.get(), s2iConfig, out.getOutputDirectory(), nativeImage.getPath());
    artifactResultProducer.produce(new ArtifactResultBuildItem(null, "native-container", Collections.emptyMap()));
    containerImageBuilder.produce(new ContainerImageBuilderBuildItem(S2I));
}
Also used : Arrays(java.util.Arrays) KubernetesClientBuildItem(io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem) KubernetesEnvBuildItem(io.quarkus.kubernetes.spi.KubernetesEnvBuildItem) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArchiveRootBuildItem(io.quarkus.deployment.builditem.ArchiveRootBuildItem) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Build(io.fabric8.openshift.api.model.Build) KubernetesCommandBuildItem(io.quarkus.kubernetes.spi.KubernetesCommandBuildItem) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) Predicate(java.util.function.Predicate) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Executors(java.util.concurrent.Executors) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) Config(io.fabric8.kubernetes.client.Config) List(java.util.List) Stream(java.util.stream.Stream) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) Logger(org.jboss.logging.Logger) KubernetesClientErrorHandler(io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) CompiledJavaVersionBuildItem(io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) ImageUtil(io.quarkus.container.image.deployment.util.ImageUtil) BuildStep(io.quarkus.deployment.annotations.BuildStep) BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) Serialization(io.dekorate.utils.Serialization) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) InputStreamReader(java.io.InputStreamReader) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Clients(io.dekorate.utils.Clients) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) Closeable(java.io.Closeable) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with ContainerImageConfig

use of io.quarkus.container.image.deployment.ContainerImageConfig in project quarkus by quarkusio.

the class JibProcessor method createContainerBuilderFromLegacyJar.

private JibContainerBuilder createContainerBuilderFromLegacyJar(String baseJvmImage, JibConfig jibConfig, ContainerImageConfig containerImageConfig, JarBuildItem sourceJarBuildItem, OutputTargetBuildItem outputTargetBuildItem, MainClassBuildItem mainClassBuildItem, List<ContainerImageLabelBuildItem> containerImageLabels) {
    try {
        // not ideal since this has been previously zipped - we would like to just reuse it
        Path classesDir = outputTargetBuildItem.getOutputDirectory().resolve("jib");
        ZipUtils.unzip(sourceJarBuildItem.getPath(), classesDir);
        JavaContainerBuilder javaContainerBuilder = JavaContainerBuilder.from(toRegistryImage(ImageReference.parse(baseJvmImage), jibConfig.baseRegistryUsername, jibConfig.baseRegistryPassword)).addResources(classesDir, IS_CLASS_PREDICATE.negate()).addClasses(classesDir, IS_CLASS_PREDICATE);
        // when there is no custom entry point, we just set everything up for a regular java run
        if (!jibConfig.jvmEntrypoint.isPresent()) {
            javaContainerBuilder.addJvmFlags(determineEffectiveJvmArguments(jibConfig, Optional.empty())).setMainClass(mainClassBuildItem.getClassName());
        }
        if (sourceJarBuildItem.getLibraryDir() != null) {
            try (Stream<Path> dependenciesPaths = Files.list(sourceJarBuildItem.getLibraryDir())) {
                javaContainerBuilder.addDependencies(dependenciesPaths.filter(p -> Files.isRegularFile(p) && p.getFileName().toString().endsWith(".jar")).sorted(Comparator.comparing(Path::getFileName)).collect(Collectors.toList()));
            }
        }
        JibContainerBuilder jibContainerBuilder = javaContainerBuilder.toContainerBuilder().setEnvironment(getEnvironmentVariables(jibConfig)).setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels));
        if (jibConfig.useCurrentTimestamp) {
            jibContainerBuilder.setCreationTime(Instant.now());
        }
        if (jibConfig.jvmEntrypoint.isPresent()) {
            jibContainerBuilder.setEntrypoint(jibConfig.jvmEntrypoint.get());
        }
        return jibContainerBuilder;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } catch (InvalidImageReferenceException e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) ImageReference(com.google.cloud.tools.jib.api.ImageReference) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) UpxCompressedBuildItem(io.quarkus.deployment.pkg.builditem.UpxCompressedBuildItem) Port(com.google.cloud.tools.jib.api.buildplan.Port) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) DirectoryStream(java.nio.file.DirectoryStream) Map(java.util.Map) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) ContainerImageLabelBuildItem(io.quarkus.container.spi.ContainerImageLabelBuildItem) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) ZipUtils(io.quarkus.fs.util.ZipUtils) Predicate(java.util.function.Predicate) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) PathsUtil.findMainSourcesRoot(io.quarkus.container.util.PathsUtil.findMainSourcesRoot) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) Set(java.util.Set) FilePermissions(com.google.cloud.tools.jib.api.buildplan.FilePermissions) Instant(java.time.Instant) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) Optional(java.util.Optional) NativeBinaryUtil(io.quarkus.container.image.deployment.util.NativeBinaryUtil) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) AppCDSResultBuildItem(io.quarkus.deployment.pkg.builditem.AppCDSResultBuildItem) AppCDSContainerImageBuildItem(io.quarkus.deployment.pkg.builditem.AppCDSContainerImageBuildItem) ContainerRuntimeUtil(io.quarkus.runtime.util.ContainerRuntimeUtil) DockerDaemonImage(com.google.cloud.tools.jib.api.DockerDaemonImage) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) Version(io.quarkus.builder.Version) Logger(org.jboss.logging.Logger) JibContainer(com.google.cloud.tools.jib.api.JibContainer) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) HashMap(java.util.HashMap) EnablementUtil.pushContainerImageNeeded(io.quarkus.container.image.deployment.util.EnablementUtil.pushContainerImageNeeded) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) CompiledJavaVersionBuildItem(io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BuildStep(io.quarkus.deployment.annotations.BuildStep) Jib(com.google.cloud.tools.jib.api.Jib) CredentialRetrieverFactory(com.google.cloud.tools.jib.frontend.CredentialRetrieverFactory) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) Files(java.nio.file.Files) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) PathsUtil(io.quarkus.container.util.PathsUtil) EnablementUtil.buildContainerImageNeeded(io.quarkus.container.image.deployment.util.EnablementUtil.buildContainerImageNeeded) Comparator(java.util.Comparator) Collections(java.util.Collections) MainClassBuildItem(io.quarkus.deployment.builditem.MainClassBuildItem) JarResultBuildStep(io.quarkus.deployment.pkg.steps.JarResultBuildStep) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) UncheckedIOException(java.io.UncheckedIOException) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 3 with ContainerImageConfig

use of io.quarkus.container.image.deployment.ContainerImageConfig in project quarkus by quarkusio.

the class BuildpackProcessor method runBuildpackBuild.

private String runBuildpackBuild(BuildpackConfig buildpackConfig, ContainerImageInfoBuildItem containerImage, ContainerImageConfig containerImageConfig, Optional<ContainerImagePushRequestBuildItem> pushRequest, OutputTargetBuildItem outputTarget, boolean isNativeBuild) {
    Map<ProjectDirs, Path> dirs = getPaths(outputTarget);
    log.debug("Using target dir of " + dirs.get(ProjectDirs.TARGET));
    log.debug("Using source root of " + dirs.get(ProjectDirs.SOURCE));
    log.debug("Using project root of " + dirs.get(ProjectDirs.ROOT));
    String targetImageName = containerImage.getImage().toString();
    log.debug("Using Destination image of " + targetImageName);
    Map<String, String> envMap = new HashMap<>(buildpackConfig.builderEnv);
    if (!envMap.isEmpty()) {
        log.info("Using builder environment of " + envMap);
    }
    // Let's explicitly disable build and push during the build to avoid inception style builds
    envMap.put(QUARKUS_CONTAINER_IMAGE_BUILD, "false");
    envMap.put(QUARKUS_CONTAINER_IMAGE_PUSH, "false");
    log.info("Initiating Buildpack build");
    Buildpack buildpack = Buildpack.builder().addNewFileContent(dirs.get(ProjectDirs.ROOT).toFile()).withFinalImage(targetImageName).withEnvironment(envMap).withLogLevel(buildpackConfig.logLevel).withPullTimeoutSeconds(buildpackConfig.pullTimeoutSeconds).withLogger(new BuildpackLogger()).accept(BuildpackBuilder.class, b -> {
        if (isNativeBuild) {
            buildpackConfig.nativeBuilderImage.ifPresent(i -> b.withBuilderImage(i));
        } else {
            buildpackConfig.jvmBuilderImage.ifPresent(i -> b.withBuilderImage(i));
        }
        if (buildpackConfig.runImage.isPresent()) {
            log.info("Using Run image of " + buildpackConfig.runImage.get());
            b.withRunImage(buildpackConfig.runImage.get());
        }
        if (buildpackConfig.dockerHost.isPresent()) {
            log.info("Using DockerHost of " + buildpackConfig.dockerHost.get());
            b.withDockerHost(buildpackConfig.dockerHost.get());
        }
    }).build();
    if (buildpack.getExitCode() != 0) {
        throw new IllegalStateException("Buildpack build failed");
    }
    log.info("Buildpack build complete");
    if (containerImageConfig.isPushExplicitlyEnabled() || pushRequest.isPresent()) {
        if (!containerImageConfig.registry.isPresent()) {
            log.info("No container image registry was set, so 'docker.io' will be used");
        }
        AuthConfig authConfig = new AuthConfig();
        authConfig.withRegistryAddress(containerImageConfig.registry.orElse("docker.io"));
        containerImageConfig.username.ifPresent(u -> authConfig.withUsername(u));
        containerImageConfig.password.ifPresent(p -> authConfig.withPassword(p));
        log.info("Pushing image to " + authConfig.getRegistryAddress());
        Stream.concat(Stream.of(containerImage.getImage()), containerImage.getAdditionalImageTags().stream()).forEach(i -> {
            ResultCallback.Adapter<PushResponseItem> callback = buildpack.getDockerClient().pushImageCmd(i).start();
            try {
                callback.awaitCompletion();
                log.info("Push complete");
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        });
    }
    return targetImageName;
}
Also used : Path(java.nio.file.Path) Logger(org.jboss.logging.Logger) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) HashMap(java.util.HashMap) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) BuildpackBuilder(dev.snowdrop.buildpack.BuildpackBuilder) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) Buildpack(dev.snowdrop.buildpack.Buildpack) BuildStep(io.quarkus.deployment.annotations.BuildStep) Map(java.util.Map) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) ContainerImageLabelBuildItem(io.quarkus.container.spi.ContainerImageLabelBuildItem) AuthConfig(com.github.dockerjava.api.model.AuthConfig) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) PathsUtil.findMainSourcesRoot(io.quarkus.container.util.PathsUtil.findMainSourcesRoot) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) List(java.util.List) Stream(java.util.stream.Stream) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) Optional(java.util.Optional) ResultCallback(com.github.dockerjava.api.async.ResultCallback) PushResponseItem(com.github.dockerjava.api.model.PushResponseItem) NativeBinaryUtil(io.quarkus.container.image.deployment.util.NativeBinaryUtil) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) AppCDSResultBuildItem(io.quarkus.deployment.pkg.builditem.AppCDSResultBuildItem) Collections(java.util.Collections) MainClassBuildItem(io.quarkus.deployment.builditem.MainClassBuildItem) ResultCallback(com.github.dockerjava.api.async.ResultCallback) HashMap(java.util.HashMap) PushResponseItem(com.github.dockerjava.api.model.PushResponseItem) AuthConfig(com.github.dockerjava.api.model.AuthConfig) BuildpackBuilder(dev.snowdrop.buildpack.BuildpackBuilder) Buildpack(dev.snowdrop.buildpack.Buildpack)

Example 4 with ContainerImageConfig

use of io.quarkus.container.image.deployment.ContainerImageConfig in project quarkus by quarkusio.

the class S2iProcessor method s2iBuildFromJar.

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, S2iBuild.class }, onlyIfNot = NativeBuild.class)
public void s2iBuildFromJar(S2iConfig s2iConfig, ContainerImageConfig containerImageConfig, KubernetesClientBuildItem kubernetesClient, ContainerImageInfoBuildItem containerImage, ArchiveRootBuildItem archiveRoot, OutputTargetBuildItem out, PackageConfig packageConfig, List<GeneratedFileSystemResourceBuildItem> generatedResources, Optional<ContainerImageBuildRequestBuildItem> buildRequest, Optional<ContainerImagePushRequestBuildItem> pushRequest, BuildProducer<ArtifactResultBuildItem> artifactResultProducer, BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder, // used to ensure that the jar has been built
JarBuildItem jar) {
    if (containerImageConfig.isBuildExplicitlyDisabled()) {
        return;
    }
    if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() && !buildRequest.isPresent() && !pushRequest.isPresent()) {
        return;
    }
    Optional<GeneratedFileSystemResourceBuildItem> openshiftYml = generatedResources.stream().filter(r -> r.getName().endsWith("kubernetes" + File.separator + "openshift.yml")).findFirst();
    if (openshiftYml.isEmpty()) {
        LOG.warn("No Openshift manifests were generated so no s2i process will be taking place");
        return;
    }
    String namespace = Optional.ofNullable(kubernetesClient.getClient().getNamespace()).orElse("default");
    LOG.info("Performing s2i binary build with jar on server: " + kubernetesClient.getClient().getMasterUrl() + " in namespace:" + namespace + ".");
    createContainerImage(kubernetesClient, openshiftYml.get(), s2iConfig, out.getOutputDirectory(), jar.getPath(), out.getOutputDirectory().resolve("lib"));
    artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container", Collections.emptyMap()));
    containerImageBuilder.produce(new ContainerImageBuilderBuildItem(S2I));
}
Also used : Arrays(java.util.Arrays) KubernetesClientBuildItem(io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem) KubernetesEnvBuildItem(io.quarkus.kubernetes.spi.KubernetesEnvBuildItem) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArchiveRootBuildItem(io.quarkus.deployment.builditem.ArchiveRootBuildItem) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Build(io.fabric8.openshift.api.model.Build) KubernetesCommandBuildItem(io.quarkus.kubernetes.spi.KubernetesCommandBuildItem) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) Predicate(java.util.function.Predicate) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Executors(java.util.concurrent.Executors) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) Config(io.fabric8.kubernetes.client.Config) List(java.util.List) Stream(java.util.stream.Stream) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) Logger(org.jboss.logging.Logger) KubernetesClientErrorHandler(io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) CompiledJavaVersionBuildItem(io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) ImageUtil(io.quarkus.container.image.deployment.util.ImageUtil) BuildStep(io.quarkus.deployment.annotations.BuildStep) BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) Serialization(io.dekorate.utils.Serialization) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) InputStreamReader(java.io.InputStreamReader) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Clients(io.dekorate.utils.Clients) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) Closeable(java.io.Closeable) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 5 with ContainerImageConfig

use of io.quarkus.container.image.deployment.ContainerImageConfig in project quarkus by quarkusio.

the class OpenshiftProcessor method openshiftBuildFromJar.

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, OpenshiftBuild.class }, onlyIfNot = NativeBuild.class)
public void openshiftBuildFromJar(OpenshiftConfig openshiftConfig, S2iConfig s2iConfig, ContainerImageConfig containerImageConfig, KubernetesClientBuildItem kubernetesClient, ContainerImageInfoBuildItem containerImage, ArchiveRootBuildItem archiveRoot, OutputTargetBuildItem out, PackageConfig packageConfig, List<GeneratedFileSystemResourceBuildItem> generatedResources, Optional<ContainerImageBuildRequestBuildItem> buildRequest, Optional<ContainerImagePushRequestBuildItem> pushRequest, BuildProducer<ArtifactResultBuildItem> artifactResultProducer, BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder, // used to ensure that the jar has been built
JarBuildItem jar) {
    OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig);
    if (containerImageConfig.isBuildExplicitlyDisabled()) {
        return;
    }
    if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() && !buildRequest.isPresent() && !pushRequest.isPresent()) {
        return;
    }
    Optional<GeneratedFileSystemResourceBuildItem> openshiftYml = generatedResources.stream().filter(r -> r.getName().endsWith("kubernetes" + File.separator + "openshift.yml")).findFirst();
    if (openshiftYml.isEmpty()) {
        LOG.warn("No Openshift manifests were generated so no openshift build process will be taking place");
        return;
    }
    String namespace = Optional.ofNullable(kubernetesClient.getClient().getNamespace()).orElse("default");
    LOG.info("Starting (in-cluster) container image build for jar using: " + config.buildStrategy + " on server: " + kubernetesClient.getClient().getMasterUrl() + " in namespace:" + namespace + ".");
    // The contextRoot is where inside the tarball we will add the jars. A null value means everything will be added under '/' while "target" means everything will be added under '/target'.
    // For docker kind of builds where we use instructions like: `COPY target/*.jar /deployments` it using '/target' is a requirement.
    // For s2i kind of builds where jars are expected directly in the '/' we have to use null.
    String outputDirName = out.getOutputDirectory().getFileName().toString();
    String contextRoot = getContextRoot(outputDirName, packageConfig.isFastJar(), config.buildStrategy);
    if (packageConfig.isFastJar()) {
        createContainerImage(kubernetesClient, openshiftYml.get(), config, contextRoot, jar.getPath().getParent(), jar.getPath().getParent());
    } else if (jar.getLibraryDir() != null) {
        // When using uber-jar the libraryDir is going to be null, potentially causing NPE.
        createContainerImage(kubernetesClient, openshiftYml.get(), config, contextRoot, jar.getPath().getParent(), jar.getPath(), jar.getLibraryDir());
    } else {
        createContainerImage(kubernetesClient, openshiftYml.get(), config, contextRoot, jar.getPath().getParent(), jar.getPath());
    }
    artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container", Collections.emptyMap()));
    containerImageBuilder.produce(new ContainerImageBuilderBuildItem(OPENSHIFT));
}
Also used : Arrays(java.util.Arrays) KubernetesClientBuildItem(io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem) KubernetesEnvBuildItem(io.quarkus.kubernetes.spi.KubernetesEnvBuildItem) Packaging(io.dekorate.utils.Packaging) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArchiveRootBuildItem(io.quarkus.deployment.builditem.ArchiveRootBuildItem) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Build(io.fabric8.openshift.api.model.Build) KubernetesCommandBuildItem(io.quarkus.kubernetes.spi.KubernetesCommandBuildItem) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) OpenshiftUtils.mergeConfig(io.quarkus.container.image.openshift.deployment.OpenshiftUtils.mergeConfig) DEFAULT_FAST_JAR_DIRECTORY_NAME(io.quarkus.deployment.pkg.steps.JarResultBuildStep.DEFAULT_FAST_JAR_DIRECTORY_NAME) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) Predicate(java.util.function.Predicate) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) PathsUtil.findMainSourcesRoot(io.quarkus.container.util.PathsUtil.findMainSourcesRoot) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DecoratorBuildItem(io.quarkus.kubernetes.spi.DecoratorBuildItem) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) Config(io.fabric8.kubernetes.client.Config) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) Logger(org.jboss.logging.Logger) KubernetesClientErrorHandler(io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) CompiledJavaVersionBuildItem(io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) ImageUtil(io.quarkus.container.image.deployment.util.ImageUtil) BuildStep(io.quarkus.deployment.annotations.BuildStep) BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) Files(java.nio.file.Files) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) Serialization(io.dekorate.utils.Serialization) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) InputStreamReader(java.io.InputStreamReader) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Clients(io.dekorate.utils.Clients) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

ContainerImageConfig (io.quarkus.container.image.deployment.ContainerImageConfig)6 AvailableContainerImageExtensionBuildItem (io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem)6 ContainerImageBuildRequestBuildItem (io.quarkus.container.spi.ContainerImageBuildRequestBuildItem)6 ContainerImageBuilderBuildItem (io.quarkus.container.spi.ContainerImageBuilderBuildItem)6 ContainerImageInfoBuildItem (io.quarkus.container.spi.ContainerImageInfoBuildItem)6 ContainerImagePushRequestBuildItem (io.quarkus.container.spi.ContainerImagePushRequestBuildItem)6 IsNormalNotRemoteDev (io.quarkus.deployment.IsNormalNotRemoteDev)6 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)6 BuildStep (io.quarkus.deployment.annotations.BuildStep)6 PackageConfig (io.quarkus.deployment.pkg.PackageConfig)6 ArtifactResultBuildItem (io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem)6 CurateOutcomeBuildItem (io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem)6 JarBuildItem (io.quarkus.deployment.pkg.builditem.JarBuildItem)6 NativeImageBuildItem (io.quarkus.deployment.pkg.builditem.NativeImageBuildItem)6 OutputTargetBuildItem (io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem)6 NativeBuild (io.quarkus.deployment.pkg.steps.NativeBuild)6 CompiledJavaVersionBuildItem (io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem)5 Clients (io.dekorate.utils.Clients)3 Serialization (io.dekorate.utils.Serialization)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3