Search in sources :

Example 1 with Port

use of com.google.cloud.tools.jib.api.Port in project fabric8-maven-plugin by fabric8io.

the class JibServiceUtil method containerFromImageConfiguration.

static JibContainerBuilder containerFromImageConfiguration(ImageConfiguration imageConfiguration) throws InvalidImageReferenceException {
    final Optional<BuildImageConfiguration> bic = Optional.ofNullable(Objects.requireNonNull(imageConfiguration).getBuildConfiguration());
    final JibContainerBuilder containerBuilder = Jib.from(getBaseImage(imageConfiguration)).setFormat(ImageFormat.OCI);
    bic.map(BuildImageConfiguration::getEntryPoint).map(Arguments::asStrings).ifPresent(containerBuilder::setEntrypoint);
    bic.map(BuildImageConfiguration::getEnv).ifPresent(containerBuilder::setEnvironment);
    bic.map(BuildImageConfiguration::getPorts).map(List::stream).map(s -> s.map(Integer::parseInt).map(Port::tcp)).map(s -> s.collect(Collectors.toSet())).ifPresent(containerBuilder::setExposedPorts);
    bic.map(BuildImageConfiguration::getLabels).map(Map::entrySet).ifPresent(labels -> labels.forEach(l -> containerBuilder.addLabel(l.getKey(), l.getValue())));
    bic.map(BuildImageConfiguration::getCmd).map(Arguments::asStrings).ifPresent(containerBuilder::setProgramArguments);
    bic.map(BuildImageConfiguration::getUser).ifPresent(containerBuilder::setUser);
    bic.map(BuildImageConfiguration::getVolumes).map(List::stream).map(s -> s.map(AbsoluteUnixPath::get)).map(s -> s.collect(Collectors.toSet())).ifPresent(containerBuilder::setVolumes);
    bic.map(BuildImageConfiguration::getWorkdir).filter(((Predicate<String>) String::isEmpty).negate()).map(AbsoluteUnixPath::get).ifPresent(containerBuilder::setWorkingDirectory);
    return containerBuilder;
}
Also used : ImageReference(com.google.cloud.tools.jib.api.ImageReference) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ImageName(io.fabric8.maven.docker.util.ImageName) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) Logger(io.fabric8.maven.docker.util.Logger) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) ProgressEvent(com.google.cloud.tools.jib.event.events.ProgressEvent) Credential(com.google.cloud.tools.jib.api.Credential) HashSet(java.util.HashSet) Jib(com.google.cloud.tools.jib.api.Jib) TimerEventHandler(com.google.cloud.tools.jib.plugins.common.TimerEventHandler) CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) MavenProject(org.apache.maven.project.MavenProject) Map(java.util.Map) Port(com.google.cloud.tools.jib.api.Port) AbsoluteUnixPath(com.google.cloud.tools.jib.api.AbsoluteUnixPath) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) ExecutorService(java.util.concurrent.ExecutorService) Ansi.ansi(org.fusesource.jansi.Ansi.ansi) StringUtils(org.codehaus.plexus.util.StringUtils) Predicate(java.util.function.Predicate) Set(java.util.Set) TarImage(com.google.cloud.tools.jib.api.TarImage) IOException(java.io.IOException) TimerEvent(com.google.cloud.tools.jib.event.events.TimerEvent) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) RegistryException(com.google.cloud.tools.jib.api.RegistryException) ProgressEventHandler(com.google.cloud.tools.jib.event.progress.ProgressEventHandler) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) File(java.io.File) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) LogEvent(com.google.cloud.tools.jib.api.LogEvent) List(java.util.List) Containerizer(com.google.cloud.tools.jib.api.Containerizer) ImageFormat(com.google.cloud.tools.jib.api.ImageFormat) RegistryService(io.fabric8.maven.docker.service.RegistryService) Paths(java.nio.file.Paths) EnvUtil(io.fabric8.maven.docker.util.EnvUtil) ProgressDisplayGenerator(com.google.cloud.tools.jib.plugins.common.logging.ProgressDisplayGenerator) Arguments(io.fabric8.maven.docker.config.Arguments) Optional(java.util.Optional) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Aggregations

AbsoluteUnixPath (com.google.cloud.tools.jib.api.AbsoluteUnixPath)1 CacheDirectoryCreationException (com.google.cloud.tools.jib.api.CacheDirectoryCreationException)1 Containerizer (com.google.cloud.tools.jib.api.Containerizer)1 Credential (com.google.cloud.tools.jib.api.Credential)1 ImageFormat (com.google.cloud.tools.jib.api.ImageFormat)1 ImageReference (com.google.cloud.tools.jib.api.ImageReference)1 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)1 Jib (com.google.cloud.tools.jib.api.Jib)1 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)1 LogEvent (com.google.cloud.tools.jib.api.LogEvent)1 Port (com.google.cloud.tools.jib.api.Port)1 RegistryException (com.google.cloud.tools.jib.api.RegistryException)1 RegistryImage (com.google.cloud.tools.jib.api.RegistryImage)1 TarImage (com.google.cloud.tools.jib.api.TarImage)1 ProgressEvent (com.google.cloud.tools.jib.event.events.ProgressEvent)1 TimerEvent (com.google.cloud.tools.jib.event.events.TimerEvent)1 ProgressEventHandler (com.google.cloud.tools.jib.event.progress.ProgressEventHandler)1 TimerEventHandler (com.google.cloud.tools.jib.plugins.common.TimerEventHandler)1 ProgressDisplayGenerator (com.google.cloud.tools.jib.plugins.common.logging.ProgressDisplayGenerator)1 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)1