Created
January 12, 2016 21:41
-
-
Save beala/a6cf2c5eebad38aa8c7c to your computer and use it in GitHub Desktop.
haskell docker dsl sketch
This file contains hidden or 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
{-# LANGUAGE DeriveFunctor #-} | |
module Main where | |
import Control.Monad.Free | |
data DockerAction a = Add String a | |
| EntryPoint String a | |
| Run String a | |
deriving (Functor) | |
type Docker a = Free DockerAction a | |
add :: String -> Docker () | |
add path = liftF $ Add path () | |
entryPoint :: String -> Docker () | |
entryPoint path = liftF $ EntryPoint path () | |
run :: String -> Docker () | |
run cmd = liftF $ Run cmd () | |
-- Translate the DockerAction algebra into strings and print them. | |
runDocker :: Docker a -> IO a | |
runDocker = foldFree f | |
where f (Add s a) = putStrLn ("ADD " ++ s) >> return a | |
f (EntryPoint s a) = putStrLn ("ENTRYPOINT " ++ s) >> return a | |
f (Run s a) = putStrLn ("RUN " ++ s) >> return a | |
-- Docker DSL in action. Prints the docker file to the console. | |
main :: IO () | |
main = runDocker $ do | |
add "myJar.jar" | |
run "echo 'added jar'" | |
entryPoint "java -jar myJar.jar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running it: