Skip to content

Commit

Permalink
0.5.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbiehl committed Feb 20, 2023
1 parent 488633a commit e4d5755
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Revision history for testcontainer-hs

## 0.4.0.0 -- 2023-02-20
## 0.5.0.0 -- 2023-02-20

* BREAKING: Refined lifecycle management. testcontainers is now using testcontainers/ryuk resource reaper to cleanup containers, networks and volumes. Release keys for containers are deprecated. (@alexbiehl, https://github.com/testcontainers/testcontainers-hs/pull/33)

Expand Down
2 changes: 1 addition & 1 deletion src/TestContainers/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TestContainers.Monad (Config (..))

-- | Default configuration.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
defaultConfig :: Config
defaultConfig =
Config
Expand Down
40 changes: 20 additions & 20 deletions src/TestContainers/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ data ContainerRequest = ContainerRequest

-- | Parameters for a naming a Docker container.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
data NamingStrategy
= RandomName
| FixedName Text
Expand Down Expand Up @@ -319,7 +319,7 @@ setName = setFixedName
-- | Set the name of a Docker container. This is equivalent to invoking @docker run@
-- with the @--name@ parameter.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
setFixedName :: Text -> ContainerRequest -> ContainerRequest
setFixedName newName req =
-- TODO error on empty Text
Expand All @@ -328,7 +328,7 @@ setFixedName newName req =
-- | Set the name randomly given of a Docker container. This is equivalent to omitting
-- the @--name@ parameter calling @docker run@.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
setRandomName :: ContainerRequest -> ContainerRequest
setRandomName req =
-- TODO error on empty Text
Expand All @@ -337,7 +337,7 @@ setRandomName req =
-- | Set the name randomly suffixed of a Docker container. This is equivalent to invoking
-- @docker run@ with the @--name@ parameter.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
setSuffixedName :: Text -> ContainerRequest -> ContainerRequest
setSuffixedName preffix req =
-- TODO error on empty Text
Expand Down Expand Up @@ -376,22 +376,22 @@ setEnv newEnv req =
-- | Set the network the container will connect to. This is equivalent to passing
-- @--network network_name@ to @docker run@.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
withNetwork :: Network -> ContainerRequest -> ContainerRequest
withNetwork network req =
req {network = Just (Left network)}

-- | Set the network alias for this container. This is equivalent to passing
-- @--network-alias alias@ to @docker run@.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
withNetworkAlias :: Text -> ContainerRequest -> ContainerRequest
withNetworkAlias alias req =
req {networkAlias = Just alias}

-- | Sets labels for a container
--
-- @since 0.4.0.0
-- @since 0.5.0.0
withLabels :: [(Text, Text)] -> ContainerRequest -> ContainerRequest
withLabels xs request =
request {labels = xs}
Expand All @@ -406,7 +406,7 @@ setLink newLink req =

-- | Forwards container logs to the given 'LogConsumer' once ran.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
withFollowLogs :: LogConsumer -> ContainerRequest -> ContainerRequest
withFollowLogs logConsumer request =
request {followLogs = Just logConsumer}
Expand Down Expand Up @@ -434,14 +434,14 @@ data Port = Port
defaultProtocol :: Text
defaultProtocol = "tcp"

-- @since 0.4.0.0
-- @since 0.5.0.0
instance Show Port where
show Port {port, protocol} =
show port <> "/" <> unpack protocol

-- | A cursed but handy instance supporting literal 'Port's.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
instance Num Port where
fromInteger x =
Port {port = fromIntegral x, protocol = defaultProtocol}
Expand All @@ -454,7 +454,7 @@ instance Num Port where
-- | A cursed but handy instance supporting literal 'Port's of them
-- form @"8080"@, @"8080/udp"@, @"8080/tcp"@.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
instance IsString Port where
fromString input = case splitOn "/" (pack input) of
[numberish]
Expand Down Expand Up @@ -586,7 +586,7 @@ run request = do

-- | Sets up a Ryuk 'Reaper'.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
createRyukReaper :: TestContainer Reaper
createRyukReaper = do
ryukContainer <-
Expand Down Expand Up @@ -768,11 +768,11 @@ data WaitUntilReady
-- Next check
WaitUntilReady

-- | @since 0.4.0.0
-- | @since 0.5.0.0
instance Semigroup WaitUntilReady where
(<>) = WaitMany

-- | @since 0.4.0.0
-- | @since 0.5.0.0
instance Monoid WaitUntilReady where
mempty = WaitReady mempty

Expand Down Expand Up @@ -813,7 +813,7 @@ instance Exception InvalidStateException
-- | @waitForState@ waits for a certain state of the container. If the container reaches a terminal
-- state 'InvalidStateException' will be thrown.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
waitForState :: (State -> Bool) -> WaitUntilReady
waitForState isReady = WaitReady $ \Container {id} -> do
let wait = do
Expand Down Expand Up @@ -841,7 +841,7 @@ waitForState isReady = WaitReady $ \Container {id} -> do

-- | @successfulExit@ is supposed to be used in conjunction with 'waitForState'.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
successfulExit :: State -> Bool
successfulExit state =
stateStatus state == Exited && stateExitCode state == Just 0
Expand All @@ -857,7 +857,7 @@ waitUntilTimeout = WaitUntilTimeout
-- | Waits for a specific http status code.
-- This combinator should always be used with `waitUntilTimeout`.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
waitForHttp ::
-- | Port
Port ->
Expand Down Expand Up @@ -1097,7 +1097,7 @@ internalContainerIp Container {id, inspectOutput} =
-- | Get the container's network alias.
-- Takes the first alias found.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
containerAlias :: Container -> Text
containerAlias Container {id, inspectOutput} =
case inspectOutput
Expand All @@ -1120,7 +1120,7 @@ containerAlias Container {id, inspectOutput} =
-- | Get the IP address for the container's gateway, i.e. the host.
-- Takes the first gateway address found.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
containerGateway :: Container -> Text
containerGateway Container {id, inspectOutput} =
case inspectOutput
Expand Down Expand Up @@ -1174,7 +1174,7 @@ containerPort Container {id, inspectOutput} Port {port, protocol} =
-- domain and port if the program is running in the same network. Otherwise,
-- 'containerAddress' will use the exposed port on the Docker host.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
containerAddress :: Container -> Port -> (Text, Int)
containerAddress container Port {port, protocol} =
let inDocker = unsafePerformIO isRunningInDocker
Expand Down
8 changes: 4 additions & 4 deletions src/TestContainers/Docker/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import TestContainers.Trace (Trace (..), Tracer, withTrace)

-- | Identifies a network within the Docker runtime. Assigned by @docker network create@
--
-- @since 0.4.0.0
-- @since 0.5.0.0
type NetworkId = Text

-- | Identifies a container within the Docker runtime. Assigned by @docker run@.
Expand Down Expand Up @@ -132,12 +132,12 @@ data Pipe

-- | An abstraction for forwarding logs.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
type LogConsumer = Pipe -> ByteString -> IO ()

-- | A simple 'LogConsumer' that writes log lines to stdout and stderr respectively.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
consoleLogConsumer :: LogConsumer
consoleLogConsumer pipe line = do
case pipe of
Expand All @@ -150,7 +150,7 @@ consoleLogConsumer pipe line = do

-- | Forwards container logs to a 'LogConsumer'. This is equivalent of calling @docker logs containerId --follow@
--
-- @since 0.4.0.0
-- @since 0.5.0.0
dockerFollowLogs :: (MonadResource m) => Tracer -> ContainerId -> LogConsumer -> m ()
dockerFollowLogs tracer containerId logConsumer = do
let dockerArgs =
Expand Down
14 changes: 7 additions & 7 deletions src/TestContainers/Docker/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ import Prelude hiding (id)

-- | Handle to a Docker network.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
newtype Network = Network
{ id :: NetworkId
}

-- | Returns the id of the network.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
networkId :: Network -> NetworkId
networkId Network {id} = id

-- | Parameters for creating a new Docker network.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
data NetworkRequest = NetworkRequest
{ ipv6 :: Bool,
driver :: Maybe Text,
Expand All @@ -51,7 +51,7 @@ data NetworkRequest = NetworkRequest

-- | Default parameters for creating a new Docker network.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
networkRequest :: NetworkRequest
networkRequest =
NetworkRequest
Expand All @@ -62,21 +62,21 @@ networkRequest =

-- | Enable IPv6 for the Docker network.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
withIpv6 :: NetworkRequest -> NetworkRequest
withIpv6 request =
request {ipv6 = True}

-- | Driver to manage the Network (default "bridge").
--
-- @since 0.4.0.0
-- @since 0.5.0.0
withDriver :: Text -> NetworkRequest -> NetworkRequest
withDriver driver request =
request {driver = Just driver}

-- | Creates a new 'Network' from a 'NetworkRequest'.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
createNetwork :: NetworkRequest -> TestContainer Network
createNetwork NetworkRequest {..} = do
Config {..} <- ask
Expand Down
12 changes: 6 additions & 6 deletions src/TestContainers/Docker/Reaper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import qualified System.Random as Random

-- | Reaper for safe resource cleanup.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
data Reaper = Reaper
{ -- | @runReaper label value@ reaps Docker any Docker resource with a matching
-- label.
Expand All @@ -37,33 +37,33 @@ data Reaper = 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.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
reaperLabels :: Reaper -> [(Text, Text)]
reaperLabels Reaper {labels} =
labels

-- | Ryuk based resource reaper
--
-- @since 0.4.0.0
-- @since 0.5.0.0
newtype Ryuk = Ryuk {ryukSocket :: Socket.Socket}

-- | Tag for the ryuk image
--
-- @since 0.4.0.0
-- @since 0.5.0.0
ryukImageTag :: Text
ryukImageTag =
"docker.io/testcontainers/ryuk:0.3.4"

-- | Exposed port for the ryuk reaper.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
ryukPort :: (Num a) => a
ryukPort =
8080

-- | Creates a new 'Reaper' from a host and port.
--
-- @since 0.4.0.0
-- @since 0.5.0.0
newRyukReaper ::
(MonadResource m) =>
-- | Host
Expand Down
Loading

0 comments on commit e4d5755

Please sign in to comment.