@@ -17,6 +17,7 @@ import Data.Bits
17import qualified Data.ByteString.Lazy as BSL
17import qualified Data.ByteString.Lazy as BSL
18import Data.Default
18import Data.Default
19import qualified Data.Map as Map
19import qualified Data.Map as Map
20+import Data.Maybe (isJust)
20import qualified Data.Set as Set
21import qualified Data.Set as Set
21import Data.String.Here.Interpolated (i)
22import Data.String.Here.Interpolated (i)
22import qualified Data.Text as T
23import qualified Data.Text as T
@@ -85,12 +86,13 @@ deployInit' thunkPtr (DeployInitOpts deployDir sshKeyPath hostnames route adminE
85 --accidentally create a production deployment that uses development
86 --accidentally create a production deployment that uses development
86 --credentials to connect to some resources. This could result in, e.g.,
87 --credentials to connect to some resources. This could result in, e.g.,
87 --production data backed up to a dev environment.
88 --production data backed up to a dev environment.
88− withSpinner "Creating project configuration directories" $ liftIO $ do
89+ withSpinner "Creating project configuration directories" $ do
89− mapM_ (createDirectoryIfMissing True)
90+ callProcessAndLogOutput (Notice, Error) $
90− [ deployDir </> "config" </> "backend"
92+ , deployDir </> "config" </> "backend"
91− , deployDir </> "config" </> "common"
93+ , deployDir </> "config" </> "common"
92− , deployDir </> "config" </> "frontend"
94+ , deployDir </> "config" </> "frontend"
95 let srcDir = deployDir </> "src"
97 let srcDir = deployDir </> "src"
96 withSpinner ("Creating source thunk (" <> T.pack (makeRelative deployDir srcDir) <> ")") $ do
98 withSpinner ("Creating source thunk (" <> T.pack (makeRelative deployDir srcDir) <> ")") $ do
@@ -124,14 +126,15 @@ deployPush deployPath getNixBuilders = do
124 route <- readDeployConfig deployPath $ "config" </> "common" </> "route"
126 route <- readDeployConfig deployPath $ "config" </> "common" </> "route"
125 routeHost <- getHostFromRoute enableHttps route
127 routeHost <- getHostFromRoute enableHttps route
126 let srcPath = deployPath </> "src"
128 let srcPath = deployPath </> "src"
127− thunkPtr <- readThunk srcPath >>= \case
129+ thunkPtr' <- readThunk srcPath >>= \case
128− Right (ThunkData_Packed _ ptr) -> return ptr
130+ Right (ThunkData_Packed _ ptr) -> return $ Just ptr
129 Right ThunkData_Checkout -> do
131 Right ThunkData_Checkout -> do
130 checkGitCleanStatus srcPath True >>= \case
132 checkGitCleanStatus srcPath True >>= \case
131− True -> packThunk (ThunkPackConfig False (ThunkConfig Nothing)) srcPath
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"
132− False -> failWith $ T.pack $ "ob deploy push: ensure " <> srcPath <> " has no pending changes and latest is pushed upstream."
135+ -- failWith $ T.pack $ "ob deploy push: ensure " <> srcPath <> " has no pending changes and latest is pushed upstream."
133 Left err -> failWith $ "ob deploy push: couldn't read src thunk: " <> T.pack (show err)
136 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'
135 builders <- getNixBuilders
138 builders <- getNixBuilders
136 let moduleFile = deployPath </> "module.nix"
139 let moduleFile = deployPath </> "module.nix"
137 moduleFileExists <- liftIO $ doesFileExist moduleFile
140 moduleFileExists <- liftIO $ doesFileExist moduleFile
@@ -148,7 +151,7 @@ deployPush deployPath getNixBuilders = do
148 [ strArg "hostName" host
151 [ strArg "hostName" host
149 , strArg "adminEmail" adminEmail
152 , strArg "adminEmail" adminEmail
150 , strArg "routeHost" routeHost
153 , strArg "routeHost" routeHost
151− , strArg "version" version
154+ , strArg "version" $ maybe "Deployment was done with a dirty source tree" id version'
152 , boolArg "enableHttps" enableHttps
155 , boolArg "enableHttps" enableHttps
153 ] <> [rawArg "module" ("import " <> toNixPath moduleFile) | moduleFileExists ])
156 ] <> [rawArg "module" ("import " <> toNixPath moduleFile) | moduleFileExists ])
154 & nixCmdConfig_builders .~ builders
157 & nixCmdConfig_builders .~ builders
@@ -161,8 +164,8 @@ deployPush deployPath getNixBuilders = do
161 "nix-copy-closure" ["-v", "--to", "--use-substitutes", "root@" <> host, "--gzip", outputPath]
164 "nix-copy-closure" ["-v", "--to", "--use-substitutes", "root@" <> host, "--gzip", outputPath]
162 withSpinner "Uploading config" $ ifor_ buildOutputByHost $ \host _ -> do
165 withSpinner "Uploading config" $ ifor_ buildOutputByHost $ \host _ -> do
163 callProcessAndLogOutput (Notice, Warning) $
166 callProcessAndLogOutput (Notice, Warning) $
164− proc rsyncPath
167+ proc "rsync"
165− [ "-e " <> sshPath <> " " <> unwords sshOpts
168+ [ "-e ssh " <> unwords sshOpts
166 , "-qarvz"
169 , "-qarvz"
167 , deployPath </> "config"
170 , deployPath </> "config"
168 , "root@" <> host <> ":/var/lib/backend"
171 , "root@" <> host <> ":/var/lib/backend"
@@ -170,22 +173,22 @@ deployPush deployPath getNixBuilders = do
170 --TODO: Create GC root so we're sure our closure won't go away during this time period
173 --TODO: Create GC root so we're sure our closure won't go away during this time period
171 withSpinner "Switching to new configuration" $ ifor_ buildOutputByHost $ \host outputPath -> do
174 withSpinner "Switching to new configuration" $ ifor_ buildOutputByHost $ \host outputPath -> do
172 callProcessAndLogOutput (Notice, Warning) $
175 callProcessAndLogOutput (Notice, Warning) $
173− proc sshPath $ sshOpts <>
176+ proc "ssh" $ sshOpts <>
174 [ "root@" <> host
177 [ "root@" <> host
175 , unwords
178 , unwords
176− -- Note that we don't want to $(staticWhich "nix-env") here, because this is executing on a remote machine
177 [ "nix-env -p /nix/var/nix/profiles/system --set " <> outputPath
179 [ "nix-env -p /nix/var/nix/profiles/system --set " <> outputPath
179 , "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
181 , "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
184+ when (isJust version') $ do
182− isClean <- checkGitCleanStatus deployPath True
185+ isClean <- checkGitCleanStatus deployPath True
183− when (not isClean) $ do
186+ when (not isClean) $ do
184− withSpinner "Committing changes to Git" $ do
187+ withSpinner "Committing changes to Git" $ do
185− callProcessAndLogOutput (Debug, Error) $
188+ callProcessAndLogOutput (Debug, Error) $ proc "git"
186− gitProc deployPath ["add", "."]
189+ ["-C", deployPath, "add", "."]
187− callProcessAndLogOutput (Debug, Error) $
190+ callProcessAndLogOutput (Debug, Error) $ proc "git"
188− gitProc deployPath ["commit", "-m", "New deployment"]
191+ ["-C", deployPath, "commit", "-m", "New deployment"]
189 putLog Notice $ "Deployed => " <> T.pack route
192 putLog Notice $ "Deployed => " <> T.pack route
191 callProcess' envMap cmd args = do
194 callProcess' envMap cmd args = do
@@ -315,7 +318,7 @@ readDeployConfig deployDir fname = liftIO $ do
316verifyHostKey :: MonadObelisk m => FilePath -> FilePath -> String -> m ()
319verifyHostKey :: MonadObelisk m => FilePath -> FilePath -> String -> m ()
317verifyHostKey knownHostsPath keyPath hostName =
320verifyHostKey knownHostsPath keyPath hostName =
318− callProcessAndLogOutput (Notice, Warning) $ proc sshPath $
321+ callProcessAndLogOutput (Notice, Warning) $ proc "ssh" $
319 sshArgs knownHostsPath keyPath True <>
322 sshArgs knownHostsPath keyPath True <>
320 [ "root@" <> hostName
323 [ "root@" <> hostName
321 , "-o", "NumberOfPasswordPrompts=0"
324 , "-o", "NumberOfPasswordPrompts=0"