Class DockerComputerConnector

    • Field Detail

      • remoting

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

      • DockerComputerConnector

        public DockerComputerConnector()
    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode 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.
      • 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.
      • addEnvVar

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