Package net.officefloor.docker.test
Class OfficeFloorDockerUtil
java.lang.Object
net.officefloor.docker.test.OfficeFloorDockerUtil
Docker wrapper for running third party services (typically for testing).
- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFactory to create the build directory. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DockerContainerInstanceensureContainerAvailable(String containerName, String imageName, String defaultTagName, BiFunction<com.github.dockerjava.api.DockerClient, String, com.github.dockerjava.api.command.CreateContainerCmd> createContainer) Ensures the docker container is available.static voidensureImageAvailable(String imageName, String defaultTagName, OfficeFloorDockerUtil.BuildDirectoryFactory buildDirectoryFactory) Ensures the image is available.static DockerNetworkInstanceensureNetworkAvailable(String networkName) Ensures the docker network is available.static StringgetImageQualifiedName(String imageName, String defaulTagName) Obtains the image name qualified with appropriate tag name.
-
Constructor Details
-
OfficeFloorDockerUtil
public OfficeFloorDockerUtil()
-
-
Method Details
-
getImageQualifiedName
Obtains the image name qualified with appropriate tag name.
This allows overriding the default tag name with a configured file on the class path for the image name.
- Parameters:
imageName- Name of the image.defaulTagName- Default tag name if no overriding configuration.- Returns:
- Qualified image name.
- Throws:
Exception- If fails to load configured tag name.
-
ensureNetworkAvailable
Ensures the docker network is available.- Parameters:
networkName- Network name.- Returns:
DockerNetworkInstanceof manage docker network.- Throws:
Exception- If fails to ensure docker network available.
-
ensureImageAvailable
public static void ensureImageAvailable(String imageName, String defaultTagName, OfficeFloorDockerUtil.BuildDirectoryFactory buildDirectoryFactory) throws Exception Ensures the image is available. If not, will build image from input build directory.- Parameters:
imageName- Name of image to check exists or build.defaultTagName- Default tag name.buildDirectoryFactory-OfficeFloorDockerUtil.BuildDirectoryFactoryto use if image not built.- Throws:
Exception- If fails to ensure the image is available.
-
ensureContainerAvailable
public static DockerContainerInstance ensureContainerAvailable(String containerName, String imageName, String defaultTagName, BiFunction<com.github.dockerjava.api.DockerClient, String, throws Exceptioncom.github.dockerjava.api.command.CreateContainerCmd> createContainer) Ensures the docker container is available.- Parameters:
containerName- Name of docker container.imageName- Name of the docker image.defaultTagName- Default tag name.createContainer- Factory for theCreateContainerCmdif container not running.- Returns:
DockerContainerInstanceto manage running docker container.- Throws:
Exception- If fails to ensure docker container available.
-