docker: make output limit configurable
This commit is contained in:
parent
a4b6fccf0b
commit
65e604ce75
3 changed files with 12 additions and 3 deletions
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,17 +214,19 @@ evalCode lang numRetries code = withContainer $ \cnt -> do
|
||||||
void . killContainer $ lang ^. #name
|
void . killContainer $ lang ^. #name
|
||||||
|
|
||||||
eval :: ContainerName -> Snowflake -> Myriad EvalResult
|
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]
|
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, " 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, "`"]
|
||||||
|
|
Loading…
Reference in a new issue