-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Make rebooting a flag for "ob deploy push" #1036
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,10 @@ | |
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE PackageImports #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TupleSections #-} | ||
{-# LANGUAGE PackageImports #-} | ||
{- ORMOLU_DISABLE -} | ||
module Obelisk.Command where | ||
|
||
import Control.Monad.IO.Class (MonadIO, liftIO) | ||
|
@@ -144,7 +145,7 @@ packageNames = some (strArgument (metavar "PACKAGE-NAME...")) | |
deployCommand :: ArgsConfig -> Parser DeployCommand | ||
deployCommand cfg = hsubparser $ mconcat | ||
[ command "init" $ info (DeployCommand_Init <$> deployInitOpts) $ progDesc "Initialize a deployment configuration directory" | ||
, command "push" $ info (DeployCommand_Push <$> remoteBuilderParser) mempty | ||
, command "push" $ info (DeployCommand_Push <$> remoteBuilderParser <*> reboot) mempty | ||
, command "test" $ info (DeployCommand_Test <$> platformP) $ progDesc "Test your obelisk project from a mobile platform." | ||
, command "update" $ info (pure DeployCommand_Update) $ progDesc "Update the deployment's src thunk to latest" | ||
] | ||
|
@@ -154,6 +155,9 @@ deployCommand cfg = hsubparser $ mconcat | |
, command "ios" $ info ((,) <$> pure IOS <*> fmap pure (strArgument (metavar "TEAMID" <> help "Your Team ID - found in the Apple developer portal"))) mempty | ||
] | ||
|
||
reboot :: Parser Bool | ||
reboot = flag False True (long "reboot") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rebooting on deploy is currently the default behaviour, this shouldn't change that. Otherwise users may be surprised to see that their running apps aren't the latest version following a deployment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd argue that it should've never been turned on by default in the first place, This should've always been the users choice to actually reboot There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're talking about restarting the backend service, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was mistaken this is referring to the restart of the machine the backend service is running on. The backend service will still be restarted as part of a deploy that did not include the |
||
|
||
remoteBuilderParser :: Parser (Maybe RemoteBuilder) | ||
remoteBuilderParser = | ||
flag (if enabledByDefault then enabled else Nothing) enabled (mconcat | ||
|
@@ -171,6 +175,7 @@ deployCommand cfg = hsubparser $ mconcat | |
flagDesc = "managed Linux virtual machine as a Nix remote builder (requires Docker)" | ||
|
||
|
||
|
||
deployInitOpts :: Parser DeployInitOpts | ||
deployInitOpts = DeployInitOpts | ||
<$> strArgument (action "directory" <> metavar "DEPLOYDIR" <> help "Path to a directory where the deployment repository will be initialized") | ||
|
@@ -187,7 +192,7 @@ data RemoteBuilder = RemoteBuilder_ObeliskVM | |
|
||
data DeployCommand | ||
= DeployCommand_Init DeployInitOpts | ||
| DeployCommand_Push (Maybe RemoteBuilder) | ||
| DeployCommand_Push (Maybe RemoteBuilder) Bool | ||
| DeployCommand_Test (PlatformDeployment, [String]) | ||
| DeployCommand_Update | ||
deriving Show | ||
|
@@ -424,12 +429,12 @@ ob = \case | |
ObCommand_Init source force -> initProject source force | ||
ObCommand_Deploy dc -> case dc of | ||
DeployCommand_Init deployOpts -> withProjectRoot "." $ \root -> deployInit deployOpts root | ||
DeployCommand_Push remoteBuilder -> do | ||
DeployCommand_Push remoteBuilder reboot -> do | ||
deployPath <- liftIO $ canonicalizePath "." | ||
deployBuilders <- case remoteBuilder of | ||
Nothing -> pure [] | ||
Just RemoteBuilder_ObeliskVM -> (:[]) <$> VmBuilder.getNixBuildersArg | ||
deployPush deployPath deployBuilders | ||
deployPush deployPath deployBuilders reboot | ||
DeployCommand_Update -> deployUpdate "." | ||
DeployCommand_Test (platform, extraArgs) -> deployMobile platform extraArgs | ||
ObCommand_Run interpretPathsList certDir servePort -> withInterpretPaths interpretPathsList (run certDir servePort) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,12 @@ | |
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE PackageImports #-} | ||
{-# LANGUAGE QuasiQuotes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE PackageImports #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE ViewPatterns #-} | ||
{- ORMOLU_DISABLE -} | ||
{-| | ||
Description: | ||
Implementation of the CLI deploy commands. Deployment is done by intializing | ||
|
@@ -161,8 +162,9 @@ deployPush | |
-- ^ Path to the staging directory | ||
-> [String] | ||
-- ^ nix builders arg string for the nix-build that builds the deployment artefacts | ||
-> Bool | ||
-> m () | ||
deployPush deployPath builders = do | ||
deployPush deployPath builders reboot = do | ||
hosts <- Set.fromList . filter (/= mempty) . lines <$> readDeployConfig deployPath "backend_hosts" | ||
adminEmail <- readDeployConfig deployPath "admin_email" | ||
enableHttps <- read <$> readDeployConfig deployPath "enable_https" | ||
|
@@ -225,7 +227,7 @@ deployPush deployPath builders = do | |
[ "root@" <> host | ||
, unwords | ||
[ "bash -c" | ||
, bashEscape (deployActivationScript outputPath) | ||
, bashEscape (deployActivationScript outputPath reboot) | ||
] | ||
] | ||
isClean <- checkGitCleanStatus deployPath True | ||
|
@@ -247,8 +249,9 @@ deployPush deployPath builders = do | |
deployActivationScript | ||
:: String | ||
-- ^ The out path of the configuration to activate | ||
-> Bool | ||
-> String | ||
deployActivationScript outPath = | ||
deployActivationScript outPath reboot = | ||
-- Note that we don't want to $(staticWhich "nix-env") here, because this is executing on a remote machine | ||
-- This logic follows the nixos auto-upgrade module as of writing. | ||
-- If the workflow is added to switch-to-configuration proper, we can simplify this: | ||
|
@@ -258,7 +261,8 @@ nix-env -p /nix/var/nix/profiles/system --set "${bashEscape outPath}" | |
/nix/var/nix/profiles/system/bin/switch-to-configuration boot | ||
booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})" | ||
built="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})" | ||
if [ "$booted" = "$built" ]; then | ||
echo "${bashEscape (show reboot)}" | ||
if [[ "$booted" = "$built" && "${bashEscape (show reboot)}" == "${bashEscape (show False)}" ]]; then | ||
Comment on lines
+264
to
+265
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to me like it might be better to just template in the reboot if the flag is set rather than doing logic in bash |
||
/nix/var/nix/profiles/system/bin/switch-to-configuration switch | ||
else | ||
/run/current-system/sw/bin/shutdown -r +1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should include formatting app specific pragmas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree