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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static void
protected static void
addEnvVars
(EnvVars vars, Iterable<? extends NodeProperty<?>> nodeProperties) void
afterContainerStarted
(DockerAPI api, String workdir, DockerTransientNode node) Called once the container has started.all()
void
beforeContainerCreated
(DockerAPI api, String workdir, com.github.dockerjava.api.command.CreateContainerCmd cmd) Called just before the container is created.void
beforeContainerStarted
(DockerAPI api, String workdir, DockerTransientNode node) Called once the container has been created but not started yet, that's a good opportunity to injectremoting.jar
usinginjectRemotingJar(String, String, DockerClient)
protected abstract ComputerLauncher
createLauncher
(DockerAPI api, String workdir, com.github.dockerjava.api.command.InspectContainerResponse inspect, TaskListener listener) Create a Launcher to create an Agent with this container.final ComputerLauncher
createLauncher
(DockerAPI api, String containerId, String workdir, TaskListener listener) protected void
Ensure that a DockerNode is known to Jenkins so that Jenkins will accept an incoming JNLP connection etc.protected void
ensureWaiting
(com.github.dockerjava.api.command.CreateContainerCmd cmd) Ensure container is already set with a command, or set one to make it wait indefinitelyboolean
int
hashCode()
protected String
injectRemotingJar
(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
- TheDockerAPI
that this container belongs to.workdir
- The filesystem path to the Jenkins agent working directory.cmd
- TheCreateContainerCmd
that'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.jar
usinginjectRemotingJar(String, String, DockerClient)
- Parameters:
api
- TheDockerAPI
that 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
- TheDockerAPI
that 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
- TheCreateContainerCmd
to be adjusted.
-
ensureNodeIsKnown
Ensure that a DockerNode is known to Jenkins so that Jenkins will accept an incoming JNLP connection etc.- Parameters:
node
- TheDockerTransientNode
that'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
- TheDockerClient
for 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:
IOException
InterruptedException
-
addEnvVar
-
createLauncher
@NonNull public final ComputerLauncher createLauncher(@NonNull DockerAPI api, @NonNull String containerId, @NonNull String workdir, @NonNull TaskListener listener) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
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
- TheDockerAPI
for 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
DockerComputerConnector
descriptors.
-