Skip to content

Commit

Permalink
Add docker image mapping for languages
Browse files Browse the repository at this point in the history
  • Loading branch information
prasmussen committed Mar 6, 2021
1 parent c27a111 commit fe7531e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Handler/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ data RunPayload = RunPayload
instance Aeson.FromJSON RunPayload


-- TODO: get docker image
postRunR :: Language -> Handler Value
postRunR lang = do
langVersion <- fromMaybe "latest" <$> lookupGetParam "version"
-- persist <- fromMaybe "true" <$> lookupGetParam "persist"
when (not $ languageIsRunnable lang) $
sendResponseStatus status400 (Aeson.object ["message" .= Aeson.String "Language is not runnable"])
req <- reqWaiRequest <$> getRequest
body <- liftIO $ Wai.strictRequestBody req
mUserId <- maybeAuthId
Expand All @@ -41,7 +40,7 @@ postRunR lang = do
sendResponseStatus status400 $ object ["message" .= ("Invalid request body: " <> err)]

Right payload -> do
result <- liftIO $ DockerRun.run (toRunRequest lang "glot/bash:latest" payload)
result <- liftIO $ DockerRun.run (toRunRequest lang (languageDockerImage lang) payload)
case result of
Left err -> do
print err
Expand Down
39 changes: 39 additions & 0 deletions Model/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,45 @@ languageIsRunnable :: Language -> Bool
languageIsRunnable Plaintext = False
languageIsRunnable _ = True

languageDockerImage :: Language -> Text
languageDockerImage Assembly = "glot/assembly:latest"
languageDockerImage Ats = "glot/ats:latest"
languageDockerImage Bash = "glot/bash:latest"
languageDockerImage C = "glot/clang:latest"
languageDockerImage Clojure = "glot/clojure:latest"
languageDockerImage Cobol = "glot/cobol:latest"
languageDockerImage Coffeescript = "glot/coffeescript:latest"
languageDockerImage Cpp = "glot/clang:latest"
languageDockerImage Crystal = "glot/crystal:latest"
languageDockerImage Csharp = "glot/csharp:latest"
languageDockerImage D = "glot/dlang:latest"
languageDockerImage Elixir = "glot/elixir:latest"
languageDockerImage Elm = "glot/elm:latest"
languageDockerImage Erlang = "glot/erlang:latest"
languageDockerImage Fsharp = "glot/fsharp:latest"
languageDockerImage Go = "glot/golang:latest"
languageDockerImage Groovy = "glot/groovy:latest"
languageDockerImage Haskell = "glot/haskell:latest"
languageDockerImage Idris = "glot/idris:latest"
languageDockerImage Java = "glot/java:latest"
languageDockerImage Javascript = "glot/javascript:latest"
languageDockerImage Julia = "glot/julia:latest"
languageDockerImage Kotlin = "glot/kotlin:latest"
languageDockerImage Lua = "glot/lua:latest"
languageDockerImage Mercury = "glot/mercury:latest"
languageDockerImage Nim = "glot/nim:latest"
languageDockerImage Ocaml = "glot/ocaml:latest"
languageDockerImage Perl = "glot/perl:latest"
languageDockerImage Php = "glot/php:latest"
languageDockerImage Python = "glot/python:latest"
languageDockerImage Raku = "glot/raku:latest"
languageDockerImage Ruby = "glot/ruby:latest"
languageDockerImage Rust = "glot/rust:latest"
languageDockerImage Scala = "glot/scala:latest"
languageDockerImage Swift = "glot/swift:latest"
languageDockerImage TypeScript = "glot/typescript:latest"
languageDockerImage Plaintext = ""

-- Example of custom run command, not important, use "todo" if you are unsure what to add
languageRunCmdExample :: Language -> String
languageRunCmdExample Assembly = "nasm -f elf64 -o a.o main.asm && ld -o a.out a.o && ./a.out"
Expand Down

0 comments on commit fe7531e

Please sign in to comment.