diff --git a/config.example.yaml b/config.example.yaml index dfeef8b..6094336 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -34,6 +34,7 @@ defaultLanguage: timeout: 20 concurrent: 10 retries: 2 + outputLimit: 4k buildConcurrently: true prepareContainers: false diff --git a/src/Myriad/Config.hs b/src/Myriad/Config.hs index 7a45e23..813967b 100644 --- a/src/Myriad/Config.hs +++ b/src/Myriad/Config.hs @@ -26,6 +26,7 @@ data Language = Language , _timeout :: Int , _concurrent :: Int , _retries :: Int + , _outputLimit :: T.Text } deriving (Show) makeFieldLabelsWith classUnderscoreNoPrefixFields ''Language @@ -46,6 +47,7 @@ data DefaultLanguage = DefaultLanguage , _timeout :: Int , _concurrent :: Int , _retries :: Int + , _outputLimit :: T.Text } deriving (Show) makeFieldLabelsWith classUnderscoreNoPrefixFields ''DefaultLanguage @@ -57,6 +59,7 @@ instance FromJSON DefaultLanguage where <*> m .: "timeout" <*> m .: "concurrent" <*> m .: "retries" + <*> m .: "outputLimit" data RawLanguage = RawLanguage { _name :: LanguageName @@ -65,6 +68,7 @@ data RawLanguage = RawLanguage , _timeout :: Maybe Int , _concurrent :: Maybe Int , _retries :: Maybe Int + , _outputLimit :: Maybe T.Text } deriving (Show) makeFieldLabelsWith classUnderscoreNoPrefixFields ''RawLanguage @@ -77,6 +81,7 @@ instance FromJSON RawLanguage where <*> m .:? "timeout" <*> m .:? "concurrent" <*> m .:? "retries" + <*> m .:? "outputLimit" data RawConfig = RawConfig { _languages :: [RawLanguage] @@ -127,4 +132,5 @@ fromRawLanguage d r = , _timeout = fromMaybe (d ^. #timeout) (r ^. #timeout) , _concurrent = fromMaybe (d ^. #concurrent) (r ^. #concurrent) , _retries = fromMaybe (d ^. #retries) (r ^. #retries) + , _outputLimit = fromMaybe (d ^. #outputLimit) (r ^. #outputLimit) } diff --git a/src/Myriad/Docker.hs b/src/Myriad/Docker.hs index 12fb1c6..2039a49 100644 --- a/src/Myriad/Docker.hs +++ b/src/Myriad/Docker.hs @@ -214,17 +214,19 @@ evalCode lang numRetries code = withContainer $ \cnt -> do void . killContainer $ lang ^. #name eval :: ContainerName -> Snowflake -> Myriad EvalResult - eval cnt snowflake = do + eval cnt snowflake = do logInfo ["Running code in container ", cs cnt, ", evaluation ", cs $ show snowflake, ":\n", cs code] exec_ ["docker exec ", cs cnt, " mkdir eval/", show snowflake] exec_ ["docker exec ", cs cnt, " chmod 777 eval/", show snowflake] -- User 1001 will be used for the actual execution so that they can't access `eval` itself - let cmd = mconcat + let limit = lang ^. #outputLimit + cmd = mconcat [ "docker exec -i -u1001:1001 -w/tmp/eval/" , show snowflake , " " , cnt - , " /bin/sh /var/run/run.sh 2>&1 | head -c 4K" + , " /bin/sh /var/run/run.sh 2>&1 | head -c " + , cs limit ] pr = setStdin (byteStringInput $ cs code) $ shell cmd logDebug ["Executing with stdin `", cs cmd, "`"]