@@ -17,7 +17,6 @@ import Data.Bits
1717import qualified Data.ByteString.Lazy as BSL
1818import Data.Default
1919import qualified Data.Map as Map
20−import Data.Maybe (isJust)
2120import qualified Data.Set as Set
2221import Data.String.Here.Interpolated (i)
2322import qualified Data.Text as T
@@ -86,13 +85,12 @@ deployInit' thunkPtr (DeployInitOpts deployDir sshKeyPath hostnames route adminE
8685 --accidentally create a production deployment that uses development
8786 --credentials to connect to some resources. This could result in, e.g.,
8887 --production data backed up to a dev environment.
89− withSpinner "Creating project configuration directories" $ do
90− callProcessAndLogOutput (Notice, Error) $
91− proc "mkdir" [ "-p"
92− , deployDir </> "config" </> "backend"
93− , deployDir </> "config" </> "common"
94− , deployDir </> "config" </> "frontend"
95− ]
88+ withSpinner "Creating project configuration directories" $ liftIO $ do
89+ mapM_ (createDirectoryIfMissing True)
90+ [ deployDir </> "config" </> "backend"
91+ , deployDir </> "config" </> "common"
92+ , deployDir </> "config" </> "frontend"
93+ ]
9694
9795 let srcDir = deployDir </> "src"
9896 withSpinner ("Creating source thunk (" <> T.pack (makeRelative deployDir srcDir) <> ")") $ do
@@ -126,15 +124,14 @@ deployPush deployPath getNixBuilders = do
126124 route <- readDeployConfig deployPath $ "config" </> "common" </> "route"
127125 routeHost <- getHostFromRoute enableHttps route
128126 let srcPath = deployPath </> "src"
129− thunkPtr' <- readThunk srcPath >>= \case
130− Right (ThunkData_Packed _ ptr) -> return $ Just ptr
127+ thunkPtr <- readThunk srcPath >>= \case
128+ Right (ThunkData_Packed _ ptr) -> return ptr
131129 Right ThunkData_Checkout -> do
132130 checkGitCleanStatus srcPath True >>= \case
133− True -> Just <$> packThunk (ThunkPackConfig False (ThunkConfig Nothing)) srcPath
134− False -> Nothing <$ putLog Warning "Skipping packing of src thunk; won't be able to automatically commit this deployment"
135− -- failWith $ T.pack $ "ob deploy push: ensure " <> srcPath <> " has no pending changes and latest is pushed upstream."
131+ True -> packThunk (ThunkPackConfig False (ThunkConfig Nothing)) srcPath
132+ False -> failWith $ T.pack $ "ob deploy push: ensure " <> srcPath <> " has no pending changes and latest is pushed upstream."
136133 Left err -> failWith $ "ob deploy push: couldn't read src thunk: " <> T.pack (show err)
137− let version' = show . _thunkRev_commit . _thunkPtr_rev <$> thunkPtr'
134+ let version = show . _thunkRev_commit $ _thunkPtr_rev thunkPtr
138135 builders <- getNixBuilders
139136 let moduleFile = deployPath </> "module.nix"
140137 moduleFileExists <- liftIO $ doesFileExist moduleFile
@@ -151,7 +148,7 @@ deployPush deployPath getNixBuilders = do
151148 [ strArg "hostName" host
152149 , strArg "adminEmail" adminEmail
153150 , strArg "routeHost" routeHost
154− , strArg "version" $ maybe "Deployment was done with a dirty source tree" id version'
151+ , strArg "version" version
155152 , boolArg "enableHttps" enableHttps
156153 ] <> [rawArg "module" ("import " <> toNixPath moduleFile) | moduleFileExists ])
157154 & nixCmdConfig_builders .~ builders
@@ -164,8 +161,8 @@ deployPush deployPath getNixBuilders = do
164161 "nix-copy-closure" ["-v", "--to", "--use-substitutes", "root@" <> host, "--gzip", outputPath]
165162 withSpinner "Uploading config" $ ifor_ buildOutputByHost $ \host _ -> do
166163 callProcessAndLogOutput (Notice, Warning) $
167− proc "rsync"
168− [ "-e ssh " <> unwords sshOpts
164+ proc rsyncPath
165+ [ "-e " <> sshPath <> " " <> unwords sshOpts
169166 , "-qarvz"
170167 , deployPath </> "config"
171168 , "root@" <> host <> ":/var/lib/backend"
@@ -173,22 +170,22 @@ deployPush deployPath getNixBuilders = do
173170 --TODO: Create GC root so we're sure our closure won't go away during this time period
174171 withSpinner "Switching to new configuration" $ ifor_ buildOutputByHost $ \host outputPath -> do
175172 callProcessAndLogOutput (Notice, Warning) $
176− proc "ssh" $ sshOpts <>
173+ proc sshPath $ sshOpts <>
177174 [ "root@" <> host
178175 , unwords
176+ -- Note that we don't want to $(staticWhich "nix-env") here, because this is executing on a remote machine
179177 [ "nix-env -p /nix/var/nix/profiles/system --set " <> outputPath
180178 , "&&"
181179 , "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
182180 ]
183181 ]
184− when (isJust version') $ do
185− isClean <- checkGitCleanStatus deployPath True
186− when (not isClean) $ do
187− withSpinner "Committing changes to Git" $ do
188− callProcessAndLogOutput (Debug, Error) $ proc "git"
189− ["-C", deployPath, "add", "."]
190− callProcessAndLogOutput (Debug, Error) $ proc "git"
191− ["-C", deployPath, "commit", "-m", "New deployment"]
182+ isClean <- checkGitCleanStatus deployPath True
183+ when (not isClean) $ do
184+ withSpinner "Committing changes to Git" $ do
185+ callProcessAndLogOutput (Debug, Error) $
186+ gitProc deployPath ["add", "."]
187+ callProcessAndLogOutput (Debug, Error) $
188+ gitProc deployPath ["commit", "-m", "New deployment"]
192189 putLog Notice $ "Deployed => " <> T.pack route
193190 where
194191 callProcess' envMap cmd args = do
@@ -318,7 +315,7 @@ readDeployConfig deployDir fname = liftIO $ do
318315
319316verifyHostKey :: MonadObelisk m => FilePath -> FilePath -> String -> m ()
320317verifyHostKey knownHostsPath keyPath hostName =
321− callProcessAndLogOutput (Notice, Warning) $ proc "ssh" $
318+ callProcessAndLogOutput (Notice, Warning) $ proc sshPath $
322319 sshArgs knownHostsPath keyPath True <>
323320 [ "root@" <> hostName
324321 , "-o", "NumberOfPasswordPrompts=0"