-
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
8 changed files
with
136 additions
and
11 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,3 +1,4 @@ | ||
*.swp | ||
dist | ||
dist-* | ||
cabal-dev | ||
|
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,2 +1,6 @@ | ||
# dockmaster | ||
command line utility providing conveniences around docker-compose | ||
|
||
### resources | ||
[wiki on arg handling](https://wiki.haskell.org/Tutorials/Programming_Haskell/Argument_handling) | ||
[bad ass opt package](https://github.com/pcapriotti/optparse-applicative) |
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,6 +1,12 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Main where | ||
|
||
import Lib | ||
import Dockmaster.Types | ||
|
||
main :: IO () | ||
main = someFunc | ||
import Data.Yaml | ||
import qualified Data.ByteString as BS | ||
|
||
main = do | ||
ymlData <- BS.readFile "dockmaster.yml" | ||
let d = decodeEither ymlData :: Either String Dockmaster | ||
print d |
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,65 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Dockmaster.Types where | ||
|
||
import Data.Yaml | ||
import Control.Applicative | ||
import Data.HashMap.Lazy (HashMap, lookup, member) | ||
import Prelude hiding (lookup) | ||
import qualified Data.Text as T | ||
|
||
-- | Dockmaster configuration (specified by dockmaster.yml) | ||
data Dockmaster = Dockmaster { dmFile :: Maybe ComposeFile | ||
, dmTargets :: [Target] | ||
, dmCommands :: [HashMap T.Text CommandConfig] | ||
} deriving (Show) | ||
|
||
-- | Configuration for docker-compose.yml file template & vars | ||
data ComposeFile = ComposeFile { cfPath :: Maybe String | ||
, cfConfig :: [String] | ||
} deriving (Show) | ||
|
||
-- | Targets are used to identify where compositions are run | ||
data Target = Target { targetName :: Maybe String | ||
, targetType :: Maybe String | ||
, targetMachine :: Maybe String | ||
} deriving (Show) | ||
|
||
-- | Hooks can be specified by filename or direct shell command | ||
data Hook = File String | Shell String deriving (Show) | ||
|
||
-- | Configuration for each command | ||
data CommandConfig = CommandConfig { ccCompose :: Bool | ||
, ccPreHooks :: [Hook] | ||
, ccPostHooks :: [Hook] | ||
} deriving (Show) | ||
|
||
instance FromJSON ComposeFile where | ||
parseJSON (Object v) = ComposeFile | ||
<$> v .:? "path" | ||
<*> v .:? "config" .!= [] | ||
|
||
instance FromJSON Target where | ||
parseJSON (Object v) = Target | ||
<$> v .:? "name" | ||
<*> v .:? "type" | ||
<*> v .:? "machine" | ||
|
||
instance FromJSON Hook where | ||
parseJSON (Object v) | ||
| member "file" v = File <$> v .: "file" | ||
| member "shell" v = Shell <$> v .: "shell" | ||
| otherwise = error "Hooks are specified by file or shell only" | ||
|
||
instance FromJSON CommandConfig where | ||
parseJSON (Object v) = CommandConfig | ||
<$> v .:? "compose" .!= True | ||
<*> v .:? "pre_hooks" .!= [] | ||
<*> v .:? "post_hooks" .!= [] | ||
|
||
instance FromJSON Dockmaster where | ||
parseJSON (Object v) = Dockmaster | ||
<$> v .:? "file" | ||
<*> v .:? "targets" .!= [] | ||
<*> v .:? "commands" .!= [] | ||
-- A non-Object value is of the wrong type, so fail. | ||
parseJSON _ = error "Can't parse Dockmaster from YAML/JSON" |
This file was deleted.
Oops, something went wrong.
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,2 +1,25 @@ | ||
module Main where | ||
|
||
import Data.Yaml | ||
import Dockmaster.Types | ||
import qualified Data.ByteString as BS | ||
import Data.Maybe | ||
import System.Exit | ||
import System.Directory | ||
|
||
parseDockmasterYml :: FilePath -> IO Bool | ||
parseDockmasterYml "." = return True | ||
parseDockmasterYml ".." = return True | ||
parseDockmasterYml file = do | ||
contents <- BS.readFile $ "./test/fixtures/" ++ file | ||
case (decodeEither contents :: Either String Dockmaster) of | ||
(Left e) -> putStrLn ("Failed to parse " ++ file ++":") >> putStrLn e >> return False | ||
otherwise -> putStrLn ("Parsed " ++ file ++ " successfully.") >> return True | ||
|
||
main :: IO () | ||
main = putStrLn "Test suite not yet implemented" | ||
main = do | ||
files <- getDirectoryContents "./test/fixtures/" | ||
results <- mapM parseDockmasterYml files | ||
if and results | ||
then exitWith ExitSuccess | ||
else exitWith (ExitFailure 1) |
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,24 @@ | ||
file: | ||
path: docker-compose.j2 | ||
config: | ||
- /etc/dockmaster/defaults.yml | ||
- env.vars | ||
|
||
targets: | ||
- name: node-a | ||
type: docker-machine | ||
|
||
# optional, defaults to name | ||
machine: node-a | ||
|
||
commands: | ||
- up: | ||
pre_hooks: | ||
- file: relative_path/to/hook.sh | ||
- file: /absolute/path/to/hook.sh | ||
- shell: rm -rf .working | ||
- wiggle: | ||
compose: false | ||
# ^^^ does not call docker-compose between pre- and post- hooks. | ||
pre_hooks: | ||
- file: wiggle.sh |