-
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
3 changed files
with
84 additions
and
0 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
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 | ||
( dm | ||
) where | ||
|
||
-- Local modules | ||
import Dockmaster.Locator | ||
|
||
-- External modules | ||
import Shelly | ||
import Prelude hiding (FilePath) | ||
import qualified Data.Text as T | ||
default (T.Text) | ||
|
||
-- | Possibly provide sum type data = DcUp | DcDown | ... with to string method | ||
type DCCommand = T.Text | ||
|
||
-- | Runs docker-compose commands against resolved composition locations | ||
-- See usage docs for more info. Tries to find a dockmaster.yml file based on | ||
-- the initial path argument | ||
dm :: FilePath -> DCCommand -> [T.Text] -> Sh (T.Text) | ||
dm path command args = do | ||
gwd <- getWorkDir path | ||
case gwd of | ||
Left err -> do | ||
echo_n_err err | ||
return err -- maybe dm should return Either and executable handles printing? | ||
Right wd -> sub $ do | ||
cd wd | ||
dockermachine -- TODO handle Left errors | ||
hookWrap command $ dockercompose $ command : args | ||
|
||
dockercompose :: [T.Text] -> Sh T.Text | ||
dockercompose = run "docker-compose" | ||
|
||
-- | Executes specific dc command pre/post hooks around action argument | ||
-- (action arg is typically docker-compose command) | ||
hookWrap :: DCCommand -> Sh a -> Sh a | ||
hookWrap = undefined | ||
|
||
-- | Reads from dockmaster.yml to find machine, attempts to connect | ||
-- dm should HALT when machine is unreachable | ||
dockermachine :: Sh (Either T.Text ()) | ||
dockermachine = undefined | ||
|
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,33 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ExtendedDefaultRules #-} | ||
{-# OPTIONS_GHC -fno-warn-type-defaults #-} | ||
module Dockmaster.Locator | ||
( workDirExec | ||
, getWorkDir | ||
, cdWorkDir | ||
) where | ||
|
||
import Shelly | ||
import Prelude hiding (FilePath) | ||
import qualified Data.Text as T | ||
default (T.Text) | ||
|
||
-- | Execute action in workdir (does not affect cwd outside of action) | ||
workDirExec :: FilePath -> Sh a -> Sh (Either T.Text a) | ||
workDirExec = undefined | ||
|
||
-- | Resolve the appropriate docker-compose workdir (based on path arg) | ||
-- TODO This needs error handling when dockmaster.yml not found | ||
getWorkDir :: FilePath -> Sh (Either T.Text FilePath) | ||
getWorkDir p | ||
-- search for dockmaster.yml | ||
-- aggregate searched dirs for verbosity msg ? | ||
| p /= "." = do return $ Left "dockmaster.yml file not found" | ||
| otherwise = do | ||
wd <- pwd | ||
return $ Right wd | ||
|
||
-- | Cd into workdir | ||
-- TODO check if cd retains context when run externally (i.e. do I need to pass action here) | ||
cdWorkDir :: FilePath -> Sh (Either T.Text (Sh ())) | ||
cdWorkDir = undefined |