Commit 56513e10 authored by Valentin Reis's avatar Valentin Reis
Browse files

Adds remote execution stub.

parent c14a04e2
Pipeline #5436 failed with stage
in 1 minute and 25 seconds
......@@ -75,73 +75,61 @@ main = do
opts = hsubparser
( command
"build"
(info (wrap NixBuild <$> targetParser <*> executorParser)
(info (wrap NixBuild <$> targetParser <*> commonParser)
(progDesc "Run an argo-compatible nix-build.")
)
<> command
"shell"
(info (wrap NixShell <$> targetParser <*> executorParser)
(info (wrap NixShell <$> targetParser <*> commonParser)
(progDesc "Enter an argo-compatible nix-shell")
)
<> command
"remote-shell"
(info
(remotely <$> targetParser <*> commonParser <*> remoteParser)
(progDesc
"Enter an argo-compatible nix-shell on a remote machine with nix enabled"
)
)
<> help "Type of operation to run."
)
data Args = Args
{
argopkgs :: Text
data ArgsCommon = ArgsCommon
{ argopkgs :: Text
, verbosity :: Verbosity
, enableApps :: Bool
, remoteBuild :: Bool
, targetMachine :: Maybe Text
, retreive :: Maybe Text
, retreiveAs :: Maybe Text
, run :: Maybe Text
, overrides :: [(String, String)]
} deriving (Show)
data Verbosity = Verbose | Normal deriving (Show, Eq)
instance Default Args where
def = Args
data ArgsRemote = ArgsRemote
{ targetMachine :: Maybe Text
, retreive :: Maybe Text
, retreiveAs :: Maybe Text
} deriving (Show)
instance Default ArgsCommon where
def = ArgsCommon
{ verbosity = Normal,
argopkgs = "<argopkgs>",
enableApps = False,
remoteBuild = False,
run = Nothing,
targetMachine = Nothing,
retreive = Nothing,
retreiveAs = Nothing,
overrides = []
}
instance Default ArgsRemote where
def = ArgsRemote
{ targetMachine = Nothing,
retreive = Nothing,
retreiveAs = Nothing
}
targetParser :: Parser String
targetParser =
strArgument (metavar "TARGET" <> showDefault <> help "The build target.")
executorParser :: Parser Args
executorParser = do
argopkgs <- strOption
( long "argopkgs"
<> metavar "ARGOPKGS"
<> showDefault
<> value (argopkgs def)
<> help "Nix expression that produces the argopkgs source path."
)
verbosity <- flag
Normal
Verbose
(long "verbose" <> short 'v' <> help "Enable verbose mode")
enableApps <- flag
False
True
(long "provision_apps" <> short 'a' <> help
"Build and provision applications."
)
remoteBuild <- flag
False
True
(long "remote_build" <> short 'r' <> help
"Build on the remote rather than locally."
)
remoteParser :: Parser ArgsRemote
remoteParser = do
retreive <- optional $ strOption
(long "retreive" <> metavar "RELATIVE_PATH" <> help
"File/Folder to retreive from the remote machine."
......@@ -154,12 +142,27 @@ executorParser = do
(long "target_machine" <> metavar "USER@HOST" <> help
"Target machine. defaults to localhost via forking."
)
pure ArgsRemote {..}
commonParser :: Parser ArgsCommon
commonParser = do
argopkgs <- strOption
( long "argopkgs"
<> metavar "ARGOPKGS"
<> showDefault
<> value (argopkgs def)
<> help "Nix expression that produces the argopkgs source path."
)
verbosity <- flag
Normal
Verbose
(long "verbose" <> short 'v' <> help "Enable verbose mode")
overrides <- catMaybes <$> targets
run <- optional $ strOption
(long "run" <> metavar "COMMAND" <> help
"Command to run the environment instead of an interactive shell"
)
pure Args {..}
pure ArgsCommon {..}
where
targets :: Parser [Maybe (String, String)]
targets = traverse
......@@ -213,7 +216,7 @@ sudoRemoveFile printer desc filePath = do
cleanSocket :: FilePath -> Shell ()
cleanSocket = sudoRemoveFile printWarning "socket"
setupSystem :: Args -> Shell ()
setupSystem :: ArgsCommon -> Shell ()
setupSystem sa = do
printInfo "Setting the nix-build environment up."
printInfo "Cleaning sockets."
......@@ -252,8 +255,8 @@ setupSystem sa = do
empty
void $ printInfo "Done setting the environment for nix-build up."
nixArguments :: String -> Args -> [String]
nixArguments target Args {..} = [unpack argopkgs, "-A", target]
nixArguments :: String -> ArgsCommon -> [String]
nixArguments target ArgsCommon {..} = [unpack argopkgs, "-A", target]
++ concat [ ["--arg", longform <> "-src", p] | (longform, p) <- overrides ]
data NixCommand = NixBuild | NixShell
......@@ -261,8 +264,8 @@ toCommand :: IsString p => NixCommand -> p
toCommand NixBuild = "nix-build"
toCommand NixShell = "nix-shell"
wrap :: NixCommand -> String -> Args -> IO ()
wrap nixCommand target sa@Args {..} = sh $ do
wrap :: NixCommand -> String -> ArgsCommon -> IO ()
wrap nixCommand target sa@ArgsCommon {..} = sh $ do
when (verbosity == Verbose) $ liftIO $ print sa
_ <- setupSystem sa
printCommand $ pack nixc <> " " <> pack (unwords arglist)
......@@ -289,9 +292,13 @@ wrap nixCommand target sa@Args {..} = sh $ do
, "false"
]
remotely :: String -> ArgsCommon -> ArgsRemote -> IO ()
remotely _ _ _ = do
putStrLn "Remote argonix execution unsupported in this version yet."
{-nixshell :: IO ()-}
{-nixshell = undefined-}
{-Args {..} <- liftIO $ execParser opts-}
{-ArgsCommon {..} <- liftIO $ execParser opts-}
{--- building nixArguments (pure stuff) and shellArguments (impure stuff)-}
{-let nixArguments = ["-A", if enableApps then "expe" else "test"] ++ concat-}
......@@ -389,7 +396,7 @@ wrap nixCommand target sa@Args {..} = sh $ do
{-Nothing-}
{-where-}
{-opts = info-}
{-(executorParser <**> helper)-}
{-(commonParser <**> helper)-}
{-( fullDesc-}
{-<> progDesc "Argo environment provisioning/deployment/execution."-}
{-<> header "argonix"-}
......
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