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;
}
Aggregations