Commit 22d79ef9 authored by Valentin Reis's avatar Valentin Reis

[feature] Log parsing and minor Argotest.hs refactoring tasks.

parent 7991c67f
Pipeline #4623 passed with stage
in 26 seconds
......@@ -21,7 +21,7 @@ import System.Posix.Signals
data StackArgs = StackArgs
{ dargs :: Text --"Daemon arguments. Properly quote this."
, app :: FilePath --"Input file, target application script"
, app :: Text --"Target application call, sh+path valid"
, manifest :: FilePath --"Input file, manifest."
, cmd_out :: FilePath --"Output file, application stdout"
, cmd_err :: FilePath --"Output file, application stderr"
......@@ -33,7 +33,7 @@ data StackArgs = StackArgs
instance Default StackArgs where
def = StackArgs
{ dargs = ""
, app = "echo \"Dummy app: Hello world!\""
, app = "echo \"HelloWorld\""
, manifest = "manifests/basic.json"
, cmd_out = "cmd_out.log"
, cmd_err = "cmd_err.log"
......@@ -50,7 +50,6 @@ colorShell color s = setC color *> s *> setC White
printInfo :: Text -> Shell ()
printError :: Text -> Shell ()
printWarning :: Text -> Shell ()
printInfo = printf ("Info:"%s)
printWarning = colorShell Yellow . printf ("Warning:"%s)
printError = colorShell Red . printf ("Error:"%s)
......@@ -106,6 +105,6 @@ prepareDaemonShell dargs daemon_out daemon_err nrm_log = do
ExitFailure n -> do printInfo "Contents of argo_nodeos_config_exit_message: \n"
view $ cat ["./argo_nodeos_config_exit_message"]
die ("Clean config failed with exit code " <> repr n)
printInfo $ format ("Running the daemon: see main log at "%fp%"\n") nrm_log
printInfo $ format ("Running the daemon, main log at "%fp%", stdout at "%fp%", stderr at "%fp%"\n") nrm_log daemon_out daemon_err
export "ARGO_NODEOS_CONFIG" (format fp confPath')
return $ sh $ inshell (format (fp%" "%s%" --nrm_log="%fp%" >"%fp%" 2>"%fp) daemonPath dargs nrm_log daemon_out daemon_err) empty
#! /usr/bin/env nix-shell
#! nix-shell -i runhaskell -A test
#! /usr/bin/env runhaskell
{-# LANGUAGE
OverloadedStrings
......@@ -20,11 +19,20 @@ opts :: Parser (IO ())
opts = subparser
( command "clean" (info (pure $ runClean def) idm)<> help "Target for the greeting"
<> command "daemon" (info (pure $ runDaemon def) idm)
<> command "helloworld" (info (pure $ runSimpleStack def) idm) )
<> command "helloworld" (info (pure $ runHelloWorld def ) idm) )
main :: IO ()
main = join $ execParser (info (opts <**>helper) idm)
runHelloWorld :: StackArgs -> IO ()
runHelloWorld a@StackArgs{..} = do
let passStr = "HelloWorldFromApp"
runSimpleStack $ a {app = format ("echo "%s) passStr}
readTextFile cmd_err >>= \x -> case match (has "HelloWorldFromApp") x of
[] -> die ("Hello world app failed to run.")
_ -> sh $ printInfo "The hello world app executed properly in a \
\container and its message was received by `cmd`.\n"
runSimpleStack :: StackArgs -> IO ()
runSimpleStack a@StackArgs{..} = sh $ do
cleanLeftovers daemon_out daemon_err cmd_out cmd_err time_file nrm_log
......@@ -39,7 +47,7 @@ runSimpleStack a@StackArgs{..} = sh $ do
printInfo "Launching the application through cmd.\n"
(_,t) <- time $
shell (format ("cmd run -u toto "%fp%" "%fp%" > "%fp%" 2>"%fp) manifest app cmd_out cmd_err) empty >>= \case
shell (format ("cmd run -u toto "%fp%" "%s%" > "%fp%" 2>"%fp) manifest app cmd_out cmd_err) empty >>= \case
ExitSuccess -> printInfo "cmd has exited successfuly.\n"
ExitFailure n -> die ("cmd failed with exit code " <> repr n <>
" . The application logs are at " <> repr cmd_out <> " " <> repr cmd_err )
......@@ -54,6 +62,5 @@ runClean StackArgs{..} = sh $
cleanLeftovers daemon_out daemon_err cmd_out cmd_err time_file nrm_log
runDaemon :: StackArgs -> IO ()
runDaemon StackArgs{..} = sh $ do
daemonShell <- prepareDaemonShell dargs daemon_out daemon_err nrm_log
daemonShell
runDaemon StackArgs{..} = sh $
prepareDaemonShell dargs daemon_out daemon_err nrm_log >>= id
......@@ -19,13 +19,36 @@ let
in rec
{
dev-beforelib = hpkgs.shellFor {
dev-lib = hpkgs.shellFor {
packages = p: with p; [ argotest ];
withHoogle = true;
buildInputs = with hpkgs; with pkgs; [ cabal-install ghcid
hlint sysstat hdevtools];
};
dev-test = pkgs.stdenv.mkDerivation rec {
name = "env";
env = pkgs.buildEnv { name = name; paths = buildInputs; };
buildInputs = [
(hpkgs.ghcWithPackages (p: [
p.argotest
p.turtle
p.data-default
p.managed
p.ansi-terminal
p.unix
p.system-filepath
p.async
]))
containers
hpkgs.hdevtools
hpkgs.hlint
hpkgs.ghcid
amg
nrm
];
};
test = pkgs.stdenv.mkDerivation rec {
name = "env";
env = pkgs.buildEnv { name = name; paths = buildInputs; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment