From d3064a2a489ab5059bbcb0c6df88d5c35fe8fb39 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Thu, 30 Mar 2023 15:37:30 +0200 Subject: [PATCH] fix: Removed unsupported Docker compose utilities inherited from Docker Maven Plugin (DMP) These utilities required a class DeepCopy that contained code dealing with Bean deserialization that was a potential security threat Signed-off-by: Marc Nuri --- CHANGELOG.md | 1 + .../config/handler/compose/ComposeUtils.java | 75 --- .../compose/DockerComposeConfigHandler.java | 215 -------- .../compose/DockerComposeConfiguration.java | 40 -- .../compose/DockerComposeServiceWrapper.java | 471 ------------------ .../build/service/docker/helper/DeepCopy.java | 57 --- .../resources/META-INF/plexus/components.xml | 11 - .../resources/META-INF/plexus/components.xml | 11 - 8 files changed, 1 insertion(+), 880 deletions(-) delete mode 100644 jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/ComposeUtils.java delete mode 100644 jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeConfigHandler.java delete mode 100644 jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeConfiguration.java delete mode 100644 jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeServiceWrapper.java delete mode 100644 jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/helper/DeepCopy.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bf51cc213..0b8190ecab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ Usage: * Fix #2108: Use BouncyCastle JDK 1.8 compatible jars * Fix #2104: Bump kubernetes-client to 6.5.1 (#2079) * Fix #2101: Resolve dynamic transitive properties when creating Dockerfile +* Fix #2113: Removed unsupported Docker compose utilities inherited from Docker Maven Plugin (DMP) ### 1.11.0 (2023-02-16) * Fix #1316: Add support for adding InitContainers via plugin configuration diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/ComposeUtils.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/ComposeUtils.java deleted file mode 100644 index c76d765229..0000000000 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/ComposeUtils.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2019 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at: - * - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.jkube.kit.build.service.docker.config.handler.compose; - -import org.eclipse.jkube.kit.build.service.docker.helper.DockerPathUtil; - -import java.io.File; -import java.io.IOException; - -/** - * Path-resolution methods - */ -class ComposeUtils { - - private ComposeUtils() { } - - /** - * Resolves a docker-compose file against the supplied base directory. The returned {@code File} is guaranteed to - * be {@link File#isAbsolute() absolute}. - *

- * If {@code composeFile} is {@link File#isAbsolute() absolute}, then it is returned unmodified. Otherwise, the - * {@code composeFile} is returned as an absolute {@code File} using the {@link #resolveAbsolutely(String, - * String) resolved} {@code baseDir} as its parent. - *

- * - * @param baseDir the base directory containing the docker-compose file (ignored if {@code composeFile} is absolute) - * @param composeFile the path of the docker-compose file, may be absolute - * @param projectAbsolutePath the {@code String} used to resolve the {@code baseDir} - * @return an absolute {@code File} reference to the {@code composeFile} - */ - static File resolveComposeFileAbsolutely(String baseDir, String composeFile, String projectAbsolutePath) { - File yamlFile = new File(composeFile); - if (yamlFile.isAbsolute()) { - return yamlFile; - } - - File toCanonicalize = new File(resolveAbsolutely(baseDir, projectAbsolutePath), composeFile); - - try { - return toCanonicalize.getCanonicalFile(); - } catch (IOException e) { - throw new RuntimeException("Unable to canonicalize the resolved docker-compose file path '" + toCanonicalize + "'"); - } - } - - /** - * Resolves the supplied resource (a path or directory on the filesystem) relative the Maven base directory. The returned {@code File} is guaranteed to be {@link - * File#isAbsolute() absolute}. The returned file is not guaranteed to exist. - *

- * If {@code pathToResolve} is {@link File#isAbsolute() absolute}, then it is returned unmodified. Otherwise, the - * {@code pathToResolve} is returned as an absolute {@code File} using the Maven - * Project base directory} as its parent. - *

- * - * @param pathToResolve represents a filesystem resource, which may be an absolute path - * @param absolutePath absolute path of the Maven project used to resolve non-absolute path resources, may be {@code null} if - * {@code pathToResolve} is {@link File#isAbsolute() absolute} - * @return an absolute {@code File} reference to {@code pathToResolve}; not guaranteed to exist - */ - static File resolveAbsolutely(String pathToResolve, String absolutePath) { - // avoid an NPE if the Maven project is not needed by DockerPathUtil - return DockerPathUtil.resolveAbsolutely(pathToResolve, absolutePath); - } -} diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeConfigHandler.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeConfigHandler.java deleted file mode 100644 index c9f7ddf1b2..0000000000 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeConfigHandler.java +++ /dev/null @@ -1,215 +0,0 @@ -/** - * Copyright (c) 2019 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at: - * - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.jkube.kit.build.service.docker.config.handler.compose; - -import org.eclipse.jkube.kit.config.image.build.BuildConfiguration; -import org.eclipse.jkube.kit.config.image.ImageConfiguration; -import org.eclipse.jkube.kit.config.image.RunImageConfiguration; -import org.eclipse.jkube.kit.build.service.docker.config.handler.ExternalConfigHandler; -import org.eclipse.jkube.kit.build.service.docker.config.handler.ExternalConfigHandlerException; -import org.eclipse.jkube.kit.build.service.docker.helper.DeepCopy; -import org.eclipse.jkube.kit.common.JavaProject; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.SafeConstructor; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static org.eclipse.jkube.kit.build.service.docker.config.handler.compose.ComposeUtils.resolveAbsolutely; -import static org.eclipse.jkube.kit.build.service.docker.config.handler.compose.ComposeUtils.resolveComposeFileAbsolutely; - - -/** - * Docker Compose handler for allowing a docker-compose file to be used - * to specify the docker images. - */ - -// Moved temporarily to resources/META-INF/plexus/components.xml because of https://github.com/codehaus-plexus/plexus-containers/issues/4 -// @Component(role = ExternalConfigHandler.class) -public class DockerComposeConfigHandler implements ExternalConfigHandler { - - @Override - public String getType() { - return "compose"; - } - - @Override - @SuppressWarnings("unchecked") - public List resolve(ImageConfiguration unresolvedConfig, JavaProject project) { - List resolved = new ArrayList<>(); - - DockerComposeConfiguration handlerConfig = new DockerComposeConfiguration(unresolvedConfig.getExternalConfig()); - File composeFile = resolveComposeFileAbsolutely(handlerConfig.getBasedir(), handlerConfig.getComposeFile(), (project != null && project.getBaseDirectory() != null)? project.getBaseDirectory().getAbsolutePath() : null); - - for (Object composeO : getComposeConfigurations(composeFile)) { - Map compose = (Map) composeO; - validateVersion(compose, composeFile); - Map services = (Map) compose.get("services"); - for (Map.Entry entry : services.entrySet()) { - String serviceName = entry.getKey(); - Map serviceDefinition = (Map) entry.getValue(); - - DockerComposeServiceWrapper mapper = new DockerComposeServiceWrapper(serviceName, composeFile, serviceDefinition, unresolvedConfig, resolveAbsolutely(handlerConfig.getBasedir(), (project != null && project.getBaseDirectory() != null)? project.getBaseDirectory().getAbsolutePath() : null)); - resolved.add(buildImageConfiguration(mapper, composeFile.getParentFile(), unresolvedConfig, handlerConfig)); - } - } - - return resolved; - } - - private void validateVersion(Map compose, File file) { - Object version = compose.get("version"); - if (version == null || !isVersion2(version.toString().trim())) { - throw new ExternalConfigHandlerException("Only version 2.x of the docker-compose format is supported for " + file); - } - } - - private boolean isVersion2(String version) { - return version.equals("2") || version.startsWith("2."); - } - - private String extractDockerFilePath(DockerComposeServiceWrapper mapper, File parentDir) { - if (mapper.requiresBuild()) { - File buildDir = new File(mapper.getBuildDir()); - String dockerFile = mapper.getDockerfile(); - if (dockerFile == null) { - dockerFile = "Dockerfile"; - } - File ret = new File(buildDir, dockerFile); - return ret.isAbsolute() ? ret.getAbsolutePath() : new File(parentDir, ret.getPath()).getAbsolutePath(); - } else { - return null; - } - } - - private ImageConfiguration buildImageConfiguration(DockerComposeServiceWrapper mapper, - File composeParent, - ImageConfiguration unresolvedConfig, - DockerComposeConfiguration handlerConfig) { - ImageConfiguration.ImageConfigurationBuilder builder = ImageConfiguration.builder() - .name(getImageName(mapper, unresolvedConfig)) - .alias(mapper.getAlias()) - .build(createBuildImageConfiguration(mapper, composeParent, unresolvedConfig, handlerConfig)) - .run(createRunConfiguration(mapper, unresolvedConfig)); - if (serviceMatchesAlias(mapper, unresolvedConfig)) { - builder.watch(DeepCopy.copy(unresolvedConfig.getWatchConfiguration())); - } - return builder.build(); - } - - private String getImageName(DockerComposeServiceWrapper mapper, ImageConfiguration unresolvedConfig) { - String name = mapper.getImage(); - if (name != null) { - return name; - } else if (unresolvedConfig.getAlias() != null && unresolvedConfig.getAlias().equals(mapper.getAlias())) { - return unresolvedConfig.getName(); - } else { - return null; - } - } - - private Iterable getComposeConfigurations(File composePath) { - try { - Yaml yaml = new Yaml(new SafeConstructor()); - return yaml.loadAll(new FileReader(composePath)); - } - catch (FileNotFoundException e) { - throw new ExternalConfigHandlerException("failed to load external configuration: " + composePath, e); - } - } - - private BuildConfiguration createBuildImageConfiguration( - DockerComposeServiceWrapper mapper, File composeParent, ImageConfiguration imageConfig, - DockerComposeConfiguration handlerConfig) { - - final BuildConfiguration buildConfig = imageConfig.getBuildConfiguration(); - if (handlerConfig.isIgnoreBuild() || !mapper.requiresBuild()) { - if (serviceMatchesAlias(mapper, imageConfig)) { - // Only when the specified image name maps to the current docker-compose service - return buildConfig; - } else { - return null; - } - } - - // Build from the specification as given in the docker-compose file - return buildConfig.toBuilder() - .dockerFile(extractDockerFilePath(mapper, composeParent)) - .args(mapper.getBuildArgs()) - .build(); - } - - private boolean serviceMatchesAlias(DockerComposeServiceWrapper mapper, ImageConfiguration imageConfig) { - return mapper.getAlias() != null && mapper.getAlias().equals(imageConfig.getAlias()); - } - - private RunImageConfiguration createRunConfiguration(DockerComposeServiceWrapper wrapper, ImageConfiguration imageConfig) { - RunImageConfiguration.RunImageConfigurationBuilder builder = - serviceMatchesAlias(wrapper, imageConfig) ? - imageConfig.getRunConfiguration().toBuilder() : - RunImageConfiguration.builder(); - return builder - .capAdd(wrapper.getCapAdd()) - .capDrop(wrapper.getCapDrop()) - .cmd(wrapper.getCommand()) - // cgroup_parent not supported - // container_name is taken as an alias and ignored here for run config - // devices not supported - .dependsOn(wrapper.getDependsOn()) // depends_on relies that no container_name is set - .dns(wrapper.getDns()) - .dnsSearch(wrapper.getDnsSearch()) - .tmpfs(wrapper.getTmpfs()) - .entrypoint(wrapper.getEntrypoint()) - // env_file not supported - .env(wrapper.getEnvironment()) - // expose (for running containers) not supported - // extends not supported - .extraHosts(wrapper.getExtraHosts()) - // image added as top-level - .labels(wrapper.getLabels()) - .links(wrapper.getLinks()) // external_links and links are handled the same in d-m-p - .log(wrapper.getLogConfiguration()) - .network(wrapper.getNetworkConfig()) // TODO: Up to now only a single network is supported and not ipv4, ipv6 - // pid not supported - .ports(wrapper.getPortMapping()) - // security_opt not supported - // stop_signal not supported - .ulimits(wrapper.getUlimits()) - .volumes(wrapper.getVolumeConfig()) - .cpuShares(wrapper.getCpuShares()) - .cpus(wrapper.getCpusCount()) - .cpuSet(wrapper.getCpuSet()) - // cpu_quota n.s. - .domainname(wrapper.getDomainname()) - .hostname(wrapper.getHostname()) - // ipc n.s. - // mac_address n.s. - .memory(wrapper.getMemory()) - .memorySwap(wrapper.getMemorySwap()) - .privileged(wrapper.getPrivileged()) - // read_only n.s. - .restartPolicy(wrapper.getRestartPolicy()) - .shmSize(wrapper.getShmSize()) - // stdin_open n.s. - // tty n.s. - .user(wrapper.getUser()) - .workingDir(wrapper.getWorkingDir()) - .build(); - } - -} diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeConfiguration.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeConfiguration.java deleted file mode 100644 index 0b43f31571..0000000000 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeConfiguration.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2019 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at: - * - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.jkube.kit.build.service.docker.config.handler.compose; - -import java.util.Map; - -public class DockerComposeConfiguration { - - private final String basedir; - private final String composeFile; - private final boolean ignoreBuild; - public DockerComposeConfiguration(Map config) { - basedir = config.getOrDefault("basedir", "src/main/docker"); - composeFile = config.getOrDefault("composerFile", "docker-compose.yml"); - ignoreBuild = Boolean.parseBoolean(config.get("ignoreBuild")); - } - - String getBasedir() { - return basedir; - } - - String getComposeFile() { - return composeFile; - } - - public boolean isIgnoreBuild() { - return ignoreBuild; - } -} diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeServiceWrapper.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeServiceWrapper.java deleted file mode 100644 index b08d6ef221..0000000000 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/config/handler/compose/DockerComposeServiceWrapper.java +++ /dev/null @@ -1,471 +0,0 @@ -/** - * Copyright (c) 2019 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at: - * - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.jkube.kit.build.service.docker.config.handler.compose; - -import org.eclipse.jkube.kit.config.image.ImageConfiguration; -import org.eclipse.jkube.kit.config.image.LogConfiguration; -import org.eclipse.jkube.kit.config.image.NetworkConfig; -import org.eclipse.jkube.kit.config.image.RestartPolicy; -import org.eclipse.jkube.kit.config.image.RunVolumeConfiguration; -import org.eclipse.jkube.kit.config.image.UlimitConfig; -import org.eclipse.jkube.kit.build.service.docker.helper.VolumeBindingUtil; -import org.eclipse.jkube.kit.common.Arguments; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - - -class DockerComposeServiceWrapper { - - private final Map configuration; - private final String name; - private final File composeFile; - private final ImageConfiguration enclosingImageConfig; - private final File baseDir; - - DockerComposeServiceWrapper(String serviceName, File composeFile, Map serviceDefinition, - ImageConfiguration enclosingImageConfig, File baseDir) { - this.name = serviceName; - this.composeFile = composeFile; - this.configuration = serviceDefinition; - this.enclosingImageConfig = enclosingImageConfig; - - if (!baseDir.isAbsolute()) { - throw new IllegalArgumentException( - "Expected the base directory '" + baseDir + "' to be an absolute path."); - } - this.baseDir = baseDir; - } - - String getAlias() { - // 'container_name' takes precidence - String alias = asString("container_name"); - return (alias != null) ? alias : name; - } - - String getImage() { - return asString("image"); - } - - // ================================================================================== - // Build config: - - boolean requiresBuild() { - return asObject("build") != null; - } - - String getBuildDir() { - Object build = asObject("build"); - if (build == null) { - return null; - } - if (build instanceof String) { - return (String) build; - } - if (! (build instanceof Map)) { - throwIllegalArgumentException("build:' must be either a String or a Map"); - } - Map buildConfig = (Map) build; - if (!buildConfig.containsKey("context")) { - throwIllegalArgumentException("'build:' a context directory for a build must be specified"); - } - return buildConfig.get("context"); - } - - String getDockerfile() { - Object build = asObject("build"); - if (build instanceof Map) { - return (String) ((Map) build).get("dockerfile"); - } else { - return null; - } - } - - Map getBuildArgs() { - Object build = asObject("build"); - if (build instanceof Map) { - return (Map) ((Map) build).get("args"); - } else { - return null; - } - } - - // =================================================================================== - // Run config: - - List getCapAdd() { - return asList("cap_add"); - } - - List getCapDrop() { - return asList("cap_drop"); - } - - Arguments getCommand() { - Object command = asObject("command"); - return command != null ? asArguments(command, "command") : null; - } - - List getDependsOn() { - return asList("depends_on"); - } - - List getDns() { - return asList("dns"); - } - - List getDnsSearch() { - return asList("dns_search"); - } - - List getTmpfs() { - return asList("tmpfs"); - } - - Arguments getEntrypoint() { - Object entrypoint = asObject("entrypoint"); - return entrypoint != null ? asArguments(entrypoint, "entrypoint") : null; - } - - Map getEnvironment() { - // TODO: load the env files from compose as given with env_file and add them all to the map - return asMap("environment"); - } - - // external_links are added with "links" - - List getExtraHosts() { - return asList("extra_hosts"); - } - - // image is added as top-level in image configuration - - Map getLabels() { - return asMap("labels"); - } - - public List getLinks() { - List ret = new ArrayList<>(); - ret.addAll(this.asList("links")); - ret.addAll(this.asList("external_links")); - return ret; - } - - LogConfiguration getLogConfiguration() { - Object logConfig = asObject("logging"); - if (logConfig == null) { - return null; - } - if (!(logConfig instanceof Map)) { - throwIllegalArgumentException("'logging' has to be a map and not " + logConfig.getClass()); - } - Map config = (Map) logConfig; - return LogConfiguration.builder() - .driverName((String) config.get("driver")) - .logDriverOpts((Map) config.get("options")) - .build(); - } - - NetworkConfig getNetworkConfig() { - String net = asString("network_mode"); - if (net != null) { - return NetworkConfig.fromLegacyNetSpec(net); - } - Object networks = asObject("networks"); - if (networks == null) { - return null; - } - if (networks instanceof List) { - List toJoin = (List) networks; - if (toJoin.size() > 1) { - throwIllegalArgumentException("'networks:' Only one custom network to join is supported currently"); - } - return NetworkConfig.builder().mode(NetworkConfig.Mode.custom).name(toJoin.get(0)).build(); - } else if (networks instanceof Map) { - Map toJoin = (Map) networks; - if (toJoin.size() > 1) { - throwIllegalArgumentException("'networks:' Only one custom network to join is supported currently"); - } - String custom = toJoin.keySet().iterator().next(); - NetworkConfig ret = NetworkConfig.builder().mode(NetworkConfig.Mode.custom).name(custom).build(); - Object aliases = toJoin.get(custom); - if (aliases != null) { - if (aliases instanceof List) { - for (String alias : (List) aliases) { - ret.addAlias(alias); - } - } else if (aliases instanceof Map) { - Map> map = (Map>) aliases; - if (map.containsKey("aliases")) { - for (String alias : map.get("aliases")) { - ret.addAlias(alias); - } - } else { - throwIllegalArgumentException( - "'networks:' Aliases must be given as a map of strings. 'aliases' key not founded"); - } - } else { - throwIllegalArgumentException("'networks:' No aliases entry found in network config map"); - } - } - return ret; - } else { - throwIllegalArgumentException("'networks:' must beu either a list or a map"); - return null; - } - } - - List getPortMapping() { - List fromYml = asList("ports"); - int size = fromYml.size(); - - List ports = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - String port = fromYml.get(i); - if (port.contains(":")) { - ports.add(port); - } - else { - /* - * docker-compose allows just the port number which triggers a random port and the plugin does not, so construct a property - * name to mimic the required behavior. names will always based on position, and not the number of times we create the - * string. - */ - ports.add(String.format("%s_port_%s:%s", getAlias(), i + 1, port)); - } - } - return ports; - } - - List getUlimits() { - Object ulimits = asObject("ulimits"); - if (ulimits == null) { - return null; - } - if (!(ulimits instanceof Map)) { - throwIllegalArgumentException("'ulimits:' must be a map"); - } - Map ulimitMap = (Map) ulimits; - List ret = new ArrayList<>(); - for (Map.Entry ulimitMapEntry : ulimitMap.entrySet()) { - Object val = ulimitMapEntry.getValue(); - if (val instanceof Map) { - Map valMap = (Map) val; - Integer soft = valMap.get("soft"); - Integer hard = valMap.get("hard"); - ret.add(new UlimitConfig(ulimitMapEntry.getKey(), hard, soft)); - } else if (val instanceof Integer) { - ret.add(new UlimitConfig(ulimitMapEntry.getKey(), (Integer) val, null)); - } else { - throwIllegalArgumentException("'ulimits:' invalid limit value " + val + " (class : " + val.getClass() + ")"); - } - } - return ret; - } - - RunVolumeConfiguration getVolumeConfig() { - RunVolumeConfiguration.RunVolumeConfigurationBuilder builder = RunVolumeConfiguration.builder(); - List volumes = asList("volumes"); - boolean added = false; - if (!volumes.isEmpty()) { - builder.bind(volumes); - added = true; - } - List volumesFrom = asList("volumes_from"); - if (!volumesFrom.isEmpty()) { - builder.from(volumesFrom); - added = true; - } - - if (added) { - final RunVolumeConfiguration runVolumeConfiguration = builder.build(); - VolumeBindingUtil.resolveRelativeVolumeBindings(baseDir, runVolumeConfiguration); - return runVolumeConfiguration; - } - - return null; - } - - String getDomainname() { - return asString("domainname"); - } - - String getHostname() { - return asString("hostname"); - } - - Long getMemory() { - return asLong("mem_limit"); - } - - Long getMemorySwap() { - return asLong("memswap_limit"); - } - - Boolean getPrivileged() { - return asBoolean("privileged"); - } - - RestartPolicy getRestartPolicy() { - String restart = asString("restart"); - if (restart == null) { - return null; - } - - RestartPolicy.RestartPolicyBuilder builder = RestartPolicy.builder(); - if (restart.contains(":")) { - String[] parts = restart.split(":", 2); - builder.name(parts[0]).retry(Integer.valueOf(parts[1])); - } - else { - builder.name(restart); - } - - return builder.build(); - } - - Long getShmSize() { - return asLong("shm_size"); - } - - String getUser() { - return asString("user"); - } - - String getWorkingDir() { - return asString("working_dir"); - } - - // ================================================================ - // Not used yet: - - public String getCGroupParent() { - return asString("cgroup_parent"); - } - - public String getCpuSet() { - return asString("cpuset"); - } - - public Long getCpuShares() { - return asLong("cpu_shares"); - } - - public Long getCpusCount(){ - Double cpus = asDouble("cpus"); - return convertToNanoCpus(cpus); - } - - public List getDevices() { - return asList("devices"); - } - - // ======================================================================================================= - // Helper methods - - private Object asObject(String key) { - return configuration.get(key); - } - - private String asString(String key) { - return (String) configuration.get(key); - } - - private Long asLong(String key) { - Long value = null; - if (configuration.containsKey(key)) { - value = Long.valueOf(configuration.get(key).toString()); - } - return value; - } - - private Boolean asBoolean(String key) { - Boolean value = null; - if (configuration.containsKey(key)) { - value = Boolean.parseBoolean(configuration.get(key).toString()); - } - return value; - } - - private List asList(String key) { - if (configuration.containsKey(key)) { - Object value = configuration.get(key); - if (value instanceof String) { - value = Arrays.asList(value); - } - - return (List) value; - } - - return Collections.emptyList(); - } - - private Map asMap(String key) { - if (configuration.containsKey(key)) { - Object value = configuration.get(key); - if (value instanceof List) { - value = convertToMap((List) value); - } - return (Map) value; - } - - return Collections.emptyMap(); - } - - private Double asDouble(String key){ - Double value = null; - if (configuration.containsKey(key)) { - value = Double.valueOf(configuration.get(key).toString()); - } - return value; - } - - private Arguments asArguments(Object command, String label) { - if (command instanceof String) { - return Arguments.builder().shell((String) command).build(); - } else if (command instanceof List) { - return Arguments.builder().exec((List) command).build(); - } else { - throwIllegalArgumentException(String.format("'%s' must be either String or List but not %s", label, command.getClass())); - return null; - } - } - - private Map convertToMap(List list) { - Map map = new HashMap<>(list.size()); - for (String entry : list) { - String[] parts = entry.split("=", 2); - map.put(parts[0], parts[1]); - } - return map; - } - - private Long convertToNanoCpus(Double cpus){ - if(cpus == null){ - return null; - } - return (long)(cpus * 1000000000); - } - - private void throwIllegalArgumentException(String msg) { - throw new IllegalArgumentException(String.format("%s: %s - ", composeFile, name) + msg); - } - -} - diff --git a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/helper/DeepCopy.java b/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/helper/DeepCopy.java deleted file mode 100644 index 18a0fe3bd5..0000000000 --- a/jkube-kit/build/service/docker/src/main/java/org/eclipse/jkube/kit/build/service/docker/helper/DeepCopy.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (c) 2019 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at: - * - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.jkube.kit.build.service.docker.helper; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -public class DeepCopy { - - private DeepCopy() { } - - /** - * Returns a copy of the object, or null if the object cannot - * be serialized. - * - * @param orig object provided - * @param type of object - * @return returns copy of the object or null - */ - public static T copy(T orig) { - if (orig == null) { - return null; - } - try { - // Write the object out to a byte array - ByteArrayOutputStream fbos = new ByteArrayOutputStream(); - - try (ObjectOutputStream out = new ObjectOutputStream(fbos)) { - out.writeObject(orig); - out.flush(); - } - - // Retrieve an input stream from the byte array and read - // a copy of the object back in. - try (ByteArrayInputStream fbis = new ByteArrayInputStream(fbos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(fbis)) { - return (T) in.readObject(); - } - } catch (IOException | ClassNotFoundException e) { - throw new IllegalStateException("Cannot copy " + orig, e); - } - } -} diff --git a/kubernetes-maven-plugin/plugin/src/main/resources/META-INF/plexus/components.xml b/kubernetes-maven-plugin/plugin/src/main/resources/META-INF/plexus/components.xml index 469bcca69c..ceaa520506 100644 --- a/kubernetes-maven-plugin/plugin/src/main/resources/META-INF/plexus/components.xml +++ b/kubernetes-maven-plugin/plugin/src/main/resources/META-INF/plexus/components.xml @@ -90,17 +90,6 @@ - - org.eclipse.jkube.kit.build.service.docker.config.handler.compose.DockerComposeConfigHandler - org.eclipse.jkube.kit.build.service.docker.config.handler.compose.DockerComposeConfigHandler - - - org.apache.maven.shared.filtering.MavenReaderFilter - readerFilter - - - false - org.eclipse.jkube.kit.build.service.docker.config.handler.property.PropertyConfigHandler org.eclipse.jkube.kit.build.service.docker.config.handler.property.PropertyConfigHandler diff --git a/openshift-maven-plugin/plugin/src/main/resources/META-INF/plexus/components.xml b/openshift-maven-plugin/plugin/src/main/resources/META-INF/plexus/components.xml index 469bcca69c..ceaa520506 100644 --- a/openshift-maven-plugin/plugin/src/main/resources/META-INF/plexus/components.xml +++ b/openshift-maven-plugin/plugin/src/main/resources/META-INF/plexus/components.xml @@ -90,17 +90,6 @@ - - org.eclipse.jkube.kit.build.service.docker.config.handler.compose.DockerComposeConfigHandler - org.eclipse.jkube.kit.build.service.docker.config.handler.compose.DockerComposeConfigHandler - - - org.apache.maven.shared.filtering.MavenReaderFilter - readerFilter - - - false - org.eclipse.jkube.kit.build.service.docker.config.handler.property.PropertyConfigHandler org.eclipse.jkube.kit.build.service.docker.config.handler.property.PropertyConfigHandler