on master help sign in
Merge branch 'develop' into eac@access-log-stdout
commit8afca75d463c69040398fc8b78469b88a1cb22ca authorElliot Cameron <3noch@users.noreply.github.com> dateThu 23 Jul 2020, 21:10 (6 years ago) parent06c9cf3656cee0
6 files changed+65−28
default.nix+1 haskell-overlays/obelisk.nix+4 lib/command/src/Obelisk/Command/Deploy.hs+15−15 lib/command/src/Obelisk/Command/Project.hs+10−4 lib/command/src/Obelisk/Command/Utils.hs+27−1 lib/command/src/Obelisk/Command/VmBuilder.hs+8−8
default.nix+1
@@ -131,6 +131,7 @@ in rec {
131131 }: {...}: {
132132 services.nginx = {
133133 enable = true;
134+ recommendedProxySettings = true;
134135 virtualHosts."${routeHost}" = {
135136 enableACME = enableHttps;
136137 forceSSL = enableHttps;
haskell-overlays/obelisk.nix+4
@@ -19,8 +19,12 @@ in
1919 obelisk-command = haskellLib.overrideCabal (self.callCabal2nix "obelisk-command" (obeliskCleanSource ../lib/command) {}) {
2020 librarySystemDepends = [
2121 pkgs.jre
22+ pkgs.git
2223 pkgs.nix
2324 pkgs.nix-prefetch-git
25+ pkgs.openssh
26+ pkgs.rsync
27+ pkgs.which
2428 (haskellLib.justStaticExecutables self.ghcid)
2529 ];
2630 };
lib/command/src/Obelisk/Command/Deploy.hs+15−15
@@ -85,13 +85,12 @@ deployInit' thunkPtr (DeployInitOpts deployDir sshKeyPath hostnames route adminE
8585 --accidentally create a production deployment that uses development
8686 --credentials to connect to some resources. This could result in, e.g.,
8787 --production data backed up to a dev environment.
88− withSpinner "Creating project configuration directories" $ do
89− callProcessAndLogOutput (Notice, Error) $
90− proc "mkdir" [ "-p"
91− , deployDir </> "config" </> "backend"
92− , deployDir </> "config" </> "common"
93− , deployDir </> "config" </> "frontend"
94− ]
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+ ]
9594
9695 let srcDir = deployDir </> "src"
9796 withSpinner ("Creating source thunk (" <> T.pack (makeRelative deployDir srcDir) <> ")") $ do
@@ -162,8 +161,8 @@ deployPush deployPath getNixBuilders = do
162161 "nix-copy-closure" ["-v", "--to", "--use-substitutes", "root@" <> host, "--gzip", outputPath]
163162 withSpinner "Uploading config" $ ifor_ buildOutputByHost $ \host _ -> do
164163 callProcessAndLogOutput (Notice, Warning) $
165− proc "rsync"
166− [ "-e ssh " <> unwords sshOpts
164+ proc rsyncPath
165+ [ "-e " <> sshPath <> " " <> unwords sshOpts
167166 , "-qarvz"
168167 , deployPath </> "config"
169168 , "root@" <> host <> ":/var/lib/backend"
@@ -171,9 +170,10 @@ deployPush deployPath getNixBuilders = do
171170 --TODO: Create GC root so we're sure our closure won't go away during this time period
172171 withSpinner "Switching to new configuration" $ ifor_ buildOutputByHost $ \host outputPath -> do
173172 callProcessAndLogOutput (Notice, Warning) $
174− proc "ssh" $ sshOpts <>
173+ proc sshPath $ sshOpts <>
175174 [ "root@" <> host
176175 , unwords
176+ -- Note that we don't want to $(staticWhich "nix-env") here, because this is executing on a remote machine
177177 [ "nix-env -p /nix/var/nix/profiles/system --set " <> outputPath
178178 , "&&"
179179 , "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
@@ -182,10 +182,10 @@ deployPush deployPath getNixBuilders = do
182182 isClean <- checkGitCleanStatus deployPath True
183183 when (not isClean) $ do
184184 withSpinner "Committing changes to Git" $ do
185− callProcessAndLogOutput (Debug, Error) $ proc "git"
186− ["-C", deployPath, "add", "."]
187− callProcessAndLogOutput (Debug, Error) $ proc "git"
188− ["-C", deployPath, "commit", "-m", "New deployment"]
185+ callProcessAndLogOutput (Debug, Error) $
186+ gitProc deployPath ["add", "."]
187+ callProcessAndLogOutput (Debug, Error) $
188+ gitProc deployPath ["commit", "-m", "New deployment"]
189189 putLog Notice $ "Deployed => " <> T.pack route
190190 where
191191 callProcess' envMap cmd args = do
@@ -315,7 +315,7 @@ readDeployConfig deployDir fname = liftIO $ do
315315
316316verifyHostKey :: MonadObelisk m => FilePath -> FilePath -> String -> m ()
317317verifyHostKey knownHostsPath keyPath hostName =
318− callProcessAndLogOutput (Notice, Warning) $ proc "ssh" $
318+ callProcessAndLogOutput (Notice, Warning) $ proc sshPath $
319319 sshArgs knownHostsPath keyPath True <>
320320 [ "root@" <> hostName
321321 , "-o", "NumberOfPasswordPrompts=0"
lib/command/src/Obelisk/Command/Project.hs+10−4
@@ -51,7 +51,7 @@ import Obelisk.App (MonadObelisk)
5151import Obelisk.CliApp
5252import Obelisk.Command.Nix
5353import Obelisk.Command.Thunk
54−import Obelisk.Command.Utils (nixBuildExePath, nixExePath, toNixPath)
54+import Obelisk.Command.Utils (nixBuildExePath, nixExePath, toNixPath, cp, nixShellPath)
5555
5656--TODO: Make this module resilient to random exceptions
5757
@@ -116,7 +116,7 @@ initProject source force = withSystemTempDirectory "ob-init" $ \tmpDir -> do
116116 skel <- nixBuildAttrWithCache implDir "skeleton" --TODO: I don't think there's actually any reason to cache this
117117
118118 callProcessAndLogOutput (Notice, Error) $
119− proc "cp"
119+ proc cp
120120 [ "-r"
121121 , "--preserve=links"
122122 , obDir
@@ -126,7 +126,7 @@ initProject source force = withSystemTempDirectory "ob-init" $ \tmpDir -> do
126126
127127 withSpinner "Copying project skeleton" $ do
128128 callProcessAndLogOutput (Notice, Error) $
129− proc "cp"
129+ proc cp
130130 [ "-r"
131131 , "--no-preserve=mode"
132132 , "-T"
@@ -137,6 +137,12 @@ initProject source force = withSystemTempDirectory "ob-init" $ \tmpDir -> do
137137 let configDir = "config"
138138 createDirectoryIfMissing False configDir
139139 mapM_ (createDirectoryIfMissing False . (configDir </>)) ["backend", "common", "frontend"]
140+ putLog Notice $ T.intercalate "\n"
141+ [ "An obelisk project has been successfully initialized. Next steps:"
142+ , " 'ob run': Start a development server"
143+ , " 'ob watch': Watch for changes without starting a server"
144+ , " 'ob repl': Load your project into GHCi"
145+ ]
140146
141147callHandoffOb
142148 :: MonadObelisk m
@@ -292,7 +298,7 @@ bashEscape :: String -> String
292298bashEscape = BSU.toString . bytes . bash . BSU.fromString
293299
294300nixShellRunProc :: NixShellConfig -> ProcessSpec
295−nixShellRunProc cfg = setDelegateCtlc True $ proc "nix-shell" $ runNixShellConfig cfg
301+nixShellRunProc cfg = setDelegateCtlc True $ proc nixShellPath $ runNixShellConfig cfg
296302
297303nixShellWithoutPkgs
298304 :: MonadObelisk m
lib/command/src/Obelisk/Command/Utils.hs+27−1
@@ -60,6 +60,32 @@ nixPrefetchGitPath = $(staticWhich "nix-prefetch-git")
6060nixPrefetchUrlPath :: FilePath
6161nixPrefetchUrlPath = $(staticWhich "nix-prefetch-url")
6262
63+nixShellPath :: FilePath
64+nixShellPath = $(staticWhich "nix-shell")
65+
66+rsyncPath :: FilePath
67+rsyncPath = $(staticWhich "rsync")
68+
69+sshPath :: FilePath
70+sshPath = $(staticWhich "ssh")
71+
72+gitPath :: FilePath
73+gitPath = $(staticWhich "git")
74+
75+whichPath :: FilePath
76+whichPath = $(staticWhich "which")
77+
78+sshKeygenPath :: FilePath
79+sshKeygenPath = $(staticWhich "ssh-keygen")
80+
81+-- $(staticWhich "docker") was intentionally omitted, at least for now
82+-- One concern is that I don't know how particular docker is about having the
83+-- CLI exe match the version of the docker daemon, which is largely outside of
84+-- the control of obelisk-command.
85+-- TODO: Investigate the tradeoffs associated with this choice
86+dockerPath :: FilePath
87+dockerPath = "docker"
88+
6389-- | Nix syntax requires relative paths to be prefixed by @./@ or
6490-- @../@. This will make a 'FilePath' that can be embedded in a Nix
6591-- expression.
@@ -97,7 +123,7 @@ initGit repo = do
97123 git ["commit", "-m", "Initial commit."]
98124
99125gitProcNoRepo :: [String] -> ProcessSpec
100−gitProcNoRepo args = setEnvOverride (M.singleton "GIT_TERMINAL_PROMPT" "0" <>) $ proc "git" args
126+gitProcNoRepo args = setEnvOverride (M.singleton "GIT_TERMINAL_PROMPT" "0" <>) $ proc gitPath args
101127
102128gitProc :: FilePath -> [String] -> ProcessSpec
103129gitProc repo = gitProcNoRepo . runGitInDir
lib/command/src/Obelisk/Command/VmBuilder.hs+8−8
@@ -21,7 +21,7 @@ import qualified System.Info
2121
2222import Obelisk.App (MonadObelisk, getObeliskUserStateDir)
2323import Obelisk.CliApp
24−import Obelisk.Command.Utils (rmPath)
24+import Obelisk.Command.Utils (rmPath, whichPath, sshKeygenPath, nixBuildExePath, dockerPath)
2525
2626-- | Generate the `--builders` argument string to enable the VM builder after ensuring it is available.
2727getNixBuildersArg :: MonadObelisk m => m String
@@ -35,7 +35,7 @@ getNixBuildersArg = do
3535
3636checkForNixDarwin :: MonadObelisk m => String -> m ()
3737checkForNixDarwin sshIdFile = do
38− (exitCode, _, _) <- readCreateProcessWithExitCode $ proc "which" ["darwin-rebuild"]
38+ (exitCode, _, _) <- readCreateProcessWithExitCode $ proc whichPath ["darwin-rebuild"]
3939 unless (exitCode == ExitSuccess) $ failWith $ T.intercalate "\n"
4040 [ "Deployments from macOS require nix-darwin to be installed."
4141 , "Follow the installation instructions here: https://github.com/LnL7/nix-darwin"
@@ -67,7 +67,7 @@ containerExists :: MonadObelisk m => FilePath -> m Bool
6767containerExists stateDir = handle (\(_ :: IOError) -> failWith needDockerMsg) $ do
6868 containerNames <- fmap (map T.strip . T.lines) $
6969 readProcessAndLogStderr Error $
70− proc "docker" ["container", "list", "--all", "--format", "{{.Names}}"]
70+ proc dockerPath ["container", "list", "--all", "--format", "{{.Names}}"]
7171 let exists = containerName `elem` containerNames
7272 when exists $ testLinuxBuild stateDir
7373 pure exists
@@ -85,7 +85,7 @@ containerSshPort = 2222
8585startContainer :: MonadObelisk m => m ()
8686startContainer = withSpinner "Starting VM builder" $
8787 callProcessAndLogOutput (Debug, Debug) $
88− proc "docker" ["start", containerName]
88+ proc dockerPath ["start", containerName]
8989
9090-- | Creates the Docker container; assumes it does not exist.
9191setupNixDocker :: MonadObelisk m => FilePath -> m ()
@@ -98,12 +98,12 @@ setupNixDocker stateDir = withSpinner ("Creating Docker container named " <> con
9898 callProcessAndLogOutput (Debug, Error) $
9999 proc rmPath ["-f", stateDir </> sshKeyFileName, stateDir </> sshKeyFileName <.> "pub"]
100100 callProcessAndLogOutput (Debug, Error) $
101− proc "ssh-keygen" ["-t", "ed25519", "-f", stateDir </> sshKeyFileName, "-P", ""]
101+ proc sshKeygenPath ["-t", "ed25519", "-f", stateDir </> sshKeyFileName, "-P", ""]
102102
103103 -- Build the docker container (which uses the SSH keys in the 'ssh' folder)
104104 containerId <- fmap T.strip $ readProcessAndLogStderr Error $
105− proc "docker" ["build", stateDir, "--quiet"]
106− callProcessAndLogOutput (Debug, Error) $ proc "docker"
105+ proc dockerPath ["build", stateDir, "--quiet"]
106+ callProcessAndLogOutput (Debug, Error) $ proc dockerPath
107107 [ "run"
108108 , "--restart", "always"
109109 , "--detach"
@@ -155,7 +155,7 @@ testLinuxBuild :: MonadObelisk m => FilePath -> m ()
155155testLinuxBuild stateDir
156156 | System.Info.os == "linux" = failWith "Using the docker builder is not necessary on linux."
157157 | otherwise = do
158− (exitCode, _stdout, stderr) <- readCreateProcessWithExitCode $ proc "nix-build"
158+ (exitCode, _stdout, stderr) <- readCreateProcessWithExitCode $ proc nixBuildExePath
159159 [ "--no-out-link"
160160 , "-E", "(import <nixpkgs> { system = \"x86_64-linux\"; }).writeText \"test\" builtins.currentTime"
161161 , "--builders", nixBuildersArgString stateDir