|
1 | 1 | /*******************************************************************************
|
2 | 2 | * Copyright (c) 2014, 2020 Red Hat.
|
3 |
| - * |
| 3 | + * |
4 | 4 | * This program and the accompanying materials are made
|
5 | 5 | * available under the terms of the Eclipse Public License 2.0
|
6 | 6 | * which is available at https://www.eclipse.org/legal/epl-2.0/
|
|
22 | 22 | import java.util.TreeSet;
|
23 | 23 |
|
24 | 24 | import org.eclipse.linuxtools.docker.core.IDockerContainerConfig;
|
25 |
| - |
26 | 25 | import org.mandas.docker.client.messages.ContainerConfig;
|
27 | 26 | import org.mandas.docker.client.messages.HostConfig;
|
| 27 | +import org.mandas.docker.client.messages.ImageConfig; |
28 | 28 |
|
29 | 29 | public class DockerContainerConfig implements IDockerContainerConfig {
|
30 | 30 |
|
@@ -55,7 +55,7 @@ public class DockerContainerConfig implements IDockerContainerConfig {
|
55 | 55 | private final List<String> onBuild;
|
56 | 56 | private final Map<String, String> labels;
|
57 | 57 |
|
58 |
| - public DockerContainerConfig(final ContainerConfig containerConfig) { |
| 58 | + public DockerContainerConfig(final ImageConfig containerConfig) { |
59 | 59 | this.hostname = containerConfig != null ? containerConfig.hostname()
|
60 | 60 | : null;
|
61 | 61 | this.domainname = containerConfig != null ? containerConfig.domainname()
|
@@ -114,6 +114,74 @@ public DockerContainerConfig(final ContainerConfig containerConfig) {
|
114 | 114 | this.labels = containerConfig != null ? containerConfig.labels() : null;
|
115 | 115 | }
|
116 | 116 |
|
| 117 | + public DockerContainerConfig(final ContainerConfig containerConfig) { |
| 118 | + this.hostname = containerConfig != null ? containerConfig.hostname() |
| 119 | + : null; |
| 120 | + this.domainname = containerConfig != null ? containerConfig.domainname() |
| 121 | + : null; |
| 122 | + this.user = containerConfig != null ? containerConfig.user() : null; |
| 123 | + final HostConfig hc = containerConfig != null |
| 124 | + ? containerConfig.hostConfig() |
| 125 | + : null; |
| 126 | + this.memory = hc != null ? hc.memory() : null; |
| 127 | + this.memorySwap = hc != null ? hc.memorySwap() : null; |
| 128 | + this.cpuShares = hc != null ? hc.cpuShares() : null; |
| 129 | + this.cpuset = hc != null ? hc.cpusetCpus() : null; |
| 130 | + this.attachStdin = containerConfig != null |
| 131 | + && containerConfig.attachStdin() != null |
| 132 | + ? containerConfig.attachStdin() |
| 133 | + : false; |
| 134 | + this.attachStdout = containerConfig != null |
| 135 | + && containerConfig.attachStdout() != null |
| 136 | + ? containerConfig.attachStdout() |
| 137 | + : false; |
| 138 | + this.attachStderr = containerConfig != null |
| 139 | + && containerConfig.attachStderr() != null |
| 140 | + ? containerConfig.attachStderr() |
| 141 | + : false; |
| 142 | + this.portSpecs = containerConfig != null ? containerConfig.portSpecs() |
| 143 | + : null; |
| 144 | + this.exposedPorts = containerConfig != null |
| 145 | + ? containerConfig.exposedPorts() |
| 146 | + : null; |
| 147 | + this.tty = containerConfig != null && containerConfig.tty() != null |
| 148 | + ? containerConfig.tty() |
| 149 | + : false; |
| 150 | + this.openStdin = containerConfig != null |
| 151 | + && containerConfig.openStdin() != null |
| 152 | + ? containerConfig.openStdin() |
| 153 | + : false; |
| 154 | + this.stdinOnce = containerConfig != null |
| 155 | + && containerConfig.stdinOnce() != null |
| 156 | + ? containerConfig.stdinOnce() |
| 157 | + : false; |
| 158 | + this.env = containerConfig != null ? containerConfig.env() : null; |
| 159 | + this.cmd = containerConfig != null ? containerConfig.cmd() : null; |
| 160 | + this.image = containerConfig != null ? containerConfig.image() : null; |
| 161 | + |
| 162 | + @SuppressWarnings("rawtypes") |
| 163 | + Map<String, Map> res = new HashMap<>(); |
| 164 | + try { |
| 165 | + if (containerConfig != null && containerConfig.volumes() != null) { |
| 166 | + containerConfig.volumes() |
| 167 | + .forEach(v -> res.put(v, Collections.emptyMap())); |
| 168 | + } |
| 169 | + } catch (NullPointerException e) { |
| 170 | + } |
| 171 | + this.volumes = res; |
| 172 | + this.workingDir = containerConfig != null ? containerConfig.workingDir() |
| 173 | + : null; |
| 174 | + this.entrypoint = containerConfig != null ? containerConfig.entrypoint() |
| 175 | + : null; |
| 176 | + this.networkDisabled = containerConfig != null |
| 177 | + && containerConfig.networkDisabled() != null |
| 178 | + ? containerConfig.networkDisabled() |
| 179 | + : false; |
| 180 | + this.onBuild = containerConfig != null ? containerConfig.onBuild() |
| 181 | + : null; |
| 182 | + this.labels = containerConfig != null ? containerConfig.labels() : null; |
| 183 | + } |
| 184 | + |
117 | 185 | private DockerContainerConfig(final Builder builder) {
|
118 | 186 | this.hostname = builder.hostname;
|
119 | 187 | this.domainname = builder.domainname;
|
@@ -600,7 +668,7 @@ public DockerContainerConfig build() {
|
600 | 668 |
|
601 | 669 | /**
|
602 | 670 | * Create a proper command list after handling quotation.
|
603 |
| - * |
| 671 | + * |
604 | 672 | * @param command
|
605 | 673 | * the command as a single {@link String}
|
606 | 674 | * @return the command splitted in a list of ars or <code>null</code> if
|
|
0 commit comments