Add CLI and configurable configuration
This commit is contained in:
parent
07bbc86744
commit
8e246c8851
4 changed files with 31 additions and 7 deletions
11
README.md
11
README.md
|
@ -2,10 +2,15 @@
|
||||||
|
|
||||||
Arbitrary code execution server using Docker.
|
Arbitrary code execution server using Docker.
|
||||||
|
|
||||||
## Setup
|
## Install
|
||||||
|
|
||||||
- Fill out `config.dhall`, read it for documentation and an example
|
- Install [Stack 2+](https://docs.haskellstack.org/en/stable/README/)
|
||||||
- Run `stack run`
|
- 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
|
## Endpoints
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ dependencies:
|
||||||
- monad-control
|
- monad-control
|
||||||
- monad-logger
|
- monad-logger
|
||||||
- mtl
|
- mtl
|
||||||
|
- optparse-applicative
|
||||||
- servant
|
- servant
|
||||||
- servant-server
|
- servant-server
|
||||||
- snowflake
|
- snowflake
|
||||||
|
|
20
src/Main.hs
20
src/Main.hs
|
@ -2,15 +2,33 @@ module Main where
|
||||||
|
|
||||||
import Control.Monad.Logger
|
import Control.Monad.Logger
|
||||||
|
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import Options.Applicative
|
||||||
|
|
||||||
import Network.Wai.Handler.Warp (run)
|
import Network.Wai.Handler.Warp (run)
|
||||||
|
|
||||||
import Myriad.Core
|
import Myriad.Core
|
||||||
import Myriad.Docker
|
import Myriad.Docker
|
||||||
import Myriad.Server
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
env <- initEnv "./config.dhall"
|
Args { configInput } <- parseArgs
|
||||||
|
env <- initEnv configInput
|
||||||
runMyriadT env do
|
runMyriadT env do
|
||||||
buildAllImages
|
buildAllImages
|
||||||
startCleanup
|
startCleanup
|
||||||
|
|
|
@ -67,12 +67,12 @@ type MyriadT m = ReaderT Env (LoggingT m)
|
||||||
type MonadWithIO m = (MonadIO m, MonadBase IO m, MonadBaseControl IO m)
|
type MonadWithIO m = (MonadIO m, MonadBase IO m, MonadBaseControl IO m)
|
||||||
|
|
||||||
readConfig :: T.Text -> IO MyriadConfig
|
readConfig :: T.Text -> IO MyriadConfig
|
||||||
readConfig path = input auto path
|
readConfig = input auto
|
||||||
|
|
||||||
initEnv :: T.Text -> IO Env
|
initEnv :: T.Text -> IO Env
|
||||||
initEnv path =
|
initEnv configInput =
|
||||||
Env
|
Env
|
||||||
<$> readConfig path
|
<$> readConfig configInput
|
||||||
<*> newIORef M.empty
|
<*> newIORef M.empty
|
||||||
<*> newIORef M.empty
|
<*> newIORef M.empty
|
||||||
<*> newIORef M.empty
|
<*> newIORef M.empty
|
||||||
|
|
Loading…
Reference in a new issue