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 ## Running
- Make sure the configuration is filled out, see `config.dhall` for an example - Make sure the configuration is filled out, see `config.example.dhall` for an example
- Run `myriad --config path/to/config.dhall` - Run `myriad --config /path/to/config.dhall --languages /path/to/languages/`
## Endpoints ## Endpoints

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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