Change the CLI to take the languages folder

This commit is contained in:
1Computer1 2019-09-05 10:17:08 -04:00
parent d1b94f6dda
commit c31b52ce5e
7 changed files with 27 additions and 19 deletions

View file

@ -9,8 +9,8 @@ Arbitrary code execution server using Docker.
## Running
- Make sure the configuration is filled out, see `config.dhall` for an example
- Run `myriad --config path/to/config.dhall`
- Make sure the configuration is filled out, see `config.example.dhall` for an example
- Run `myriad --config /path/to/config.dhall --languages /path/to/languages/`
## Endpoints

View file

@ -8,19 +8,27 @@ import Myriad
data Args = Args
{ configInput :: T.Text
, languagesDir :: T.Text
}
parseArgs :: IO Args
parseArgs = execParser $ info (helper <*> args) (fullDesc <> progDesc "Run the Myriad server")
where
args = Args <$> option str (mconcat
args = Args
<$> option str (mconcat
[ long "config"
, short 'c'
, help "Sets the Dhall configuration"
, help "Set the Dhall configuration"
, metavar "DHALL"
])
<*> option str (mconcat
[ long "languages"
, short 'l'
, help "Set the languages directory"
, metavar "DIR"
])
main :: IO ()
main = do
Args { configInput } <- parseArgs
runMyriadServer configInput
Args { configInput, languagesDir } <- parseArgs
runMyriadServer configInput languagesDir

View file

@ -36,6 +36,5 @@ let config : Config =
, prepareContainers = False
, cleanupInterval = 30
, port = 8081
, languagesDir = "./languages"
}
in config

View file

@ -1,7 +1,7 @@
cabal-version: 2.2
name: myriad
version: 0.1.0.0
version: 0.2.0.0
synopsis: Arbitrary code execution in Docker
description: Please see the README
category: Server

View file

@ -13,9 +13,9 @@ import Myriad.Core
import Myriad.Docker
import Myriad.Server
runMyriadServer :: T.Text -> IO ()
runMyriadServer configInput = do
env <- initEnv configInput
runMyriadServer :: T.Text -> T.Text -> IO ()
runMyriadServer configInput languagesDir = do
env <- initEnv configInput languagesDir
runMyriadT env do
buildAllImages
startCleanup

View file

@ -49,6 +49,7 @@ data EvalResult = EvalOk BL.ByteString | EvalTimedOut | EvalErrored
data Env = Env
{ config :: MyriadConfig
, languagesDir :: T.Text
, containers :: MVar (M.Map Language ContainerName)
, containerSems :: MVar (M.Map Language QSem)
, evalSems :: MVar (M.Map Language QSem)
@ -61,7 +62,6 @@ data MyriadConfig = MyriadConfig
, prepareContainers :: Bool
, cleanupInterval :: Natural
, port :: Natural
, languagesDir :: T.Text
} deriving (Show, Generic)
instance Interpret MyriadConfig
@ -112,10 +112,11 @@ type Myriadic m = (MonadReader Env m, MonadLogger m, MonadLoggerIO m, MonadIO m,
readConfig :: T.Text -> IO MyriadConfig
readConfig = input auto
initEnv :: T.Text -> IO Env
initEnv configInput =
initEnv :: T.Text -> T.Text -> IO Env
initEnv configInput languagesDir =
Env
<$> readConfig configInput
<*> pure languagesDir
<*> newMVar M.empty
<*> newMVar M.empty
<*> newMVar M.empty

View file

@ -27,7 +27,7 @@ import Myriad.Core
buildImage :: Myriadic m => LanguageConfig -> m ()
buildImage lang@LanguageConfig { name, concurrent } = do
MyriadConfig { prepareContainers, languagesDir } <- asks config
Env { config = MyriadConfig { prepareContainers }, languagesDir } <- ask
logInfo ["Building image ", cs $ imageName lang]
exec_ ["docker build -t ", imageName lang, " ", cs languagesDir </> cs name]
setupQSems