@Override public void invoke() { super.start(); this.followOutput(new Slf4jLogConsumer(logger())); // wait for the compose container to stop, which should only happen after it has spawned all the service containers logger().info("Docker Compose container is running for command: {}", Joiner.on(" ").join(this.getCommandParts())); while (this.isRunning()) { logger().trace("Compose container is still running"); Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } logger().info("Docker Compose has finished running"); AuditLogger.doComposeLog(this.getCommandParts(), this.getEnv()); final Integer exitCode = this.dockerClient.inspectContainerCmd(containerId) .exec() .getState() .getExitCode(); if (exitCode == null || exitCode != 0) { throw new ContainerLaunchException( "Containerised Docker Compose exited abnormally with code " + exitCode + " whilst running command: " + StringUtils.join(this.getCommandParts(), ' ')); } } }
@Override public void invoke() { super.start(); this.followOutput(new Slf4jLogConsumer(logger())); // wait for the compose container to stop, which should only happen after it has spawned all the service containers logger().info("Docker Compose container is running for command: {}", Joiner.on(" ").join(this.getCommandParts())); while (this.isRunning()) { logger().trace("Compose container is still running"); Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } logger().info("Docker Compose has finished running"); AuditLogger.doComposeLog(this.getCommandParts(), this.getEnv()); final Integer exitCode = this.dockerClient.inspectContainerCmd(containerId).exec().getState().getExitCode(); if (exitCode == null || exitCode != 0) { throw new ContainerLaunchException("Containerised Docker Compose exited abnormally with code " + exitCode + " whilst running command: " + StringUtils.join(this.getCommandParts(), ' ')); } } }
public static void doLog(@NotNull String action, @Nullable String image, @Nullable String containerId, @NotNull DockerCmd<?> cmd, @Nullable Exception e) { if (! log.isTraceEnabled()) { return; } MDC.put(MDC_PREFIX + ".Action", nullToEmpty(action)); MDC.put(MDC_PREFIX + ".Image", nullToEmpty(image)); MDC.put(MDC_PREFIX + ".ContainerId", nullToEmpty(containerId)); try { MDC.put(MDC_PREFIX + ".Command", objectMapper.writeValueAsString(cmd)); } catch (JsonProcessingException ignored) { } if (e != null) { MDC.put(MDC_PREFIX + ".Exception", e.getLocalizedMessage()); log.trace("{} action with image: {}, containerId: {}", action, image, containerId, e); } else { log.trace("{} action with image: {}, containerId: {}", action, image, containerId); } MDC.remove(MDC_PREFIX + ".Action"); MDC.remove(MDC_PREFIX + ".Image"); MDC.remove(MDC_PREFIX + ".ContainerId"); MDC.remove(MDC_PREFIX + ".Command"); MDC.remove(MDC_PREFIX + ".Exception"); }
doLog(action, image, containerId, cmd, null);