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 timeout: 20
concurrent: 10 concurrent: 10
retries: 2 retries: 2
outputLimit: 4k
buildConcurrently: true buildConcurrently: true
prepareContainers: false prepareContainers: false

View file

@ -26,6 +26,7 @@ data Language = Language
, _timeout :: Int , _timeout :: Int
, _concurrent :: Int , _concurrent :: Int
, _retries :: Int , _retries :: Int
, _outputLimit :: T.Text
} deriving (Show) } deriving (Show)
makeFieldLabelsWith classUnderscoreNoPrefixFields ''Language makeFieldLabelsWith classUnderscoreNoPrefixFields ''Language
@ -46,6 +47,7 @@ data DefaultLanguage = DefaultLanguage
, _timeout :: Int , _timeout :: Int
, _concurrent :: Int , _concurrent :: Int
, _retries :: Int , _retries :: Int
, _outputLimit :: T.Text
} deriving (Show) } deriving (Show)
makeFieldLabelsWith classUnderscoreNoPrefixFields ''DefaultLanguage makeFieldLabelsWith classUnderscoreNoPrefixFields ''DefaultLanguage
@ -57,6 +59,7 @@ instance FromJSON DefaultLanguage where
<*> m .: "timeout" <*> m .: "timeout"
<*> m .: "concurrent" <*> m .: "concurrent"
<*> m .: "retries" <*> m .: "retries"
<*> m .: "outputLimit"
data RawLanguage = RawLanguage data RawLanguage = RawLanguage
{ _name :: LanguageName { _name :: LanguageName
@ -65,6 +68,7 @@ data RawLanguage = RawLanguage
, _timeout :: Maybe Int , _timeout :: Maybe Int
, _concurrent :: Maybe Int , _concurrent :: Maybe Int
, _retries :: Maybe Int , _retries :: Maybe Int
, _outputLimit :: Maybe T.Text
} deriving (Show) } deriving (Show)
makeFieldLabelsWith classUnderscoreNoPrefixFields ''RawLanguage makeFieldLabelsWith classUnderscoreNoPrefixFields ''RawLanguage
@ -77,6 +81,7 @@ instance FromJSON RawLanguage where
<*> m .:? "timeout" <*> m .:? "timeout"
<*> m .:? "concurrent" <*> m .:? "concurrent"
<*> m .:? "retries" <*> m .:? "retries"
<*> m .:? "outputLimit"
data RawConfig = RawConfig data RawConfig = RawConfig
{ _languages :: [RawLanguage] { _languages :: [RawLanguage]
@ -127,4 +132,5 @@ fromRawLanguage d r =
, _timeout = fromMaybe (d ^. #timeout) (r ^. #timeout) , _timeout = fromMaybe (d ^. #timeout) (r ^. #timeout)
, _concurrent = fromMaybe (d ^. #concurrent) (r ^. #concurrent) , _concurrent = fromMaybe (d ^. #concurrent) (r ^. #concurrent)
, _retries = fromMaybe (d ^. #retries) (r ^. #retries) , _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, " mkdir eval/", show snowflake]
exec_ ["docker exec ", cs cnt, " chmod 777 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 -- 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/" [ "docker exec -i -u1001:1001 -w/tmp/eval/"
, show snowflake , show snowflake
, " " , " "
, cnt , 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 pr = setStdin (byteStringInput $ cs code) $ shell cmd
logDebug ["Executing with stdin `", cs cmd, "`"] logDebug ["Executing with stdin `", cs cmd, "`"]