-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# todo | ||
|
||
## mvp | ||
1. Use COP to generate docker-compose.yml and pipe to `docker-compose -f -` | ||
1. Fixup haddock docs and add to /docs directory for github.io. Use `stack build --haddock` to check coverage and get output | ||
2. Parse `DOCKMASTER_HOME` from config.yml PATHS into `get_env "DOCKMASTER_HOME" ~> "~/.dockmaster/home" or whatever | ||
|
||
## later | ||
0. --local flag to execute on local machine instead of docker-machine targets | ||
1. Use monad transformer to stack Sh on top of Either (error transformer) | ||
2. Read up on exception handling link in haskell-fun-times resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ExtendedDefaultRules #-} | ||
{-# OPTIONS_GHC -fno-warn-type-defaults #-} | ||
module Dockmaster.Compose | ||
( -- * Orchestration for docker-compose.yml | ||
dockercompose | ||
) where | ||
|
||
-- Local modules | ||
import Dockmaster.Types | ||
import Dockmaster.Utils (parsePath, toText) | ||
|
||
-- External modules | ||
import Control.Monad ((<=<)) | ||
import Shelly | ||
import Prelude hiding (FilePath) | ||
import qualified Data.Text as T | ||
default (T.Text) | ||
|
||
-- | Runs docker-compose but uses compiled docker-compose.yml file | ||
-- if template/vars are specified in dockmaster.yml | ||
dockercompose :: Dockmaster -> [T.Text] -> Sh () | ||
dockercompose cfg optargs = print_stdout True $ maybe | ||
(run_ "docker-compose" optargs) -- default run on docker-compose.yml, as usual | ||
(composeViaTemplate optargs) | ||
(dmFile cfg) | ||
|
||
-- | Uses 'ComposeFile' argument to build templated docker-compose.yml content | ||
-- and pipes it directly to docker-compose | ||
-- | ||
-- TODO make sure the pipe doesnt output garbage | ||
-- If we need shell-level pipe this is possible: | ||
-- https://hackage.haskell.org/package/shelly-1.6.8.1/docs/Shelly.html#v:-45--124--45- | ||
composeViaTemplate :: [T.Text] -> ComposeFile -> Sh () | ||
composeViaTemplate optargs cf = | ||
compileTemplate cf -|- run_ "docker-compose" (optargs ++ ["-f", "-"]) | ||
|
||
-- | Leverages @cop@ to build docker-compose.yml content from template/vars | ||
-- | ||
-- This function returns the stdout wrapped in 'Sh'. It can then be piped to | ||
-- docker-compose via @docker-compose -f -@ -- see documentation for docker-compose. | ||
compileTemplate :: ComposeFile -> Sh T.Text | ||
compileTemplate cf = do | ||
file <- parse (cfPath cf) | ||
vars <- mapM parse (cfVars cf) | ||
run "cop" $ ["--render-template", file] ++ vars | ||
where parse = toText <=< parsePath <=< toText |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters