Package adams.docker

Class SimpleDockerHelper


  • public class SimpleDockerHelper
    extends Object
    Helper class for issuing docker commands.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • SimpleDockerHelper

        public SimpleDockerHelper()
    • Method Detail

      • login

        public static adams.core.management.CommandResult login​(String binary,
                                                                String registry,
                                                                String user,
                                                                String pw)
        Performs a login.
        Parameters:
        binary - the docker binary to use
        registry - the registry to log into, empty/null for default
        user - the user for the registry
        pw - the password for the registry
        Returns:
        the result of the command
      • logout

        public static adams.core.management.CommandResult logout​(String binary,
                                                                 String registry)
        Performs a login.
        Parameters:
        binary - the docker binary to use
        registry - the registry to log into, empty/null for default
        Returns:
        the result of the command
      • command

        public static adams.core.management.CommandResult command​(String binary,
                                                                  String[] command)
        Performs a docker command.
        Parameters:
        binary - the docker binary to use
        command - the docker command and its parameters
        Returns:
        the result of the command
      • command

        public static adams.core.management.CommandResult command​(String binary,
                                                                  List<String> command)
        Performs a docker command (waits for command to finish).
        Parameters:
        binary - the docker binary to use
        command - the docker command and its parameters
        Returns:
        the result of the command
      • fixPath

        public static String fixPath​(String path)
        Fixes the path a bit, removing duplicate slashes, trailing slash.
        Parameters:
        path - the path to fix
        Returns:
        the fixed path
      • toContainerPath

        public static String toContainerPath​(List<DockerDirectoryMapping> mappings,
                                             String path)
                                      throws IOException
        Translates the local path into a container path. Skips a string that does not start with a forward slash.
        Parameters:
        path - the local path
        Returns:
        the translated path
        Throws:
        IOException - if the path cannot be translated into a container one
      • toContainerPaths

        public static String[] toContainerPaths​(List<DockerDirectoryMapping> mappings,
                                                String[] paths)
                                         throws IOException
        Translates the local paths into container paths. Skips entries that do not start with a forward slash.
        Parameters:
        paths - the local paths
        Returns:
        the translated paths
        Throws:
        IOException - if a path cannot be translated into a container one
      • canAddMapping

        public static String canAddMapping​(List<DockerDirectoryMapping> mappings,
                                           DockerDirectoryMapping newMapping)
        Checks whether a mapping can be added to the current list of directory mappings. Ensures that neither local nor container path are already in use.
        Parameters:
        mappings - the mappings to far
        newMapping - the new mapping to check
        Returns:
        null if it can be added, otherwise reason why not
      • addMapping

        public static boolean addMapping​(List<DockerDirectoryMapping> mappings,
                                         DockerDirectoryMapping newMapping)
        Adds the mapping, if possible.
        Parameters:
        mappings - the mappings to add to
        newMapping - the mapping to add
        Returns:
        true if added otherwise false