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 Details

    • remoting

      protected static final File remoting
      Name of the remoting jar file
  • Constructor Details

    • DockerComputerConnector

      public DockerComputerConnector()
  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • 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 - The DockerAPI that this container belongs to.
      workdir - The filesystem path to the Jenkins agent working directory.
      cmd - The CreateContainerCmd 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 inject remoting.jar using injectRemotingJar(String, String, DockerClient)
      Parameters:
      api - The DockerAPI 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 - The DockerAPI 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 - The CreateContainerCmd to be adjusted.
    • ensureNodeIsKnown

      protected void ensureNodeIsKnown(DockerTransientNode node) throws IOException
      Ensure that a DockerNode is known to Jenkins so that Jenkins will accept an incoming JNLP connection etc.
      Parameters:
      node - The DockerTransientNode 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 ID
      workdir - The filesystem path to the Jenkins agent working directory.
      client - The DockerClient 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

      @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) protected static void addEnvVar(@NonNull EnvVars vars, @NonNull String name, @Nullable Object valueOrNull)
    • 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 - The DockerAPI 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

      Returns:
      all the registered DockerComputerConnector descriptors.