Search in sources :

Example 1 with ExecException

use of org.eclipse.jkube.kit.build.service.docker.access.ExecException in project jkube by eclipse.

the class RunService method execInContainer.

/**
 * Create and start a Exec container with the given image configuration.
 * @param containerId container id to run exec command against
 * @param command command to execute
 * @param imageConfiguration configuration of the container's image
 * @return the exec container id
 *
 * @throws DockerAccessException if access to the docker backend fails
 * @throws ExecException if any problem faced during exec
 */
public String execInContainer(String containerId, String command, ImageConfiguration imageConfiguration) throws DockerAccessException, ExecException {
    Arguments arguments = new Arguments();
    arguments.setExec(Arrays.asList(EnvUtil.splitOnSpaceWithEscape(command)));
    String execContainerId = docker.createExecContainer(containerId, arguments);
    docker.startExecContainer(execContainerId, logConfig.createSpec(containerId, imageConfiguration));
    ExecDetails execContainer = docker.getExecContainer(execContainerId);
    Integer exitCode = execContainer.getExitCode();
    if (exitCode != null && exitCode != 0) {
        ContainerDetails container = docker.getContainer(containerId);
        throw new ExecException(execContainer, container);
    }
    return execContainerId;
}
Also used : ExecDetails(org.eclipse.jkube.kit.build.api.model.ExecDetails) ExecException(org.eclipse.jkube.kit.build.service.docker.access.ExecException) Arguments(org.eclipse.jkube.kit.config.image.build.Arguments) ContainerDetails(org.eclipse.jkube.kit.build.api.model.ContainerDetails)

Example 2 with ExecException

use of org.eclipse.jkube.kit.build.service.docker.access.ExecException in project jkube by eclipse.

the class StartContainerExecutor method waitAndPostExec.

private void waitAndPostExec(String containerId, Properties projProperties) throws IOException, ExecException {
    // Wait if requested
    hub.getWaitService().wait(imageConfig, projProperties, containerId);
    WaitConfiguration waitConfig = imageConfig.getRunConfiguration().getWait();
    if (waitConfig != null && waitConfig.getExec() != null && waitConfig.getExec().getPostStart() != null) {
        try {
            hub.getRunService().execInContainer(containerId, waitConfig.getExec().getPostStart(), imageConfig);
        } catch (ExecException exp) {
            if (waitConfig.getExec().isBreakOnError()) {
                throw exp;
            } else {
                log.warn("Cannot run postStart: %s", exp.getMessage());
            }
        }
    }
}
Also used : WaitConfiguration(org.eclipse.jkube.kit.config.image.WaitConfiguration) ExecException(org.eclipse.jkube.kit.build.service.docker.access.ExecException)

Aggregations

ExecException (org.eclipse.jkube.kit.build.service.docker.access.ExecException)2 ContainerDetails (org.eclipse.jkube.kit.build.api.model.ContainerDetails)1 ExecDetails (org.eclipse.jkube.kit.build.api.model.ExecDetails)1 WaitConfiguration (org.eclipse.jkube.kit.config.image.WaitConfiguration)1 Arguments (org.eclipse.jkube.kit.config.image.build.Arguments)1