-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Docker containers for your integration tests. -- -- testcontainers is a Haskell library that provides a friendly API to -- run Docker containers. It is designed to create a runtime environment -- to use during your integration tests @package testcontainers @version 0.4.0.0 module TestContainers.Docker.Reaper -- | Reaper for safe resource cleanup. data Reaper -- | Additional labels to add to any Docker resource on creation. Adding -- the labels is necessary in order for the Reaper to find -- resources for cleanup. reaperLabels :: Reaper -> [(Text, Text)] -- | Tag for the ryuk image ryukImageTag :: Text -- | Exposed port for the ryuk reaper. ryukPort :: Num a => a -- | Creates a new Reaper from a host and port. newRyukReaper :: MonadResource m => Text -> Int -> m Reaper module TestContainers.Trace -- | Type representing various events during testcontainer execution. data Trace -- | The low-level invocation of docker command -- --
--   TraceDockerInvocation args stdin exitcode
--   
TraceDockerInvocation :: [Text] -> Text -> ExitCode -> Trace -- | Preparations to follow the logs for a certain container TraceDockerFollowLogs :: [Text] -> Trace -- | Line written to STDOUT by a Docker process. TraceDockerStdout :: Text -> Trace -- | Line written to STDERR by a Docker process. TraceDockerStderr :: Text -> Trace -- | Waiting for a container to become ready. Attached with the timeout to -- wait (in seconds). TraceWaitUntilReady :: Maybe Int -> Trace -- | Opening socket TraceOpenSocket :: Text -> Int -> Maybe IOException -> Trace -- | Call HTTP endpoint TraceHttpCall :: Text -> Int -> Either String Int -> Trace -- | Traces execution within testcontainers library. data Tracer -- | Construct a new Tracer from a tracing function. newTracer :: (Trace -> IO ()) -> Tracer withTrace :: MonadIO m => Tracer -> Trace -> m () instance GHC.Show.Show TestContainers.Trace.Trace instance GHC.Classes.Eq TestContainers.Trace.Trace instance GHC.Base.Monoid TestContainers.Trace.Tracer instance GHC.Base.Semigroup TestContainers.Trace.Tracer module TestContainers.Monad -- | Docker related functionality is parameterized over this Monad. -- Since 0.4.0.0 this is just a type alias for m ~ -- TestContainer. type MonadDocker m = (m ~ TestContainer) -- | The heart and soul of the testcontainers library. data TestContainer a -- | Run a TestContainer action. Any container spun up during the -- computation are guaranteed to be shutdown and cleaned up once this -- function returns. runTestContainer :: Config -> TestContainer a -> IO a -- | Configuration for defaulting behavior. data Config Config :: Maybe Int -> Tracer -> TestContainer Reaper -> Config -- | The number of seconds to maximally wait for a container to become -- ready. Default is `Just 60`. -- -- Nothing = waits indefinitely. [configDefaultWaitTimeout] :: Config -> Maybe Int -- | Traces execution inside testcontainers library. [configTracer] :: Config -> Tracer -- | How to obtain a Reaper [configCreateReaper] :: Config -> TestContainer Reaper instance Control.Monad.Fix.MonadFix TestContainers.Monad.TestContainer instance Control.Monad.Trans.Resource.Internal.MonadResource TestContainers.Monad.TestContainer instance Control.Monad.Catch.MonadThrow TestContainers.Monad.TestContainer instance Control.Monad.Catch.MonadCatch TestContainers.Monad.TestContainer instance Control.Monad.Catch.MonadMask TestContainers.Monad.TestContainer instance Control.Monad.IO.Class.MonadIO TestContainers.Monad.TestContainer instance GHC.Base.Monad TestContainers.Monad.TestContainer instance GHC.Base.Applicative TestContainers.Monad.TestContainer instance GHC.Base.Functor TestContainers.Monad.TestContainer instance Control.Monad.IO.Unlift.MonadUnliftIO TestContainers.Monad.TestContainer instance Control.Monad.Reader.Class.MonadReader TestContainers.Monad.Config TestContainers.Monad.TestContainer instance GHC.Base.Semigroup a => GHC.Base.Semigroup (TestContainers.Monad.TestContainer a) instance GHC.Base.Monoid a => GHC.Base.Monoid (TestContainers.Monad.TestContainer a) module TestContainers.Docker.Internal -- | Failing to interact with Docker results in this exception being -- thrown. data DockerException DockerException :: ExitCode -> [Text] -> Text -> DockerException -- | Exit code of the underlying Docker process. [exitCode] :: DockerException -> ExitCode -- | Arguments that were passed to Docker. [args] :: DockerException -> [Text] -- | Docker's STDERR output. [stderr] :: DockerException -> Text InspectUnknownContainerId :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputInvalidJSON :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputMissingNetwork :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputUnexpected :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId UnknownPortMapping :: ContainerId -> Text -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId -- | Textual representation of port mapping we were trying to look up. [port] :: DockerException -> Text -- | Identifies a container within the Docker runtime. Assigned by -- docker run. type ContainerId = Text -- | The parsed JSON output of docker inspect command. type InspectOutput = Value -- | Identifies a network within the Docker runtime. Assigned by docker -- network create type NetworkId = Text -- | Internal function that runs Docker. Takes care of throwing an -- exception in case of failure. docker :: MonadIO m => Tracer -> [Text] -> m String -- | Internal function that runs Docker. Takes care of throwing an -- exception in case of failure. dockerWithStdin :: MonadIO m => Tracer -> [Text] -> Text -> m String -- | A data type indicating which pipe to scan for a specific log line. data Pipe -- | Refer to logs on STDOUT. Stdout :: Pipe -- | Refer to logs on STDERR. Stderr :: Pipe -- | An abstraction for forwarding logs. type LogConsumer = Pipe -> ByteString -> IO () -- | A simple LogConsumer that writes log lines to stdout and stderr -- respectively. consoleLogConsumer :: LogConsumer -- | Forwards container logs to a LogConsumer. This is equivalent of -- calling docker logs containerId --follow dockerFollowLogs :: MonadResource m => Tracer -> ContainerId -> LogConsumer -> m () instance GHC.Show.Show TestContainers.Docker.Internal.DockerException instance GHC.Classes.Eq TestContainers.Docker.Internal.DockerException instance GHC.Show.Show TestContainers.Docker.Internal.Pipe instance GHC.Classes.Ord TestContainers.Docker.Internal.Pipe instance GHC.Classes.Eq TestContainers.Docker.Internal.Pipe instance GHC.Exception.Type.Exception TestContainers.Docker.Internal.DockerException module TestContainers.Docker.State -- | State of a Docker container. data State -- | Extract the State of a Docker container from an -- InspectOutput. containerState :: InspectOutput -> State -- | Status of a Docker container. data Status Created :: Status Running :: Status Paused :: Status Restarting :: Status Removing :: Status Exited :: Status Dead :: Status Other :: Text -> Status -- | Returns the Status of container. stateStatus :: State -> Status -- | Whether a container was killed by the OOM killer. stateOOMKilled :: State -> Bool statePid :: State -> Maybe Int stateExitCode :: State -> Maybe Int stateError :: State -> Maybe Text stateStartedAt :: State -> Maybe Text stateFinishedAt :: State -> Maybe Text instance GHC.Show.Show TestContainers.Docker.State.StateInvalidException instance GHC.Classes.Eq TestContainers.Docker.State.StateInvalidException instance GHC.Show.Show TestContainers.Docker.State.Status instance GHC.Classes.Eq TestContainers.Docker.State.Status instance GHC.Exception.Type.Exception TestContainers.Docker.State.StateInvalidException module TestContainers.Docker.Network -- | Identifies a network within the Docker runtime. Assigned by docker -- network create type NetworkId = Text -- | Handle to a Docker network. data Network -- | Returns the id of the network. networkId :: Network -> NetworkId -- | Creates a new Network from a NetworkRequest. createNetwork :: NetworkRequest -> TestContainer Network -- | Parameters for creating a new Docker network. data NetworkRequest -- | Default parameters for creating a new Docker network. networkRequest :: NetworkRequest -- | Driver to manage the Network (default "bridge"). withDriver :: Text -> NetworkRequest -> NetworkRequest -- | Enable IPv6 for the Docker network. withIpv6 :: NetworkRequest -> NetworkRequest module TestContainers.Docker -- | Docker related functionality is parameterized over this Monad. -- Since 0.4.0.0 this is just a type alias for m ~ -- TestContainer. type MonadDocker m = (m ~ TestContainer) -- | The heart and soul of the testcontainers library. data TestContainer a -- | Configuration for defaulting behavior. data Config Config :: Maybe Int -> Tracer -> TestContainer Reaper -> Config -- | The number of seconds to maximally wait for a container to become -- ready. Default is `Just 60`. -- -- Nothing = waits indefinitely. [configDefaultWaitTimeout] :: Config -> Maybe Int -- | Traces execution inside testcontainers library. [configTracer] :: Config -> Tracer -- | How to obtain a Reaper [configCreateReaper] :: Config -> TestContainer Reaper -- | Default configuration. defaultDockerConfig :: Config -- | Autoselect the default configuration depending on wether you use -- Docker For Mac or not. determineConfig :: IO Config -- | Traces execution within testcontainers library. data Tracer -- | Type representing various events during testcontainer execution. data Trace -- | The low-level invocation of docker command -- --
--   TraceDockerInvocation args stdin exitcode
--   
TraceDockerInvocation :: [Text] -> Text -> ExitCode -> Trace -- | Preparations to follow the logs for a certain container TraceDockerFollowLogs :: [Text] -> Trace -- | Line written to STDOUT by a Docker process. TraceDockerStdout :: Text -> Trace -- | Line written to STDERR by a Docker process. TraceDockerStderr :: Text -> Trace -- | Waiting for a container to become ready. Attached with the timeout to -- wait (in seconds). TraceWaitUntilReady :: Maybe Int -> Trace -- | Opening socket TraceOpenSocket :: Text -> Int -> Maybe IOException -> Trace -- | Call HTTP endpoint TraceHttpCall :: Text -> Int -> Either String Int -> Trace -- | Construct a new Tracer from a tracing function. newTracer :: (Trace -> IO ()) -> Tracer withTrace :: MonadIO m => Tracer -> Trace -> m () -- | A tag to a Docker image. type ImageTag = Text -- | Handle to a Docker image. data Image -- | The image tag assigned by Docker. Uniquely identifies an Image -- within Docker. imageTag :: Image -> ImageTag -- | Defintion of a Port. Allows for specifying ports using various -- protocols. Due to the Num and IsString instance allows -- for convenient Haskell literals. -- --
--   >>> "80" :: Port
--   80/tcp
--   
-- --
--   >>> "80/tcp" :: Port
--   80/tcp
--   
-- --
--   >>> 80 :: Port
--   80/tcp
--   
-- --
--   >>> "90/udp" :: Port
--   90/udp
--   
data Port Port :: Int -> Text -> Port [$sel:port:Port] :: Port -> Int [$sel:protocol:Port] :: Port -> Text -- | Identifies a container within the Docker runtime. Assigned by -- docker run. type ContainerId = Text -- | Handle to a Docker container. data Container -- | Returns the id of the container. containerId :: Container -> ContainerId -- | Returns the underlying image of the container. containerImage :: Container -> Image -- | Get the container's network alias. Takes the first alias found. containerAlias :: Container -> Text -- | Get the IP address for the container's gateway, i.e. the host. Takes -- the first gateway address found. containerGateway :: Container -> Text -- | Looks up the ip address of the container. containerIp :: Container -> Text -- | Looks up an exposed port on the host. containerPort :: Container -> Port -> Int -- | Returns the domain and port exposing the given container's port. -- Differs from containerPort in that containerAddress will -- return the container's domain and port if the program is running in -- the same network. Otherwise, containerAddress will use the -- exposed port on the Docker host. containerAddress :: MonadIO m => Container -> Port -> m (Text, Int) -- | Returns the internal release key used for safely shutting down the -- container. Use this with care. This function is considered an internal -- detail. -- | Deprecated: Containers are cleaned up with a separate resource -- reaper. Releasing the container manually is not going to work. containerReleaseKey :: Container -> ReleaseKey -- | State of a Docker container. data State -- | Status of a Docker container. data Status Created :: Status Running :: Status Paused :: Status Restarting :: Status Removing :: Status Exited :: Status Dead :: Status Other :: Text -> Status stateError :: State -> Maybe Text stateExitCode :: State -> Maybe Int stateFinishedAt :: State -> Maybe Text -- | Whether a container was killed by the OOM killer. stateOOMKilled :: State -> Bool statePid :: State -> Maybe Int stateStartedAt :: State -> Maybe Text -- | Returns the Status of container. stateStatus :: State -> Status -- | successfulExit is supposed to be used in conjunction with -- waitForState. successfulExit :: State -> Bool -- | A description of how to build an Image. data ToImage -- | Get an Image from a tag. fromTag :: ImageTag -> ToImage -- | Build the image from a build path and an optional path to the -- Dockerfile (default is Dockerfile) fromBuildContext :: FilePath -> Maybe FilePath -> ToImage -- | Build a contextless image only from a Dockerfile passed as -- Text. fromDockerfile :: Text -> ToImage -- | Build the Image referred to by the argument. If the -- construction of the image is expensive (e.g. a call to -- fromBuildContext) we don't want to repeatedly build the image. -- Instead, build can be used to execute the underlying Docker -- build once and re-use the resulting Image. build :: ToImage -> TestContainer ToImage -- | Failing to interact with Docker results in this exception being -- thrown. data DockerException DockerException :: ExitCode -> [Text] -> Text -> DockerException -- | Exit code of the underlying Docker process. [exitCode] :: DockerException -> ExitCode -- | Arguments that were passed to Docker. [args] :: DockerException -> [Text] -- | Docker's STDERR output. [stderr] :: DockerException -> Text InspectUnknownContainerId :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputInvalidJSON :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputMissingNetwork :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputUnexpected :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId UnknownPortMapping :: ContainerId -> Text -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId -- | Textual representation of port mapping we were trying to look up. [port] :: DockerException -> Text -- | Parameters for a running a Docker container. data ContainerRequest -- | Default ContainerRequest. Used as base for every Docker -- container. containerRequest :: ToImage -> ContainerRequest -- | Sets labels for a container withLabels :: [(Text, Text)] -> ContainerRequest -> ContainerRequest -- | Set the name of a Docker container. This is equivalent to invoking -- docker run with the --name parameter. -- | Deprecated: See setFixedName setName :: Text -> ContainerRequest -> ContainerRequest -- | Set the name of a Docker container. This is equivalent to invoking -- docker run with the --name parameter. setFixedName :: Text -> ContainerRequest -> ContainerRequest -- | Set the name randomly suffixed of a Docker container. This is -- equivalent to invoking docker run with the --name -- parameter. setSuffixedName :: Text -> ContainerRequest -> ContainerRequest -- | Set the name randomly given of a Docker container. This is equivalent -- to omitting the --name parameter calling docker run. setRandomName :: ContainerRequest -> ContainerRequest -- | The command to execute inside the Docker container. This is the -- equivalent of passing the command on the docker run -- invocation. setCmd :: [Text] -> ContainerRequest -> ContainerRequest -- | The volume mounts to link to Docker container. This is the equivalent -- of passing the command on the docker run -v invocation. setVolumeMounts :: [(Text, Text)] -> ContainerRequest -> ContainerRequest -- | Wether to remove the container once exited. This is equivalent to -- passing --rm to docker run. (default is -- True). setRm :: Bool -> ContainerRequest -> ContainerRequest -- | Set the environment for the container. This is equivalent to passing -- --env key=value to docker run. setEnv :: [(Text, Text)] -> ContainerRequest -> ContainerRequest -- | Set the network the container will connect to. This is equivalent to -- passing --network network_name to docker run. setNetwork :: Text -> ContainerRequest -> ContainerRequest -- | Set the network the container will connect to. This is equivalent to -- passing --network network_name to docker run. withNetwork :: Network -> ContainerRequest -> ContainerRequest -- | Set the network alias for this container. This is equivalent to -- passing --network-alias alias to docker run. withNetworkAlias :: Text -> ContainerRequest -> ContainerRequest -- | Set link on the container. This is equivalent to passing --link -- other_container to docker run. setLink :: [ContainerId] -> ContainerRequest -> ContainerRequest -- | Set exposed ports on the container. This is equivalent to setting -- --publish $PORT to docker run. Docker assigns a -- random port for the host port. You will have to use containerIp -- and containerPort to connect to the published port. -- --
--   container <- run $ containerRequest redis & setExpose [ 6379 ]
--   let (redisHost, redisPort) = (containerIp container, containerPort container 6379)
--   print (redisHost, redisPort)
--   
setExpose :: [Port] -> ContainerRequest -> ContainerRequest -- | Set the waiting strategy on the container. Depending on a Docker -- container it can take some time until the provided service is ready. -- You will want to use to setWaitingFor to block until the -- container is ready to use. setWaitingFor :: WaitUntilReady -> ContainerRequest -> ContainerRequest -- | Runs a Docker container from an Image and -- ContainerRequest. A finalizer is registered so that the -- container is aways stopped when it goes out of scope. This function is -- essentially docker run. run :: ContainerRequest -> TestContainer Container -- | An abstraction for forwarding logs. type LogConsumer = Pipe -> ByteString -> IO () -- | A simple LogConsumer that writes log lines to stdout and stderr -- respectively. consoleLogConsumer :: LogConsumer -- | Forwards container logs to the given LogConsumer once ran. withFollowLogs :: LogConsumer -> ContainerRequest -> ContainerRequest -- | Identifies a network within the Docker runtime. Assigned by docker -- network create type NetworkId = Text -- | Handle to a Docker network. data Network -- | Parameters for creating a new Docker network. data NetworkRequest -- | Returns the id of the network. networkId :: Network -> NetworkId -- | Default parameters for creating a new Docker network. networkRequest :: NetworkRequest -- | Creates a new Network from a NetworkRequest. createNetwork :: NetworkRequest -> TestContainer Network -- | Enable IPv6 for the Docker network. withIpv6 :: NetworkRequest -> NetworkRequest -- | Driver to manage the Network (default "bridge"). withDriver :: Text -> NetworkRequest -> NetworkRequest -- | The parsed JSON output of docker inspect command. type InspectOutput = Value -- | Runs the `docker inspect` command. Memoizes the result. inspect :: Container -> TestContainer InspectOutput -- | Stops a Docker container. stop is essentially docker -- stop. stop :: Container -> TestContainer () -- | Kills a Docker container. kill is essentially docker -- kill. kill :: Container -> TestContainer () -- | Remove a Docker container. rm is essentially docker rm -- -f rm :: Container -> TestContainer () -- | Access STDOUT and STDERR of a running Docker container. This is -- essentially docker logs under the hood. withLogs :: Container -> (Handle -> Handle -> TestContainer a) -> TestContainer a -- | A strategy that describes how to asses readiness of a -- Container. Allows Users to plug in their definition of -- readiness. data WaitUntilReady -- | Blocks until the container is ready. waitUntilReady might throw -- exceptions depending on the used WaitUntilReady on the -- container. -- -- In case the readiness check times out waitUntilReady throws a -- TimeoutException. waitUntilReady :: Container -> WaitUntilReady -> TestContainer () -- | The exception thrown by waitUntilTimeout. newtype TimeoutException TimeoutException :: ContainerId -> TimeoutException -- | The id of the underlying container that was not ready in time. [$sel:id:TimeoutException] :: TimeoutException -> ContainerId -- | waitUntilTimeout n waitUntilReady waits n seconds -- for the container to be ready. If the container is not ready by then a -- TimeoutException will be thrown. waitUntilTimeout :: Int -> WaitUntilReady -> WaitUntilReady -- | waitForState waits for a certain state of the container. If -- the container reaches a terminal state InvalidStateException -- will be thrown. waitForState :: (State -> Bool) -> WaitUntilReady -- | A low-level primitive that allows scanning the logs for specific log -- lines that indicate readiness of a container. -- -- The Handles passed to the function argument represent -- stdout and stderr of the container. waitWithLogs :: (Container -> Handle -> Handle -> IO ()) -> WaitUntilReady -- | A data type indicating which pipe to scan for a specific log line. data Pipe -- | Refer to logs on STDOUT. Stdout :: Pipe -- | Refer to logs on STDERR. Stderr :: Pipe -- | The exception thrown by waitForLine in case the expected log -- line wasn't found. newtype UnexpectedEndOfPipe UnexpectedEndOfPipe :: ContainerId -> UnexpectedEndOfPipe -- | The id of the underlying container. [$sel:id:UnexpectedEndOfPipe] :: UnexpectedEndOfPipe -> ContainerId -- | Waits for a specific line to occur in the logs. Throws a -- UnexpectedEndOfPipe exception in case the desired line can not -- be found on the logs. -- -- Say you want to find "Ready to accept connections" in the logs on -- Stdout try: -- --
--   waitForLogLine Stdout ("Ready to accept connections" `isInfixOf`)
--   
waitForLogLine :: Pipe -> (Text -> Bool) -> WaitUntilReady dockerHostOs :: TestContainer Text isDockerOnLinux :: TestContainer Bool -- | Waits until the port of a container is ready to accept connections. -- This combinator should always be used with waitUntilTimeout. waitUntilMappedPortReachable :: Port -> WaitUntilReady -- | Waits for a specific http status code. This combinator should always -- be used with waitUntilTimeout. waitForHttp :: Port -> String -> [Int] -> WaitUntilReady -- | Sets up a Ryuk Reaper. createRyukReaper :: TestContainer Reaper -- | Convenient alias for ResourceT IO. type ResIO = ResourceT IO -- | Unwrap a ResourceT transformer, and call all registered release -- actions. -- -- Note that there is some reference counting involved due to -- resourceForkIO. If multiple threads are sharing the same -- collection of resources, only the last call to runResourceT -- will deallocate the resources. -- -- NOTE Since version 1.2.0, this function will throw a -- ResourceCleanupException if any of the cleanup functions throw -- an exception. runResourceT :: MonadUnliftIO m => ResourceT m a -> m a -- | & is a reverse application operator. This provides -- notational convenience. Its precedence is one higher than that of the -- forward application operator $, which allows & to be -- nested in $. -- --
--   >>> 5 & (+1) & show
--   "6"
--   
(&) :: a -> (a -> b) -> b infixl 1 & instance GHC.Classes.Ord TestContainers.Docker.Port instance GHC.Classes.Eq TestContainers.Docker.Port instance GHC.Show.Show TestContainers.Docker.UnexpectedEndOfPipe instance GHC.Classes.Eq TestContainers.Docker.UnexpectedEndOfPipe instance GHC.Show.Show TestContainers.Docker.TimeoutException instance GHC.Classes.Eq TestContainers.Docker.TimeoutException instance GHC.Show.Show TestContainers.Docker.InvalidStateException instance GHC.Classes.Eq TestContainers.Docker.InvalidStateException instance GHC.Show.Show TestContainers.Docker.Image instance GHC.Classes.Eq TestContainers.Docker.Image instance GHC.Base.Semigroup TestContainers.Docker.WaitUntilReady instance GHC.Base.Monoid TestContainers.Docker.WaitUntilReady instance GHC.Exception.Type.Exception TestContainers.Docker.InvalidStateException instance GHC.Exception.Type.Exception TestContainers.Docker.TimeoutException instance GHC.Exception.Type.Exception TestContainers.Docker.UnexpectedEndOfPipe instance GHC.Show.Show TestContainers.Docker.Port instance GHC.Num.Num TestContainers.Docker.Port instance Data.String.IsString TestContainers.Docker.Port module TestContainers.Config -- | Configuration for defaulting behavior. data Config Config :: Maybe Int -> Tracer -> TestContainer Reaper -> Config -- | The number of seconds to maximally wait for a container to become -- ready. Default is `Just 60`. -- -- Nothing = waits indefinitely. [configDefaultWaitTimeout] :: Config -> Maybe Int -- | Traces execution inside testcontainers library. [configTracer] :: Config -> Tracer -- | How to obtain a Reaper [configCreateReaper] :: Config -> TestContainer Reaper -- | Default configuration. defaultConfig :: Config -- | Default configuration. defaultDockerConfig :: Config -- | Autoselect the default configuration depending on wether you use -- Docker For Mac or not. determineConfig :: IO Config module TestContainers.Image -- | Image for Redis database. -- --
--   redis = fromTag "redis:5.0"
--   
redis :: ToImage -- | Image for Mongo database. -- --
--   mongo = Tag "mongo:4.0.17"
--   
mongo :: ToImage -- | Handle to a Docker image. data Image -- | A description of how to build an Image. data ToImage -- | Build the Image referred to by the argument. If the -- construction of the image is expensive (e.g. a call to -- fromBuildContext) we don't want to repeatedly build the image. -- Instead, build can be used to execute the underlying Docker -- build once and re-use the resulting Image. build :: ToImage -> TestContainer ToImage -- | Get an Image from a tag. fromTag :: ImageTag -> ToImage -- | Build the image from a build path and an optional path to the -- Dockerfile (default is Dockerfile) fromBuildContext :: FilePath -> Maybe FilePath -> ToImage -- | Build a contextless image only from a Dockerfile passed as -- Text. fromDockerfile :: Text -> ToImage -- | This module shall be used as entrypoint to the testcontainers library. -- It exports all the necessary types and functions for most common -- use-cases. module TestContainers -- | A tag to a Docker image. type ImageTag = Text -- | Handle to a Docker image. data Image -- | The image tag assigned by Docker. Uniquely identifies an Image -- within Docker. imageTag :: Image -> ImageTag -- | A description of how to build an Image. data ToImage -- | Get an Image from a tag. fromTag :: ImageTag -> ToImage -- | Build the image from a build path and an optional path to the -- Dockerfile (default is Dockerfile) fromBuildContext :: FilePath -> Maybe FilePath -> ToImage -- | Build the Image referred to by the argument. If the -- construction of the image is expensive (e.g. a call to -- fromBuildContext) we don't want to repeatedly build the image. -- Instead, build can be used to execute the underlying Docker -- build once and re-use the resulting Image. build :: ToImage -> TestContainer ToImage -- | Parameters for a running a Docker container. data ContainerRequest -- | Default ContainerRequest. Used as base for every Docker -- container. containerRequest :: ToImage -> ContainerRequest -- | Set the name of a Docker container. This is equivalent to invoking -- docker run with the --name parameter. -- | Deprecated: See setFixedName setName :: Text -> ContainerRequest -> ContainerRequest -- | Set the name of a Docker container. This is equivalent to invoking -- docker run with the --name parameter. setFixedName :: Text -> ContainerRequest -> ContainerRequest -- | Set the name randomly suffixed of a Docker container. This is -- equivalent to invoking docker run with the --name -- parameter. setSuffixedName :: Text -> ContainerRequest -> ContainerRequest -- | Set the name randomly given of a Docker container. This is equivalent -- to omitting the --name parameter calling docker run. setRandomName :: ContainerRequest -> ContainerRequest -- | The command to execute inside the Docker container. This is the -- equivalent of passing the command on the docker run -- invocation. setCmd :: [Text] -> ContainerRequest -> ContainerRequest -- | The volume mounts to link to Docker container. This is the equivalent -- of passing the command on the docker run -v invocation. setVolumeMounts :: [(Text, Text)] -> ContainerRequest -> ContainerRequest -- | Wether to remove the container once exited. This is equivalent to -- passing --rm to docker run. (default is -- True). setRm :: Bool -> ContainerRequest -> ContainerRequest -- | Set the environment for the container. This is equivalent to passing -- --env key=value to docker run. setEnv :: [(Text, Text)] -> ContainerRequest -> ContainerRequest -- | Set the network the container will connect to. This is equivalent to -- passing --network network_name to docker run. setNetwork :: Text -> ContainerRequest -> ContainerRequest -- | Set the network the container will connect to. This is equivalent to -- passing --network network_name to docker run. withNetwork :: Network -> ContainerRequest -> ContainerRequest -- | Set the network alias for this container. This is equivalent to -- passing --network-alias alias to docker run. withNetworkAlias :: Text -> ContainerRequest -> ContainerRequest -- | Set link on the container. This is equivalent to passing --link -- other_container to docker run. setLink :: [ContainerId] -> ContainerRequest -> ContainerRequest -- | Set exposed ports on the container. This is equivalent to setting -- --publish $PORT to docker run. Docker assigns a -- random port for the host port. You will have to use containerIp -- and containerPort to connect to the published port. -- --
--   container <- run $ containerRequest redis & setExpose [ 6379 ]
--   let (redisHost, redisPort) = (containerIp container, containerPort container 6379)
--   print (redisHost, redisPort)
--   
setExpose :: [Port] -> ContainerRequest -> ContainerRequest -- | Set the waiting strategy on the container. Depending on a Docker -- container it can take some time until the provided service is ready. -- You will want to use to setWaitingFor to block until the -- container is ready to use. setWaitingFor :: WaitUntilReady -> ContainerRequest -> ContainerRequest -- | Forwards container logs to the given LogConsumer once ran. withFollowLogs :: LogConsumer -> ContainerRequest -> ContainerRequest -- | An abstraction for forwarding logs. type LogConsumer = Pipe -> ByteString -> IO () -- | A simple LogConsumer that writes log lines to stdout and stderr -- respectively. consoleLogConsumer :: LogConsumer -- | Parameters for creating a new Docker network. data NetworkRequest -- | Default parameters for creating a new Docker network. networkRequest :: NetworkRequest -- | Driver to manage the Network (default "bridge"). withDriver :: Text -> NetworkRequest -> NetworkRequest -- | Enable IPv6 for the Docker network. withIpv6 :: NetworkRequest -> NetworkRequest -- | Handle to a Docker network. data Network -- | Identifies a network within the Docker runtime. Assigned by docker -- network create type NetworkId = Text -- | Creates a new Network from a NetworkRequest. createNetwork :: NetworkRequest -> TestContainer Network -- | Defintion of a Port. Allows for specifying ports using various -- protocols. Due to the Num and IsString instance allows -- for convenient Haskell literals. -- --
--   >>> "80" :: Port
--   80/tcp
--   
-- --
--   >>> "80/tcp" :: Port
--   80/tcp
--   
-- --
--   >>> 80 :: Port
--   80/tcp
--   
-- --
--   >>> "90/udp" :: Port
--   90/udp
--   
data Port Port :: Int -> Text -> Port [$sel:port:Port] :: Port -> Int [$sel:protocol:Port] :: Port -> Text -- | Handle to a Docker container. data Container -- | Get the container's network alias. Takes the first alias found. containerAlias :: Container -> Text -- | Get the IP address for the container's gateway, i.e. the host. Takes -- the first gateway address found. containerGateway :: Container -> Text -- | Looks up the ip address of the container. containerIp :: Container -> Text -- | Looks up an exposed port on the host. containerPort :: Container -> Port -> Int -- | Returns the domain and port exposing the given container's port. -- Differs from containerPort in that containerAddress will -- return the container's domain and port if the program is running in -- the same network. Otherwise, containerAddress will use the -- exposed port on the Docker host. containerAddress :: MonadIO m => Container -> Port -> m (Text, Int) -- | Returns the internal release key used for safely shutting down the -- container. Use this with care. This function is considered an internal -- detail. -- | Deprecated: Containers are cleaned up with a separate resource -- reaper. Releasing the container manually is not going to work. containerReleaseKey :: Container -> ReleaseKey -- | Returns the underlying image of the container. containerImage :: Container -> Image -- | Runs a Docker container from an Image and -- ContainerRequest. A finalizer is registered so that the -- container is aways stopped when it goes out of scope. This function is -- essentially docker run. run :: ContainerRequest -> TestContainer Container -- | The parsed JSON output of docker inspect command. type InspectOutput = Value -- | Runs the `docker inspect` command. Memoizes the result. inspect :: Container -> TestContainer InspectOutput -- | Stops a Docker container. stop is essentially docker -- stop. stop :: Container -> TestContainer () -- | Kills a Docker container. kill is essentially docker -- kill. kill :: Container -> TestContainer () -- | Remove a Docker container. rm is essentially docker rm -- -f rm :: Container -> TestContainer () -- | Access STDOUT and STDERR of a running Docker container. This is -- essentially docker logs under the hood. withLogs :: Container -> (Handle -> Handle -> TestContainer a) -> TestContainer a -- | A strategy that describes how to asses readiness of a -- Container. Allows Users to plug in their definition of -- readiness. data WaitUntilReady -- | waitUntilTimeout n waitUntilReady waits n seconds -- for the container to be ready. If the container is not ready by then a -- TimeoutException will be thrown. waitUntilTimeout :: Int -> WaitUntilReady -> WaitUntilReady -- | State of a Docker container. data State -- | Status of a Docker container. data Status Created :: Status Running :: Status Paused :: Status Restarting :: Status Removing :: Status Exited :: Status Dead :: Status Other :: Text -> Status stateError :: State -> Maybe Text stateExitCode :: State -> Maybe Int stateFinishedAt :: State -> Maybe Text -- | Whether a container was killed by the OOM killer. stateOOMKilled :: State -> Bool statePid :: State -> Maybe Int stateStartedAt :: State -> Maybe Text -- | Returns the Status of container. stateStatus :: State -> Status -- | waitForState waits for a certain state of the container. If -- the container reaches a terminal state InvalidStateException -- will be thrown. waitForState :: (State -> Bool) -> WaitUntilReady -- | successfulExit is supposed to be used in conjunction with -- waitForState. successfulExit :: State -> Bool -- | A data type indicating which pipe to scan for a specific log line. data Pipe -- | Refer to logs on STDOUT. Stdout :: Pipe -- | Refer to logs on STDERR. Stderr :: Pipe -- | A low-level primitive that allows scanning the logs for specific log -- lines that indicate readiness of a container. -- -- The Handles passed to the function argument represent -- stdout and stderr of the container. waitWithLogs :: (Container -> Handle -> Handle -> IO ()) -> WaitUntilReady -- | Waits for a specific line to occur in the logs. Throws a -- UnexpectedEndOfPipe exception in case the desired line can not -- be found on the logs. -- -- Say you want to find "Ready to accept connections" in the logs on -- Stdout try: -- --
--   waitForLogLine Stdout ("Ready to accept connections" `isInfixOf`)
--   
waitForLogLine :: Pipe -> (Text -> Bool) -> WaitUntilReady -- | Waits until the port of a container is ready to accept connections. -- This combinator should always be used with waitUntilTimeout. waitUntilMappedPortReachable :: Port -> WaitUntilReady -- | Waits for a specific http status code. This combinator should always -- be used with waitUntilTimeout. waitForHttp :: Port -> String -> [Int] -> WaitUntilReady -- | Docker related functionality is parameterized over this Monad. -- Since 0.4.0.0 this is just a type alias for m ~ -- TestContainer. type MonadDocker m = (m ~ TestContainer) -- | The heart and soul of the testcontainers library. data TestContainer a -- | Configuration for defaulting behavior. data Config Config :: Maybe Int -> Tracer -> TestContainer Reaper -> Config -- | The number of seconds to maximally wait for a container to become -- ready. Default is `Just 60`. -- -- Nothing = waits indefinitely. [configDefaultWaitTimeout] :: Config -> Maybe Int -- | Traces execution inside testcontainers library. [configTracer] :: Config -> Tracer -- | How to obtain a Reaper [configCreateReaper] :: Config -> TestContainer Reaper -- | Default configuration. defaultDockerConfig :: Config -- | Autoselect the default configuration depending on wether you use -- Docker For Mac or not. determineConfig :: IO Config -- | Traces execution within testcontainers library. data Tracer -- | Type representing various events during testcontainer execution. data Trace -- | The low-level invocation of docker command -- --
--   TraceDockerInvocation args stdin exitcode
--   
TraceDockerInvocation :: [Text] -> Text -> ExitCode -> Trace -- | Preparations to follow the logs for a certain container TraceDockerFollowLogs :: [Text] -> Trace -- | Line written to STDOUT by a Docker process. TraceDockerStdout :: Text -> Trace -- | Line written to STDERR by a Docker process. TraceDockerStderr :: Text -> Trace -- | Waiting for a container to become ready. Attached with the timeout to -- wait (in seconds). TraceWaitUntilReady :: Maybe Int -> Trace -- | Opening socket TraceOpenSocket :: Text -> Int -> Maybe IOException -> Trace -- | Call HTTP endpoint TraceHttpCall :: Text -> Int -> Either String Int -> Trace -- | Construct a new Tracer from a tracing function. newTracer :: (Trace -> IO ()) -> Tracer -- | Failing to interact with Docker results in this exception being -- thrown. data DockerException DockerException :: ExitCode -> [Text] -> Text -> DockerException -- | Exit code of the underlying Docker process. [exitCode] :: DockerException -> ExitCode -- | Arguments that were passed to Docker. [args] :: DockerException -> [Text] -- | Docker's STDERR output. [stderr] :: DockerException -> Text InspectUnknownContainerId :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputInvalidJSON :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputMissingNetwork :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputUnexpected :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId UnknownPortMapping :: ContainerId -> Text -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId -- | Textual representation of port mapping we were trying to look up. [port] :: DockerException -> Text -- | The exception thrown by waitUntilTimeout. newtype TimeoutException TimeoutException :: ContainerId -> TimeoutException -- | The id of the underlying container that was not ready in time. [$sel:id:TimeoutException] :: TimeoutException -> ContainerId -- | The exception thrown by waitForLine in case the expected log -- line wasn't found. newtype UnexpectedEndOfPipe UnexpectedEndOfPipe :: ContainerId -> UnexpectedEndOfPipe -- | The id of the underlying container. [$sel:id:UnexpectedEndOfPipe] :: UnexpectedEndOfPipe -> ContainerId dockerHostOs :: TestContainer Text isDockerOnLinux :: TestContainer Bool -- | Image for Redis database. -- --
--   redis = fromTag "redis:5.0"
--   
redis :: ToImage -- | Image for Mongo database. -- --
--   mongo = Tag "mongo:4.0.17"
--   
mongo :: ToImage -- | Convenient alias for ResourceT IO. type ResIO = ResourceT IO -- | Unwrap a ResourceT transformer, and call all registered release -- actions. -- -- Note that there is some reference counting involved due to -- resourceForkIO. If multiple threads are sharing the same -- collection of resources, only the last call to runResourceT -- will deallocate the resources. -- -- NOTE Since version 1.2.0, this function will throw a -- ResourceCleanupException if any of the cleanup functions throw -- an exception. runResourceT :: MonadUnliftIO m => ResourceT m a -> m a -- | & is a reverse application operator. This provides -- notational convenience. Its precedence is one higher than that of the -- forward application operator $, which allows & to be -- nested in $. -- --
--   >>> 5 & (+1) & show
--   "6"
--   
(&) :: a -> (a -> b) -> b infixl 1 & module TestContainers.Tasty -- | Tasty Ingredient that adds useful options to control defaults -- within the TetContainers library. -- --
--   main :: IO ()
--   main = defaultMainWithIngredients (ingredient : defaultIngredients) tests
--   
ingredient :: Ingredient withContainers :: forall a. TestContainer a -> (IO a -> TestTree) -> TestTree -- | & is a reverse application operator. This provides -- notational convenience. Its precedence is one higher than that of the -- forward application operator $, which allows & to be -- nested in $. -- --
--   >>> 5 & (+1) & show
--   "6"
--   
(&) :: a -> (a -> b) -> b infixl 1 & -- | Unwrap a ResourceT transformer, and call all registered release -- actions. -- -- Note that there is some reference counting involved due to -- resourceForkIO. If multiple threads are sharing the same -- collection of resources, only the last call to runResourceT -- will deallocate the resources. -- -- NOTE Since version 1.2.0, this function will throw a -- ResourceCleanupException if any of the cleanup functions throw -- an exception. runResourceT :: MonadUnliftIO m => ResourceT m a -> m a -- | Convenient alias for ResourceT IO. type ResIO = ResourceT IO -- | Traces execution within testcontainers library. data Tracer -- | Call HTTP endpoint pattern TraceHttpCall :: () => Text -> Int -> Either String Int -> Trace -- | Opening socket pattern TraceOpenSocket :: () => Text -> Int -> Maybe IOException -> Trace -- | Waiting for a container to become ready. Attached with the timeout to -- wait (in seconds). pattern TraceWaitUntilReady :: () => Maybe Int -> Trace -- | Line written to STDERR by a Docker process. pattern TraceDockerStderr :: () => Text -> Trace -- | Line written to STDOUT by a Docker process. pattern TraceDockerStdout :: () => Text -> Trace -- | The low-level invocation of docker command -- --
--   TraceDockerInvocation args stdin exitcode
--   
pattern TraceDockerInvocation :: () => [Text] -> Text -> ExitCode -> Trace -- | Preparations to follow the logs for a certain container pattern TraceDockerFollowLogs :: () => [Text] -> Trace -- | Construct a new Tracer from a tracing function. newTracer :: (Trace -> IO ()) -> Tracer -- | Configuration for defaulting behavior. data Config Config :: Maybe Int -> Tracer -> TestContainer Reaper -> Config -- | The number of seconds to maximally wait for a container to become -- ready. Default is `Just 60`. -- -- Nothing = waits indefinitely. [configDefaultWaitTimeout] :: Config -> Maybe Int -- | Traces execution inside testcontainers library. [configTracer] :: Config -> Tracer -- | How to obtain a Reaper [configCreateReaper] :: Config -> TestContainer Reaper -- | Docker related functionality is parameterized over this Monad. -- Since 0.4.0.0 this is just a type alias for m ~ -- TestContainer. type MonadDocker m = (m ~ TestContainer) -- | The heart and soul of the testcontainers library. data TestContainer a -- | Default configuration. defaultDockerConfig :: Config -- | Autoselect the default configuration depending on wether you use -- Docker For Mac or not. determineConfig :: IO Config -- | An abstraction for forwarding logs. type LogConsumer = Pipe -> ByteString -> IO () -- | A data type indicating which pipe to scan for a specific log line. data Pipe -- | Refer to logs on STDOUT. Stdout :: Pipe -- | Refer to logs on STDERR. Stderr :: Pipe -- | Failing to interact with Docker results in this exception being -- thrown. data DockerException DockerException :: ExitCode -> [Text] -> Text -> DockerException -- | Exit code of the underlying Docker process. [exitCode] :: DockerException -> ExitCode -- | Arguments that were passed to Docker. [args] :: DockerException -> [Text] -- | Docker's STDERR output. [stderr] :: DockerException -> Text InspectUnknownContainerId :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputInvalidJSON :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputMissingNetwork :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId InspectOutputUnexpected :: ContainerId -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId UnknownPortMapping :: ContainerId -> Text -> DockerException -- | Id of the Container that we tried to lookup the port mapping. [id] :: DockerException -> ContainerId -- | Textual representation of port mapping we were trying to look up. [port] :: DockerException -> Text -- | The parsed JSON output of docker inspect command. type InspectOutput = Value -- | Identifies a network within the Docker runtime. Assigned by docker -- network create type NetworkId = Text -- | A simple LogConsumer that writes log lines to stdout and stderr -- respectively. consoleLogConsumer :: LogConsumer -- | State of a Docker container. data State -- | Status of a Docker container. data Status Created :: Status Running :: Status Paused :: Status Restarting :: Status Removing :: Status Exited :: Status Dead :: Status Other :: Text -> Status -- | Returns the Status of container. stateStatus :: State -> Status -- | Whether a container was killed by the OOM killer. stateOOMKilled :: State -> Bool statePid :: State -> Maybe Int stateExitCode :: State -> Maybe Int stateError :: State -> Maybe Text stateStartedAt :: State -> Maybe Text stateFinishedAt :: State -> Maybe Text -- | Parameters for creating a new Docker network. data NetworkRequest -- | Handle to a Docker network. data Network -- | Default parameters for creating a new Docker network. networkRequest :: NetworkRequest -- | Enable IPv6 for the Docker network. withIpv6 :: NetworkRequest -> NetworkRequest -- | Driver to manage the Network (default "bridge"). withDriver :: Text -> NetworkRequest -> NetworkRequest -- | Creates a new Network from a NetworkRequest. createNetwork :: NetworkRequest -> TestContainer Network -- | Handle to a Docker container. data Container -- | Handle to a Docker image. data Image -- | The exception thrown by waitUntilTimeout. newtype TimeoutException TimeoutException :: ContainerId -> TimeoutException -- | The id of the underlying container that was not ready in time. [$sel:id:TimeoutException] :: TimeoutException -> ContainerId -- | The exception thrown by waitForLine in case the expected log -- line wasn't found. newtype UnexpectedEndOfPipe UnexpectedEndOfPipe :: ContainerId -> UnexpectedEndOfPipe -- | The id of the underlying container. [$sel:id:UnexpectedEndOfPipe] :: UnexpectedEndOfPipe -> ContainerId -- | A strategy that describes how to asses readiness of a -- Container. Allows Users to plug in their definition of -- readiness. data WaitUntilReady -- | A description of how to build an Image. data ToImage -- | A tag to a Docker image. type ImageTag = Text -- | Defintion of a Port. Allows for specifying ports using various -- protocols. Due to the Num and IsString instance allows -- for convenient Haskell literals. -- --
--   >>> "80" :: Port
--   80/tcp
--   
-- --
--   >>> "80/tcp" :: Port
--   80/tcp
--   
-- --
--   >>> 80 :: Port
--   80/tcp
--   
-- --
--   >>> "90/udp" :: Port
--   90/udp
--   
data Port Port :: Int -> Text -> Port [$sel:port:Port] :: Port -> Int [$sel:protocol:Port] :: Port -> Text -- | Parameters for a running a Docker container. data ContainerRequest -- | Default ContainerRequest. Used as base for every Docker -- container. containerRequest :: ToImage -> ContainerRequest -- | Set the name of a Docker container. This is equivalent to invoking -- docker run with the --name parameter. -- | Deprecated: See setFixedName setName :: Text -> ContainerRequest -> ContainerRequest -- | Set the name of a Docker container. This is equivalent to invoking -- docker run with the --name parameter. setFixedName :: Text -> ContainerRequest -> ContainerRequest -- | Set the name randomly given of a Docker container. This is equivalent -- to omitting the --name parameter calling docker run. setRandomName :: ContainerRequest -> ContainerRequest -- | Set the name randomly suffixed of a Docker container. This is -- equivalent to invoking docker run with the --name -- parameter. setSuffixedName :: Text -> ContainerRequest -> ContainerRequest -- | The command to execute inside the Docker container. This is the -- equivalent of passing the command on the docker run -- invocation. setCmd :: [Text] -> ContainerRequest -> ContainerRequest -- | The volume mounts to link to Docker container. This is the equivalent -- of passing the command on the docker run -v invocation. setVolumeMounts :: [(Text, Text)] -> ContainerRequest -> ContainerRequest -- | Wether to remove the container once exited. This is equivalent to -- passing --rm to docker run. (default is -- True). setRm :: Bool -> ContainerRequest -> ContainerRequest -- | Set the environment for the container. This is equivalent to passing -- --env key=value to docker run. setEnv :: [(Text, Text)] -> ContainerRequest -> ContainerRequest -- | Set the network the container will connect to. This is equivalent to -- passing --network network_name to docker run. setNetwork :: Text -> ContainerRequest -> ContainerRequest -- | Set the network the container will connect to. This is equivalent to -- passing --network network_name to docker run. withNetwork :: Network -> ContainerRequest -> ContainerRequest -- | Set the network alias for this container. This is equivalent to -- passing --network-alias alias to docker run. withNetworkAlias :: Text -> ContainerRequest -> ContainerRequest -- | Set link on the container. This is equivalent to passing --link -- other_container to docker run. setLink :: [ContainerId] -> ContainerRequest -> ContainerRequest -- | Forwards container logs to the given LogConsumer once ran. withFollowLogs :: LogConsumer -> ContainerRequest -> ContainerRequest -- | Set exposed ports on the container. This is equivalent to setting -- --publish $PORT to docker run. Docker assigns a -- random port for the host port. You will have to use containerIp -- and containerPort to connect to the published port. -- --
--   container <- run $ containerRequest redis & setExpose [ 6379 ]
--   let (redisHost, redisPort) = (containerIp container, containerPort container 6379)
--   print (redisHost, redisPort)
--   
setExpose :: [Port] -> ContainerRequest -> ContainerRequest -- | Set the waiting strategy on the container. Depending on a Docker -- container it can take some time until the provided service is ready. -- You will want to use to setWaitingFor to block until the -- container is ready to use. setWaitingFor :: WaitUntilReady -> ContainerRequest -> ContainerRequest -- | Runs a Docker container from an Image and -- ContainerRequest. A finalizer is registered so that the -- container is aways stopped when it goes out of scope. This function is -- essentially docker run. run :: ContainerRequest -> TestContainer Container -- | Kills a Docker container. kill is essentially docker -- kill. kill :: Container -> TestContainer () -- | Stops a Docker container. stop is essentially docker -- stop. stop :: Container -> TestContainer () -- | Remove a Docker container. rm is essentially docker rm -- -f rm :: Container -> TestContainer () -- | Access STDOUT and STDERR of a running Docker container. This is -- essentially docker logs under the hood. withLogs :: Container -> (Handle -> Handle -> TestContainer a) -> TestContainer a -- | Build the Image referred to by the argument. If the -- construction of the image is expensive (e.g. a call to -- fromBuildContext) we don't want to repeatedly build the image. -- Instead, build can be used to execute the underlying Docker -- build once and re-use the resulting Image. build :: ToImage -> TestContainer ToImage -- | Get an Image from a tag. fromTag :: ImageTag -> ToImage -- | Build the image from a build path and an optional path to the -- Dockerfile (default is Dockerfile) fromBuildContext :: FilePath -> Maybe FilePath -> ToImage -- | waitForState waits for a certain state of the container. If -- the container reaches a terminal state InvalidStateException -- will be thrown. waitForState :: (State -> Bool) -> WaitUntilReady -- | successfulExit is supposed to be used in conjunction with -- waitForState. successfulExit :: State -> Bool -- | waitUntilTimeout n waitUntilReady waits n seconds -- for the container to be ready. If the container is not ready by then a -- TimeoutException will be thrown. waitUntilTimeout :: Int -> WaitUntilReady -> WaitUntilReady -- | Waits for a specific http status code. This combinator should always -- be used with waitUntilTimeout. waitForHttp :: Port -> String -> [Int] -> WaitUntilReady -- | Waits until the port of a container is ready to accept connections. -- This combinator should always be used with waitUntilTimeout. waitUntilMappedPortReachable :: Port -> WaitUntilReady -- | A low-level primitive that allows scanning the logs for specific log -- lines that indicate readiness of a container. -- -- The Handles passed to the function argument represent -- stdout and stderr of the container. waitWithLogs :: (Container -> Handle -> Handle -> IO ()) -> WaitUntilReady -- | Waits for a specific line to occur in the logs. Throws a -- UnexpectedEndOfPipe exception in case the desired line can not -- be found on the logs. -- -- Say you want to find "Ready to accept connections" in the logs on -- Stdout try: -- --
--   waitForLogLine Stdout ("Ready to accept connections" `isInfixOf`)
--   
waitForLogLine :: Pipe -> (Text -> Bool) -> WaitUntilReady -- | The image tag assigned by Docker. Uniquely identifies an Image -- within Docker. imageTag :: Image -> ImageTag -- | Returns the underlying image of the container. containerImage :: Container -> Image -- | Returns the internal release key used for safely shutting down the -- container. Use this with care. This function is considered an internal -- detail. -- | Deprecated: Containers are cleaned up with a separate resource -- reaper. Releasing the container manually is not going to work. containerReleaseKey :: Container -> ReleaseKey -- | Looks up the ip address of the container. containerIp :: Container -> Text -- | Get the container's network alias. Takes the first alias found. containerAlias :: Container -> Text -- | Get the IP address for the container's gateway, i.e. the host. Takes -- the first gateway address found. containerGateway :: Container -> Text -- | Looks up an exposed port on the host. containerPort :: Container -> Port -> Int -- | Returns the domain and port exposing the given container's port. -- Differs from containerPort in that containerAddress will -- return the container's domain and port if the program is running in -- the same network. Otherwise, containerAddress will use the -- exposed port on the Docker host. containerAddress :: MonadIO m => Container -> Port -> m (Text, Int) -- | Runs the `docker inspect` command. Memoizes the result. inspect :: Container -> TestContainer InspectOutput dockerHostOs :: TestContainer Text isDockerOnLinux :: TestContainer Bool -- | Image for Redis database. -- --
--   redis = fromTag "redis:5.0"
--   
redis :: ToImage -- | Image for Mongo database. -- --
--   mongo = Tag "mongo:4.0.17"
--   
mongo :: ToImage instance Test.Tasty.Options.IsOption TestContainers.Tasty.Trace instance Test.Tasty.Options.IsOption TestContainers.Tasty.DefaultTimeout module TestContainers.Hspec -- | Allow Spec to depend on Docker containers. Hspec takes care of -- initialization and de-initialization of the containers. -- --
--   containers :: MonadDocker m => m Boolean
--   containers = do
--     _redis <- TestContainers.run $ TestContainers.containerRequest TestContainers.redis
--     _kafka <- TestContainers.run $ TestContainers.containerRequest TestContainers.kafka
--     pure True
--   
--   example :: Spec
--   example =
--     around (withContainers containers) $ describe "Example tests"
--       it "first test" $ \isBoolean -> do
--         isBoolean shouldBe True
--   
-- -- withContainers allows you naturally scope the handling of -- containers for your tests. withContainers :: forall a. TestContainer a -> (a -> IO ()) -> IO ()