|
7 | 7 | -- Stability : experimental |
8 | 8 | -- Portability : POSIX |
9 | 9 | module Restyler.CodeVolume |
10 | | - ( withCodeVolume |
| 10 | + ( VolumeName (..) |
| 11 | + , withCodeVolume |
11 | 12 | ) where |
12 | 13 |
|
13 | 14 | import Restyler.Prelude |
14 | 15 |
|
15 | 16 | import Restyler.Monad.Docker |
16 | 17 | import UnliftIO.Exception (bracket) |
17 | 18 |
|
18 | | -withCodeVolume :: (MonadDocker m, MonadUnliftIO m) => (String -> m a) -> m a |
19 | | -withCodeVolume = bracket acquire dockerVolumeRm |
| 19 | +newtype VolumeName = VolumeName |
| 20 | + { unwrap :: String |
| 21 | + } |
| 22 | + |
| 23 | +withCodeVolume :: (MonadDocker m, MonadUnliftIO m) => (VolumeName -> m a) -> m a |
| 24 | +withCodeVolume = bracket acquire (dockerVolumeRm . (.unwrap)) |
20 | 25 | where |
21 | | - acquire :: (MonadDocker m, MonadUnliftIO m) => m String |
| 26 | + acquire :: (MonadDocker m, MonadUnliftIO m) => m VolumeName |
22 | 27 | acquire = withVolumeInContainer tmpVolumeName $ \cName cPath -> do |
23 | | - tmpVolumeName <$ dockerCp "." (cName <> ":" <> cPath) |
| 28 | + tmpVolumeName <$ dockerCp "." (cName.unwrap <> ":" <> cPath.unwrap) |
| 29 | + |
| 30 | +newtype ContainerName = ContainerName |
| 31 | + { unwrap :: String |
| 32 | + } |
| 33 | + |
| 34 | +newtype ContainerPath = ContainerPath |
| 35 | + { unwrap :: FilePath |
| 36 | + } |
24 | 37 |
|
25 | 38 | withVolumeInContainer |
26 | 39 | :: (MonadDocker m, MonadUnliftIO m) |
27 | | - => String |
28 | | - -> (String -> FilePath -> m a) |
| 40 | + => VolumeName |
| 41 | + -> (ContainerName -> ContainerPath -> m a) |
29 | 42 | -> m a |
30 | | -withVolumeInContainer name = bracket acquire (dockerRm . fst) . uncurry |
| 43 | +withVolumeInContainer name = |
| 44 | + bracket acquire (dockerRm . (.unwrap) . fst) . uncurry |
31 | 45 | where |
32 | | - acquire :: MonadDocker m => m (String, FilePath) |
| 46 | + acquire :: MonadDocker m => m (ContainerName, ContainerPath) |
33 | 47 | acquire = do |
34 | 48 | dockerCreate |
35 | | - $ ["--name", tmpContainerName] |
36 | | - <> ["--volume", name <> ":" <> tmpContainerPath] |
| 49 | + $ ["--name", tmpContainerName.unwrap] |
| 50 | + <> ["--volume", name.unwrap <> ":" <> tmpContainerPath.unwrap] |
37 | 51 | <> ["busybox"] |
38 | 52 |
|
39 | 53 | pure (tmpContainerName, tmpContainerPath) |
40 | 54 |
|
41 | | -tmpVolumeName :: String |
42 | | -tmpVolumeName = "restyler-code-volume" |
| 55 | +tmpVolumeName :: VolumeName |
| 56 | +tmpVolumeName = VolumeName "restyler-code-volume" |
43 | 57 |
|
44 | | -tmpContainerName :: String |
45 | | -tmpContainerName = "restyler-tmp-container" |
| 58 | +tmpContainerName :: ContainerName |
| 59 | +tmpContainerName = ContainerName "restyler-tmp-container" |
46 | 60 |
|
47 | | -tmpContainerPath :: FilePath |
48 | | -tmpContainerPath = "/data" |
| 61 | +tmpContainerPath :: ContainerPath |
| 62 | +tmpContainerPath = ContainerPath "/data" |
0 commit comments