Package adams.docker
Class SimpleDockerHelper
- java.lang.Object
-
- adams.docker.SimpleDockerHelper
-
public class SimpleDockerHelper extends Object
Helper class for issuing docker commands.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Constructor Summary
Constructors Constructor Description SimpleDockerHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
addMapping(List<DockerDirectoryMapping> mappings, DockerDirectoryMapping newMapping)
Adds the mapping, if possible.static String
canAddMapping(List<DockerDirectoryMapping> mappings, DockerDirectoryMapping newMapping)
Checks whether a mapping can be added to the current list of directory mappings.static adams.core.management.CommandResult
command(String binary, String[] command)
Performs a docker command.static adams.core.management.CommandResult
command(String binary, List<String> command)
Performs a docker command (waits for command to finish).static String
fixPath(String path)
Fixes the path a bit, removing duplicate slashes, trailing slash.static adams.core.management.CommandResult
login(String binary, String registry, String user, String pw)
Performs a login.static adams.core.management.CommandResult
logout(String binary, String registry)
Performs a login.static String
toContainerPath(List<DockerDirectoryMapping> mappings, String path)
Translates the local path into a container path.static String[]
toContainerPaths(List<DockerDirectoryMapping> mappings, String[] paths)
Translates the local paths into container paths.
-
-
-
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 useregistry
- the registry to log into, empty/null for defaultuser
- the user for the registrypw
- 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 useregistry
- 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 usecommand
- 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 usecommand
- 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 farnewMapping
- 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 tonewMapping
- the mapping to add- Returns:
- true if added otherwise false
-
-