|
39 | 39 | import eu.openanalytics.containerproxy.model.spec.ProxySpec; |
40 | 40 | import eu.openanalytics.containerproxy.util.Retrying; |
41 | 41 | import org.mandas.docker.client.DockerClient; |
| 42 | +import org.mandas.docker.client.LogStream; |
42 | 43 | import org.mandas.docker.client.exceptions.DockerException; |
43 | 44 | import org.mandas.docker.client.exceptions.ServiceNotFoundException; |
44 | 45 | import org.mandas.docker.client.messages.RegistryAuth; |
|
61 | 62 | import org.springframework.stereotype.Component; |
62 | 63 |
|
63 | 64 | import javax.annotation.PostConstruct; |
| 65 | +import java.io.IOException; |
| 66 | +import java.io.OutputStream; |
64 | 67 | import java.net.MalformedURLException; |
65 | 68 | import java.net.URI; |
66 | 69 | import java.net.URL; |
| 70 | +import java.nio.channels.ClosedChannelException; |
67 | 71 | import java.util.ArrayList; |
68 | 72 | import java.util.HashMap; |
69 | 73 | import java.util.List; |
70 | 74 | import java.util.Map; |
71 | 75 | import java.util.Optional; |
72 | | -import java.util.UUID; |
| 76 | +import java.util.function.BiConsumer; |
73 | 77 | import java.util.stream.Stream; |
74 | 78 |
|
75 | 79 | @Component |
@@ -134,11 +138,11 @@ public Proxy startContainer(Authentication user, Container initialContainer, Con |
134 | 138 | .secrets(secretBinds) |
135 | 139 | .build(); |
136 | 140 |
|
137 | | - List<NetworkAttachmentConfig> networks = spec.getNetworkConnections() |
| 141 | + List<NetworkAttachmentConfig> networks = new ArrayList<>(spec.getNetworkConnections() |
138 | 142 | .getValueOrDefault(new ArrayList<>()) |
139 | 143 | .stream() |
140 | 144 | .map(n -> NetworkAttachmentConfig.builder().target(n).build()) |
141 | | - .toList(); |
| 145 | + .toList()); |
142 | 146 |
|
143 | 147 | if (spec.getNetwork().isPresent()) { |
144 | 148 | networks.add(NetworkAttachmentConfig.builder().target(spec.getNetwork().getValue()).build()); |
@@ -349,5 +353,21 @@ public List<ExistingContainerInfo> scanExistingContainers() throws Exception { |
349 | 353 | return containers; |
350 | 354 | } |
351 | 355 |
|
| 356 | + @Override |
| 357 | + public BiConsumer<OutputStream, OutputStream> getOutputAttacher(Proxy proxy) { |
| 358 | + Container container = getPrimaryContainer(proxy); |
| 359 | + if (container == null) return null; |
| 360 | + String serviceId = container.getRuntimeObjectOrNull(BackendContainerNameKey.inst); |
| 361 | + |
| 362 | + return (stdOut, stdErr) -> { |
| 363 | + try { |
| 364 | + LogStream logStream = dockerClient.serviceLogs(serviceId, DockerClient.LogsParam.follow(), DockerClient.LogsParam.stdout(), DockerClient.LogsParam.stderr()); |
| 365 | + logStream.attach(stdOut, stdErr); |
| 366 | + } catch (ClosedChannelException ignored) { |
| 367 | + } catch (IOException | InterruptedException | DockerException e) { |
| 368 | + log.error("Error while attaching to container output", e); |
| 369 | + } |
| 370 | + }; |
| 371 | + } |
352 | 372 |
|
353 | 373 | } |
0 commit comments