@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 protected ComputerLauncher createLauncher(DockerAPI api, String workdir, InspectContainerResponse inspect, TaskListener listener) throws IOException, InterruptedException { if ("exited".equals(inspect.getState().getStatus())) { // Something went wrong // FIXME report error "somewhere" visible to end user. LOGGER.error("Failed to launch docker SSH agent :" + inspect.getState().getExitCode()); throw new IOException("Failed to launch docker SSH agent. Container exited with status " + inspect.getState().getExitCode()); } LOGGER.debug("container created {}", inspect); final InetSocketAddress address = getBindingForPort(api, inspect, port); // Wait until sshd has started // TODO we could (also) have a more generic mechanism relying on healthcheck (inspect State.Health.Status) final PortUtils.ConnectionCheck connectionCheck = PortUtils.connectionCheck( address ) .withRetries( maxNumRetries ) .withEveryRetryWaitFor( retryWaitTime, TimeUnit.SECONDS ); if (!connectionCheck.execute() || !connectionCheck.useSSH().execute()) { throw new IOException("SSH service didn't start after " + retryWaitTime*maxNumRetries + "s."); } return sshKeyStrategy.getSSHLauncher(address, this); }
return dockerClient.inspectContainerCmd(exec.getId()).exec().getState().getExitCode(); } finally { dockerClient.removeContainerCmd(exec.getId()).exec();
@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 boolean isContainerExitCodeSuccess(InspectContainerResponse.ContainerState state) { int exitCode = state.getExitCode(); // 0 is the only exit code we can consider as success return exitCode == 0; } }
public static boolean isContainerExitCodeSuccess(InspectContainerResponse.ContainerState state) { int exitCode = state.getExitCode(); // 0 is the only exit code we can consider as success return exitCode == 0; } }