Skip to content

Commit

Permalink
Stubbing out dockmaster funcs/types
Browse files Browse the repository at this point in the history
  • Loading branch information
samtay committed Dec 13, 2016
1 parent 8b94ec0 commit 0ba31ca
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dockmaster.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ description:
library
hs-source-dirs: src
exposed-modules: Dockmaster.Types
, Dockmaster
other-modules: Dockmaster.Locator
build-depends: base >= 4.7 && < 5
, yaml
, text
, unordered-containers
, shelly
, text
default-language: Haskell2010

executable dockmaster-exe
Expand Down
47 changes: 47 additions & 0 deletions src/Dockmaster.hs
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

33 changes: 33 additions & 0 deletions src/Dockmaster/Locator.hs
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

0 comments on commit 0ba31ca

Please sign in to comment.