docker: make output limit configurable

This commit is contained in:
1computer1 2020-06-22 02:47:40 -04:00
parent a4b6fccf0b
commit 65e604ce75
3 changed files with 12 additions and 3 deletions

View file

@ -34,6 +34,7 @@ defaultLanguage:
timeout: 20
concurrent: 10
retries: 2
outputLimit: 4k
buildConcurrently: true
prepareContainers: false

View file

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

View file

@ -219,12 +219,14 @@ evalCode lang numRetries code = withContainer $ \cnt -> do
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, "`"]