diff --git a/.gitignore b/.gitignore index 076d2fb..3981fb3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,3 @@ -dist -dist-* -cabal-dev -*.o -*.hi -*.hie -*.chi -*.chs.h -*.dyn_o -*.dyn_hi -.hpc -.hsenv -.cabal-sandbox/ -cabal.sandbox.config -*.prof -*.aux -*.hp -*.eventlog .stack-work/ -cabal.project.local -cabal.project.local~ -.HTF/ -.ghc.environment.* -.vscode/ +*~ config.dhall diff --git a/LICENSE b/LICENSE index ce54236..6c656c9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2019 1Computer1 +Copyright 2020 1Computer1 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index f58cd1f..4d22fd3 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,28 @@ Arbitrary code execution server using Docker. -## Install +## Requirements -- Install GHC and Cabal, see [the Haskell website](https://www.haskell.org/) -- Run `cabal new-install`, a `myriad` executable will be installed +You can use either `stack` or `cabal`. +- `stack` should be >= 2.1.1, `cabal` should be >= 2.4.0.0. +- GHC 8.8.3 is required if not already installed by `stack` or if using `cabal`. -## Running +#### Install Binary -- Make sure the configuration is filled out, see `config.example.dhall` for an example -- Run `myriad --config /path/to/config.dhall --languages /path/to/languages/` +Make sure the place where `stack` or `cabal` places binaries is in your PATH. +- For `stack`, you can get it with `stack path --local-bin`. +- For `cabal`, you should find it in `$HOME/.cabal/bin` (Linux) or `%APPDATA%\cabal\bin` (Windows). + +Run `stack install` or `cabal new-install` inside the project folder. +Make sure the configuration is filled out, see `config.example.dhall` for an example. +Run `myriad --config /path/to/config.dhall --languages /path/to/languages/`. + +#### Install in Place + +Make sure the configuration is filled out, see `config.example.dhall` for an example. +Run `stack run` or `cabal v2-run` inside the project folder. +The config and languages folder will default to `./config.dhall` and `./languages`. +You can configure this with `--config` and `--languages`. ## Endpoints diff --git a/hie.yaml b/hie.yaml new file mode 100644 index 0000000..d3d635a --- /dev/null +++ b/hie.yaml @@ -0,0 +1,6 @@ +cradle: + stack: + - path: "./src" + component: "myriad:lib" + - path: "./app" + component: "myriad:exe:myriad-exe" \ No newline at end of file diff --git a/myriad.cabal b/myriad.cabal index 49bd7d1..2892d27 100644 --- a/myriad.cabal +++ b/myriad.cabal @@ -1,95 +1,101 @@ -cabal-version: 2.2 +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.33.0. +-- +-- see: https://github.com/sol/hpack +-- +-- hash: eed4fdad9349ff4c0a5b9359f95a9d1a2781565ece0832118e944caeb29d7054 name: myriad -version: 0.2.0.0 -synopsis: Arbitrary code execution in Docker -description: Please see the README +version: 0.3.0.0 +synopsis: Arbitrary code execution in Docker. +description: Please see the README on GitHub at category: Server -homepage: https://github.com/1computer1/myriad#readme -bug-reports: https://github.com/1computer1/myriad/issues -author: 1Computer1 +homepage: https://github.com/1Computer1/myriad#readme +bug-reports: https://github.com/1Computer1/myriad/issues +author: 1Computer maintainer: onecomputer00@gmail.com -copyright: 2019 1Computer1 +copyright: 2020 1Computer license: MIT license-file: LICENSE build-type: Simple extra-source-files: - README.md + README.md source-repository head type: git - location: https://github.com/1computer1/myriad - -common extensions - default-extensions: - BlockArguments - ConstraintKinds - DataKinds - DerivingStrategies - DeriveFunctor - DeriveGeneric - FlexibleContexts - FlexibleInstances - FunctionalDependencies - GADTs - GeneralizedNewtypeDeriving - LambdaCase - MultiParamTypeClasses - MultiWayIf - NamedFieldPuns - OverloadedStrings - PatternSynonyms - PolyKinds - RankNTypes - ScopedTypeVariables - StandaloneDeriving - TupleSections - TypeApplications - TypeOperators - TypeFamilies - ViewPatterns - -common deps - build-depends: - aeson ^>= 1.4.4.0 - , async ^>= 2.2.2 - , base ^>= 4.12.0.0 - , bytestring ^>= 0.10.8.2 - , containers ^>= 0.6.0.1 - , dhall ^>= 1.24.0 - , filepath ^>= 1.4.2.1 - , lifted-async ^>= 0.10.0.4 - , lifted-base ^>= 0.2.3.12 - , monad-control ^>= 1.0.2.3 - , monad-logger ^>= 0.3.30 - , mtl ^>= 2.2.2 - , servant ^>= 0.16.2 - , servant-server ^>= 0.16.2 - , snowflake ^>= 0.1.1.1 - , string-conversions ^>= 0.4.0.1 - , text ^>= 1.2.3.1 - , time ^>= 1.8.0.2 - , transformers ^>= 0.5.6.2 - , transformers-base ^>= 0.4.5.2 - , typed-process ^>= 0.2.6.0 - , wai ^>= 3.2.2.1 - , warp ^>= 3.2.28 - default-language: Haskell2010 + location: https://github.com/1Computer1/myriad library - import: extensions, deps exposed-modules: - Myriad - Myriad.Core - Myriad.Docker - Myriad.Server - hs-source-dirs: src + Myriad + Myriad.Core + Myriad.Docker + Myriad.Server + other-modules: + Paths_myriad + hs-source-dirs: + src + default-extensions: BlockArguments ConstraintKinds DataKinds DeriveAnyClass DeriveGeneric DeriveTraversable DerivingStrategies FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving KindSignatures LambdaCase MultiParamTypeClasses MultiWayIf NamedFieldPuns OverloadedStrings PatternSynonyms PolyKinds RankNTypes ScopedTypeVariables TupleSections TypeApplications TypeFamilies TypeOperators ViewPatterns + ghc-options: -Wall + build-depends: + aeson + , async + , base >=4.13 && <5 + , bytestring + , containers + , dhall ==1.30.* + , filepath + , lifted-async + , lifted-base + , monad-control + , monad-logger + , mtl + , servant + , servant-server + , snowflake + , string-conversions + , text + , time + , transformers + , transformers-base + , typed-process + , wai + , warp + default-language: Haskell2010 -executable myriad - import: extensions, deps +executable lanx-exe main-is: Main.hs - hs-source-dirs: app + other-modules: + Paths_myriad + hs-source-dirs: + app + default-extensions: BlockArguments ConstraintKinds DataKinds DeriveAnyClass DeriveGeneric DeriveTraversable DerivingStrategies FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving KindSignatures LambdaCase MultiParamTypeClasses MultiWayIf NamedFieldPuns OverloadedStrings PatternSynonyms PolyKinds RankNTypes ScopedTypeVariables TupleSections TypeApplications TypeFamilies TypeOperators ViewPatterns ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall build-depends: - myriad - , optparse-applicative ^>= 0.15.0.0 + aeson + , async + , base >=4.13 && <5 + , bytestring + , containers + , dhall ==1.30.* + , filepath + , lifted-async + , lifted-base + , monad-control + , monad-logger + , mtl + , myriad + , optparse-applicative + , servant + , servant-server + , snowflake + , string-conversions + , text + , time + , transformers + , transformers-base + , typed-process + , wai + , warp + default-language: Haskell2010 diff --git a/package.yaml b/package.yaml new file mode 100644 index 0000000..997b46a --- /dev/null +++ b/package.yaml @@ -0,0 +1,87 @@ +name: myriad +version: 0.3.0.0 +github: "1Computer1/myriad" +license: MIT +author: "1Computer" +maintainer: "onecomputer00@gmail.com" +copyright: "2020 1Computer" + +extra-source-files: +- README.md + +synopsis: Arbitrary code execution in Docker. +category: Server + +description: Please see the README on GitHub at + +dependencies: +- aeson +- async +- base >= 4.13 && < 5 +- bytestring +- containers +- dhall == 1.30.* +- filepath +- lifted-async +- lifted-base +- monad-control +- monad-logger +- mtl +- servant +- servant-server +- snowflake +- string-conversions +- text +- time +- transformers +- transformers-base +- typed-process +- wai +- warp + +default-extensions: +- BlockArguments +- ConstraintKinds +- DataKinds +- DeriveAnyClass +- DeriveGeneric +- DeriveTraversable +- DerivingStrategies +- FlexibleContexts +- FlexibleInstances +- FunctionalDependencies +- GADTs +- GeneralizedNewtypeDeriving +- KindSignatures +- LambdaCase +- MultiParamTypeClasses +- MultiWayIf +- NamedFieldPuns +- OverloadedStrings +- PatternSynonyms +- PolyKinds +- RankNTypes +- ScopedTypeVariables +- TupleSections +- TypeApplications +- TypeFamilies +- TypeOperators +- ViewPatterns + +library: + source-dirs: src + ghc-options: + - -Wall + +executables: + lanx-exe: + main: Main.hs + source-dirs: app + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + - -Wall + dependencies: + - myriad + - optparse-applicative diff --git a/src/Myriad/Core.hs b/src/Myriad/Core.hs index e1cf180..58fa46c 100644 --- a/src/Myriad/Core.hs +++ b/src/Myriad/Core.hs @@ -35,7 +35,6 @@ import qualified Data.Map.Strict as M import Data.Snowflake import qualified Data.Text as T import Dhall -import GHC.Generics (Generic) import Control.Concurrent.MVar.Lifted import Control.Concurrent.QSem.Lifted @@ -64,7 +63,7 @@ data MyriadConfig = MyriadConfig , port :: Natural } deriving (Show, Generic) -instance Interpret MyriadConfig +instance FromDhall MyriadConfig data LanguageConfig = LanguageConfig { name :: Language @@ -75,7 +74,7 @@ data LanguageConfig = LanguageConfig , retries :: Natural } deriving (Show, Generic) -instance Interpret LanguageConfig +instance FromDhall LanguageConfig newtype MyriadT m a = MyriadT { unMyriadT :: ReaderT Env (LoggingT m) a } deriving newtype @@ -129,7 +128,7 @@ exec :: MonadIO m => [String] -> m BL.ByteString exec = readProcessInterleaved_ . shell . mconcat exec_ :: MonadIO m => [String] -> m () -exec_ = void . exec +exec_ = (() <$) . exec logInfo :: MonadLogger m => [T.Text] -> m () logInfo = logInfoN . mconcat diff --git a/stack.yaml b/stack.yaml new file mode 100644 index 0000000..1dce4ea --- /dev/null +++ b/stack.yaml @@ -0,0 +1,66 @@ +# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# https://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-3.5 +# resolver: nightly-2015-09-21 +# resolver: ghc-7.10.2 +# +# The location of a snapshot can be provided as a file or url. Stack assumes +# a snapshot provided as a file might change, whereas a url resource does not. +# +# resolver: ./custom-snapshot.yaml +# resolver: https://example.com/snapshots/2018-01-01.yaml +resolver: lts-15.15 + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# subdirs: +# - auto-update +# - wai +packages: +- . +# Dependency packages to be pulled from upstream that are not in the resolver. +# These entries can reference officially published versions as well as +# forks / in-progress versions pinned to a git hash. For example: +# +# extra-deps: +# - acme-missiles-0.3 +# - git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# +# extra-deps: [] + +# Override default flag values for local packages and extra-deps +# flags: {} + +# Extra package databases containing global packages +# extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=2.3" +# +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor diff --git a/stack.yaml.lock b/stack.yaml.lock new file mode 100644 index 0000000..caca58d --- /dev/null +++ b/stack.yaml.lock @@ -0,0 +1,12 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + size: 496112 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/15/15.yaml + sha256: 86169722ad0056ffc9eacc157ef80ee21d7024f92c0d2961c89ccf432db230a3 + original: lts-15.15