@@ -17,6 +17,7 @@ import Data.Bits
1717import qualified Data.ByteString.Lazy as BSL
1818import Data.Default
1919import qualified Data.Map as Map
20+import Data.Maybe (isJust)
2021import qualified Data.Set as Set
2122import Data.String.Here.Interpolated (i)
2223import qualified Data.Text as T
@@ -85,12 +86,13 @@ deployInit' thunkPtr (DeployInitOpts deployDir sshKeyPath hostnames route adminE
8586 --accidentally create a production deployment that uses development
8687 --credentials to connect to some resources. This could result in, e.g.,
8788 --production data backed up to a dev environment.
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− ]
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+ ]
9496
9597 let srcDir = deployDir </> "src"
9698 withSpinner ("Creating source thunk (" <> T.pack (makeRelative deployDir srcDir) <> ")") $ do
@@ -124,14 +126,15 @@ deployPush deployPath getNixBuilders = do
124126 route <- readDeployConfig deployPath $ "config" </> "common" </> "route"
125127 routeHost <- getHostFromRoute enableHttps route
126128 let srcPath = deployPath </> "src"
127− thunkPtr <- readThunk srcPath >>= \case
128− Right (ThunkData_Packed _ ptr) -> return ptr
129+ thunkPtr' <- readThunk srcPath >>= \case
130+ Right (ThunkData_Packed _ ptr) -> return $ Just ptr
129131 Right ThunkData_Checkout -> do
130132 checkGitCleanStatus srcPath True >>= \case
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."
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."
133136 Left err -> failWith $ "ob deploy push: couldn't read src thunk: " <> T.pack (show err)
134− let version = show . _thunkRev_commit $ _thunkPtr_rev thunkPtr
137+ let version' = show . _thunkRev_commit . _thunkPtr_rev <$> thunkPtr'
135138 builders <- getNixBuilders
136139 let moduleFile = deployPath </> "module.nix"
137140 moduleFileExists <- liftIO $ doesFileExist moduleFile
@@ -148,7 +151,7 @@ deployPush deployPath getNixBuilders = do
148151 [ strArg "hostName" host
149152 , strArg "adminEmail" adminEmail
150153 , strArg "routeHost" routeHost
151− , strArg "version" version
154+ , strArg "version" $ maybe "Deployment was done with a dirty source tree" id version'
152155 , boolArg "enableHttps" enableHttps
153156 ] <> [rawArg "module" ("import " <> toNixPath moduleFile) | moduleFileExists ])
154157 & nixCmdConfig_builders .~ builders
@@ -161,8 +164,8 @@ deployPush deployPath getNixBuilders = do
161164 "nix-copy-closure" ["-v", "--to", "--use-substitutes", "root@" <> host, "--gzip", outputPath]
162165 withSpinner "Uploading config" $ ifor_ buildOutputByHost $ \host _ -> do
163166 callProcessAndLogOutput (Notice, Warning) $
164− proc rsyncPath
165− [ "-e " <> sshPath <> " " <> unwords sshOpts
167+ proc "rsync"
168+ [ "-e ssh " <> unwords sshOpts
166169 , "-qarvz"
167170 , deployPath </> "config"
168171 , "root@" <> host <> ":/var/lib/backend"
@@ -170,22 +173,22 @@ deployPush deployPath getNixBuilders = do
170173 --TODO: Create GC root so we're sure our closure won't go away during this time period
171174 withSpinner "Switching to new configuration" $ ifor_ buildOutputByHost $ \host outputPath -> do
172175 callProcessAndLogOutput (Notice, Warning) $
173− proc sshPath $ sshOpts <>
176+ proc "ssh" $ sshOpts <>
174177 [ "root@" <> host
175178 , unwords
176− -- Note that we don't want to $(staticWhich "nix-env") here, because this is executing on a remote machine
177179 [ "nix-env -p /nix/var/nix/profiles/system --set " <> outputPath
178180 , "&&"
179181 , "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
180182 ]
181183 ]
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"]
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"]
189192 putLog Notice $ "Deployed => " <> T.pack route
190193 where
191194 callProcess' envMap cmd args = do
@@ -315,7 +318,7 @@ readDeployConfig deployDir fname = liftIO $ do
315318
316319verifyHostKey :: MonadObelisk m => FilePath -> FilePath -> String -> m ()
317320verifyHostKey knownHostsPath keyPath hostName =
318− callProcessAndLogOutput (Notice, Warning) $ proc sshPath $
321+ callProcessAndLogOutput (Notice, Warning) $ proc "ssh" $
319322 sshArgs knownHostsPath keyPath True <>
320323 [ "root@" <> hostName
321324 , "-o", "NumberOfPasswordPrompts=0"