Add CLI and configurable configuration

This commit is contained in:
1computer1 2019-07-11 01:00:41 -04:00
parent 07bbc86744
commit 8e246c8851
4 changed files with 31 additions and 7 deletions

View File

@ -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

View File

@ -25,6 +25,7 @@ dependencies:
- monad-control
- monad-logger
- mtl
- optparse-applicative
- servant
- servant-server
- snowflake

View File

@ -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

View File

@ -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