diff --git a/README.md b/README.md index 8c9acaf..7d637bd 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,15 @@ Arbitrary code execution server using Docker. -## Setup +## Install -- Fill out `config.dhall`, read it for documentation and an example -- Run `stack run` +- Install [Stack 2+](https://docs.haskellstack.org/en/stable/README/) +- Run `stack install`, a `myriad` executable will be installed + +## Running + +- Make sure the configuration is filled out, see `config.dhall` for an example +- Run `myriad --config path/to/config.dhall` ## Endpoints diff --git a/package.yaml b/package.yaml index c04ba17..dd5aace 100644 --- a/package.yaml +++ b/package.yaml @@ -25,6 +25,7 @@ dependencies: - monad-control - monad-logger - mtl +- optparse-applicative - servant - servant-server - snowflake diff --git a/src/Main.hs b/src/Main.hs index d04058e..fa72674 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -2,15 +2,33 @@ module Main where import Control.Monad.Logger +import qualified Data.Text as T +import Options.Applicative + import Network.Wai.Handler.Warp (run) import Myriad.Core import Myriad.Docker import Myriad.Server +data Args = Args + { configInput :: T.Text + } + +parseArgs :: IO Args +parseArgs = execParser $ info (helper <*> args) (fullDesc <> progDesc "Run the Myriad server") + where + args = Args <$> option str (mconcat + [ long "config" + , short 'c' + , help "Sets the Dhall configuration" + , metavar "DHALL" + ]) + main :: IO () main = do - env <- initEnv "./config.dhall" + Args { configInput } <- parseArgs + env <- initEnv configInput runMyriadT env do buildAllImages startCleanup diff --git a/src/Myriad/Core.hs b/src/Myriad/Core.hs index cbb9da8..646526c 100644 --- a/src/Myriad/Core.hs +++ b/src/Myriad/Core.hs @@ -67,12 +67,12 @@ type MyriadT m = ReaderT Env (LoggingT m) type MonadWithIO m = (MonadIO m, MonadBase IO m, MonadBaseControl IO m) readConfig :: T.Text -> IO MyriadConfig -readConfig path = input auto path +readConfig = input auto initEnv :: T.Text -> IO Env -initEnv path = +initEnv configInput = Env - <$> readConfig path + <$> readConfig configInput <*> newIORef M.empty <*> newIORef M.empty <*> newIORef M.empty