Package io.jenkins.docker.connector
Class DockerComputerConnector
java.lang.Object
hudson.model.AbstractDescribableImpl<DockerComputerConnector>
io.jenkins.docker.connector.DockerComputerConnector
- All Implemented Interfaces:
Describable<DockerComputerConnector>
- Direct Known Subclasses:
DockerComputerAttachConnector,DockerComputerJNLPConnector,DockerComputerSSHConnector
public abstract class DockerComputerConnector
extends AbstractDescribableImpl<DockerComputerConnector>
Create a
DockerTransientNode based on a template. Container is created in detached mode so it can survive
a jenkins restart (typically when Pipelines are used) then a launcher can re-connect. In many cases this
means container is running a dummy command as main process, then launcher is establish with `docker exec`.- Author:
- Nicolas De Loof
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidprotected static voidaddEnvVars(EnvVars vars, Iterable<? extends NodeProperty<?>> nodeProperties) voidafterContainerStarted(DockerAPI api, String workdir, DockerTransientNode node) Called once the container has started.all()voidbeforeContainerCreated(DockerAPI api, String workdir, com.github.dockerjava.api.command.CreateContainerCmd cmd) Called just before the container is created.voidbeforeContainerStarted(DockerAPI api, String workdir, DockerTransientNode node) Called once the container has been created but not started yet, that's a good opportunity to injectremoting.jarusinginjectRemotingJar(String, String, DockerClient)protected abstract ComputerLaunchercreateLauncher(DockerAPI api, String workdir, com.github.dockerjava.api.command.InspectContainerResponse inspect, TaskListener listener) Create a Launcher to create an Agent with this container.final ComputerLaunchercreateLauncher(DockerAPI api, String containerId, String workdir, TaskListener listener) protected voidEnsure that a DockerNode is known to Jenkins so that Jenkins will accept an incoming JNLP connection etc.protected voidensureWaiting(com.github.dockerjava.api.command.CreateContainerCmd cmd) Ensure container is already set with a command, or set one to make it wait indefinitelybooleaninthashCode()protected StringinjectRemotingJar(String containerId, String workdir, com.github.dockerjava.api.DockerClient client) Utility method to copy remoting runtime into container on specified working directoryMethods inherited from class hudson.model.AbstractDescribableImpl
getDescriptor
-
Field Details
-
remoting
Name of the remoting jar file
-
-
Constructor Details
-
DockerComputerConnector
public DockerComputerConnector()
-
-
Method Details
-
hashCode
public int hashCode() -
equals
-
beforeContainerCreated
public void beforeContainerCreated(@NonNull DockerAPI api, @NonNull String workdir, @NonNull com.github.dockerjava.api.command.CreateContainerCmd cmd) throws IOException, InterruptedException Called just before the container is created. Can provide some customization to the container creation command.- Parameters:
api- TheDockerAPIthat this container belongs to.workdir- The filesystem path to the Jenkins agent working directory.cmd- TheCreateContainerCmdthat's about to be used.- Throws:
IOException- If anything goes wrong.InterruptedException- If interrupted while doing things.
-
beforeContainerStarted
public void beforeContainerStarted(@NonNull DockerAPI api, @NonNull String workdir, @NonNull DockerTransientNode node) throws IOException, InterruptedException Called once the container has been created but not started yet, that's a good opportunity to injectremoting.jarusinginjectRemotingJar(String, String, DockerClient)- Parameters:
api- TheDockerAPIthat this container belongs to.workdir- The filesystem path to the Jenkins agent working directory.node- The Jenkins node.- Throws:
IOException- If anything goes wrong.InterruptedException- If interrupted while doing things.
-
afterContainerStarted
public void afterContainerStarted(@NonNull DockerAPI api, @NonNull String workdir, @NonNull DockerTransientNode node) throws IOException, InterruptedException Called once the container has started. For some connection methods this can be a good place to check it's healthy before considering agent is ready to accept connections.- Parameters:
api- TheDockerAPIthat this container belongs to.workdir- The filesystem path to the Jenkins agent working directory.node- The Jenkins node.- Throws:
IOException- If anything goes wrong.InterruptedException- If interrupted while doing things.
-
ensureWaiting
protected void ensureWaiting(@NonNull com.github.dockerjava.api.command.CreateContainerCmd cmd) Ensure container is already set with a command, or set one to make it wait indefinitely- Parameters:
cmd- TheCreateContainerCmdto be adjusted.
-
ensureNodeIsKnown
Ensure that a DockerNode is known to Jenkins so that Jenkins will accept an incoming JNLP connection etc.- Parameters:
node- TheDockerTransientNodethat's about to try connecting via JNLP.- Throws:
IOException- if Jenkins is unable to persist the details.
-
injectRemotingJar
protected String injectRemotingJar(@NonNull String containerId, @NonNull String workdir, @NonNull com.github.dockerjava.api.DockerClient client) Utility method to copy remoting runtime into container on specified working directory- Parameters:
containerId- The docker container IDworkdir- The filesystem path to the Jenkins agent working directory.client- TheDockerClientfor the cloud this container belongs to.- Returns:
- The filesystem path to the remoting jar file.
-
addEnvVars
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) protected static void addEnvVars(@NonNull EnvVars vars, @Nullable Iterable<? extends NodeProperty<?>> nodeProperties) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
addEnvVar
-
createLauncher
@NonNull public final ComputerLauncher createLauncher(@NonNull DockerAPI api, @NonNull String containerId, @NonNull String workdir, @NonNull TaskListener listener) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
createLauncher
@NonNull protected abstract ComputerLauncher createLauncher(@NonNull DockerAPI api, @NonNull String workdir, @NonNull com.github.dockerjava.api.command.InspectContainerResponse inspect, @NonNull TaskListener listener) throws IOException, InterruptedException Create a Launcher to create an Agent with this container. Can assume container has been created by this DockerAgentConnector so adequate setup did take place.- Parameters:
api- TheDockerAPIfor the cloud this agent is running on.workdir- The filesystem path to the Jenkins agent working directory.inspect- Information from the docker daemon about our container.listener- Where to output any issues.- Returns:
- A configured
ComputerLauncher. - Throws:
IOException- If anything goes wrong, e.g. talking to docker.InterruptedException- If we're interrupted while waiting.
-
all
public static DescriptorExtensionList<DockerComputerConnector,Descriptor<DockerComputerConnector>> all()- Returns:
- all the registered
DockerComputerConnectordescriptors.
-