@@ -1,11 +1,13 @@
1+{-# LANGUAGE DeriveGeneric #-}
12{-# LANGUAGE FlexibleContexts #-}
23{-# LANGUAGE LambdaCase #-}
34{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE QuasiQuotes #-}
46{-# LANGUAGE ScopedTypeVariables #-}
57{-# LANGUAGE ViewPatterns #-}
6−{-# LANGUAGE DeriveGeneric #-}
78module Obelisk.Command.Deploy where
89
10+import Control.Applicative (liftA2)
911import Control.Lens
1012import Control.Monad
1113import Control.Monad.Catch (Exception (displayException), MonadThrow, bracket, throwM, try)
@@ -16,6 +18,7 @@ import qualified Data.ByteString.Lazy as BSL
1618import Data.Default
1719import qualified Data.Map as Map
1820import qualified Data.Set as Set
21+import Data.String.Here.Interpolated (i)
1922import qualified Data.Text as T
2023import qualified Data.Text.IO as T
2124import GHC.Generics
@@ -36,18 +39,32 @@ import Obelisk.Command.Project
3639import Obelisk.Command.Thunk
3740import Obelisk.Command.Utils
3841
42+data DeployInitOpts = DeployInitOpts
43+ { _deployInitOpts_outputDir :: FilePath
44+ , _deployInitOpts_sshKey :: FilePath
45+ , _deployInitOpts_hostname :: [String]
46+ , _deployInitOpts_route :: String
47+ , _deployInitOpts_adminEmail :: String
48+ , _deployInitOpts_enableHttps :: Bool
49+ } deriving Show
50+
51+deployInit :: MonadObelisk m => DeployInitOpts -> FilePath -> m ()
52+deployInit deployOpts root = do
53+ let deployDir = _deployInitOpts_outputDir deployOpts
54+ rootEqualsTarget <- liftIO $ liftA2 equalFilePath (canonicalizePath root) (canonicalizePath deployDir)
55+ when rootEqualsTarget $
56+ failWith [i|Deploy directory ${deployDir} should not be the same as project root.|]
57+ thunkPtr <- readThunk root >>= \case
58+ Right (ThunkData_Packed _ ptr) -> return ptr
59+ _ -> getThunkPtr False root Nothing
60+ deployInit' thunkPtr deployOpts
3961
40−deployInit
62+deployInit'
4163 :: MonadObelisk m
4264 => ThunkPtr
43− -> FilePath
44− -> FilePath
45− -> [String] -- ^ hostnames
46− -> String -- ^ route
47− -> String -- ^ admin email
48− -> Bool -- ^ enable https
65+ -> DeployInitOpts
4966 -> m ()
50−deployInit thunkPtr deployDir sshKeyPath hostnames route adminEmail enableHttps = do
67+deployInit' thunkPtr (DeployInitOpts deployDir sshKeyPath hostnames route adminEmail enableHttps) = do
5168 liftIO $ createDirectoryIfMissing True deployDir
5269 localKey <- withSpinner ("Preparing " <> T.pack deployDir) $ do
5370 localKey <- liftIO (doesFileExist sshKeyPath) >>= \case