From 9d858220db917b343d46e4b4fef542625175d298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Estrella?= <2049686+sestrella@users.noreply.github.com> Date: Fri, 22 Jan 2021 09:43:31 -0500 Subject: [PATCH 01/20] Add configWorkingDirectory to Config --- .gitignore | 2 ++ src/System/Hapistrano/Config.hs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index b835d6b..b5118a3 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ cabal.sandbox.config .stack-work/ dist-newstyle result +nix/ +shell.nix diff --git a/src/System/Hapistrano/Config.hs b/src/System/Hapistrano/Config.hs index 5e83386..7513104 100644 --- a/src/System/Hapistrano/Config.hs +++ b/src/System/Hapistrano/Config.hs @@ -62,6 +62,7 @@ data Config = Config -- ^ The number of releases to keep, the '--keep-releases' argument passed via -- the CLI takes precedence over this value. If neither CLI or configuration -- file value is specified, it defaults to 5 + , configWorkingDirectory :: !(Maybe FilePath) } deriving (Eq, Ord, Show) -- | Information about source and destination locations of a file\/directory @@ -115,6 +116,7 @@ instance FromJSON Config where configTargetSystem <- o .:? "linux" .!= GNULinux configReleaseFormat <- o .:? "release_format" configKeepReleases <- o .:? "keep_releases" + configWorkingDirectory <- o .:? "working_directory" return Config {..} instance FromJSON CopyThing where From 4c13a5f6a4e047c8b50cc40852fc38e11d466dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Estrella?= <2049686+sestrella@users.noreply.github.com> Date: Fri, 22 Jan 2021 09:49:17 -0500 Subject: [PATCH 02/20] Pass workingDirectory as an argument to playScript --- app/Main.hs | 2 +- src/System/Hapistrano.hs | 9 +++++---- src/System/Hapistrano/Config.hs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index a544320..9ca39eb 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -158,7 +158,7 @@ main = do (Hap.linkToShared configTargetSystem rpath configDeployPath) forM_ configLinkedDirs (Hap.linkToShared configTargetSystem rpath configDeployPath) - forM_ configBuildScript (Hap.playScript configDeployPath release) + forM_ configBuildScript (Hap.playScript configDeployPath release configWorkingDirectory) Hap.registerReleaseAsComplete configDeployPath release Hap.activateRelease configTargetSystem configDeployPath release Hap.dropOldReleases configDeployPath keepReleases diff --git a/src/System/Hapistrano.hs b/src/System/Hapistrano.hs index 1eb45de..c234031 100644 --- a/src/System/Hapistrano.hs +++ b/src/System/Hapistrano.hs @@ -139,11 +139,12 @@ dropOldReleases deployPath n = do -- | Play the given script switching to directory of given release. playScript - :: Path Abs Dir -- ^ Deploy path - -> Release -- ^ Release identifier - -> [GenericCommand] -- ^ Commands to execute + :: Path Abs Dir -- ^ Deploy path + -> Release -- ^ Release identifier + -> Maybe (Path Rel Dir) -- ^ Working directory + -> [GenericCommand] -- ^ Commands to execute -> Hapistrano () -playScript deployDir release cmds = do +playScript deployDir release mworkingDir cmds = do rpath <- releasePath deployDir release forM_ cmds (execWithInheritStdout . Cd rpath) diff --git a/src/System/Hapistrano/Config.hs b/src/System/Hapistrano/Config.hs index 7513104..66aab59 100644 --- a/src/System/Hapistrano/Config.hs +++ b/src/System/Hapistrano/Config.hs @@ -62,7 +62,7 @@ data Config = Config -- ^ The number of releases to keep, the '--keep-releases' argument passed via -- the CLI takes precedence over this value. If neither CLI or configuration -- file value is specified, it defaults to 5 - , configWorkingDirectory :: !(Maybe FilePath) + , configWorkingDirectory :: !(Maybe (Path Rel Dir)) } deriving (Eq, Ord, Show) -- | Information about source and destination locations of a file\/directory From e06c8dc0632b2a92b89b95814b531adeafcba7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Estrella?= <2049686+sestrella@users.noreply.github.com> Date: Fri, 22 Jan 2021 10:08:05 -0500 Subject: [PATCH 03/20] Use configWorkingDir --- app/Main.hs | 4 ++-- src/System/Hapistrano.hs | 24 ++++++++++++++---------- src/System/Hapistrano/Config.hs | 4 ++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 9ca39eb..3d6a74e 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -139,7 +139,7 @@ main = do release <- if configVcAction then Hap.pushRelease (task releaseFormat) else Hap.pushReleaseWithoutVc (task releaseFormat) - rpath <- Hap.releasePath configDeployPath release + rpath <- Hap.releasePath configDeployPath release configWorkingDir forM_ (toMaybePath configSource) $ \src -> Hap.scpDir src rpath forM_ configCopyFiles $ \(C.CopyThing src dest) -> do @@ -158,7 +158,7 @@ main = do (Hap.linkToShared configTargetSystem rpath configDeployPath) forM_ configLinkedDirs (Hap.linkToShared configTargetSystem rpath configDeployPath) - forM_ configBuildScript (Hap.playScript configDeployPath release configWorkingDirectory) + forM_ configBuildScript (Hap.playScript configDeployPath release configWorkingDir) Hap.registerReleaseAsComplete configDeployPath release Hap.activateRelease configTargetSystem configDeployPath release Hap.dropOldReleases configDeployPath keepReleases diff --git a/src/System/Hapistrano.hs b/src/System/Hapistrano.hs index c234031..36f7dfa 100644 --- a/src/System/Hapistrano.hs +++ b/src/System/Hapistrano.hs @@ -96,7 +96,7 @@ activateRelease -> Release -- ^ Release identifier to activate -> Hapistrano () activateRelease ts deployPath release = do - rpath <- releasePath deployPath release + rpath <- releasePath deployPath release Nothing let tpath = tempSymlinkPath deployPath cpath = currentSymlinkPath deployPath exec (Ln ts rpath tpath) -- create a symlink for the new candidate @@ -129,7 +129,7 @@ dropOldReleases dropOldReleases deployPath n = do dreleases <- deployedReleases deployPath forM_ (genericDrop n dreleases) $ \release -> do - rpath <- releasePath deployPath release + rpath <- releasePath deployPath release Nothing exec (Rm rpath) creleases <- completedReleases deployPath forM_ (genericDrop n creleases) $ \release -> do @@ -145,7 +145,7 @@ playScript -> [GenericCommand] -- ^ Commands to execute -> Hapistrano () playScript deployDir release mworkingDir cmds = do - rpath <- releasePath deployDir release + rpath <- releasePath deployDir release mworkingDir forM_ cmds (execWithInheritStdout . Cd rpath) -- | Plays the given script on your machine locally. @@ -202,7 +202,7 @@ cloneToRelease -> Release -- ^ 'Release' to create -> Hapistrano () cloneToRelease deployPath release = do - rpath <- releasePath deployPath release + rpath <- releasePath deployPath release Nothing let cpath = cacheRepoPath deployPath exec (GitClone False (Right cpath) rpath) @@ -215,7 +215,7 @@ setReleaseRevision -> String -- ^ Revision to checkout -> Hapistrano () setReleaseRevision deployPath release revision = do - rpath <- releasePath deployPath release + rpath <- releasePath deployPath release Nothing exec (Cd rpath (GitCheckout revision)) -- | Return a list of all currently deployed releases sorted newest first. @@ -278,14 +278,18 @@ linkToShared configTargetSystem rpath configDeployPath thingToLink = do -- | Construct path to a particular 'Release'. releasePath - :: Path Abs Dir -- ^ Deploy path - -> Release -- ^ 'Release' identifier + :: Path Abs Dir -- ^ Deploy path + -> Release -- ^ 'Release' identifier + -> Maybe (Path Rel Dir) -- ^ Working directory -> Hapistrano (Path Abs Dir) -releasePath deployPath release = do +releasePath deployPath release mworkingDir = let rendered = renderRelease release - case parseRelDir rendered of + in case parseRelDir rendered of Nothing -> failWith 1 (Just $ "Could not append path: " ++ rendered) - Just rpath -> return (releasesPath deployPath rpath) + Just rpath -> + return $ case mworkingDir of + Nothing -> releasesPath deployPath rpath + Just workingDir -> releasesPath deployPath rpath workingDir -- | Return the full path to the git repo used for cache purposes on the -- target host filesystem. diff --git a/src/System/Hapistrano/Config.hs b/src/System/Hapistrano/Config.hs index 66aab59..87690f2 100644 --- a/src/System/Hapistrano/Config.hs +++ b/src/System/Hapistrano/Config.hs @@ -62,7 +62,7 @@ data Config = Config -- ^ The number of releases to keep, the '--keep-releases' argument passed via -- the CLI takes precedence over this value. If neither CLI or configuration -- file value is specified, it defaults to 5 - , configWorkingDirectory :: !(Maybe (Path Rel Dir)) + , configWorkingDir :: !(Maybe (Path Rel Dir)) } deriving (Eq, Ord, Show) -- | Information about source and destination locations of a file\/directory @@ -116,7 +116,7 @@ instance FromJSON Config where configTargetSystem <- o .:? "linux" .!= GNULinux configReleaseFormat <- o .:? "release_format" configKeepReleases <- o .:? "keep_releases" - configWorkingDirectory <- o .:? "working_directory" + configWorkingDir <- o .:? "working_directory" return Config {..} instance FromJSON CopyThing where From 483e95060c96081ae9e4a180b095c60cb5c459a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Estrella?= <2049686+sestrella@users.noreply.github.com> Date: Fri, 22 Jan 2021 10:21:49 -0500 Subject: [PATCH 04/20] Fix specs --- spec/System/HapistranoConfigSpec.hs | 1 + spec/System/HapistranoSpec.hs | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/spec/System/HapistranoConfigSpec.hs b/spec/System/HapistranoConfigSpec.hs index 3b07fc7..2e6e799 100644 --- a/spec/System/HapistranoConfigSpec.hs +++ b/spec/System/HapistranoConfigSpec.hs @@ -56,4 +56,5 @@ defaultConfiguration = , configTargetSystem = GNULinux , configReleaseFormat = Nothing , configKeepReleases = Nothing + , configWorkingDir = Nothing } diff --git a/spec/System/HapistranoSpec.hs b/spec/System/HapistranoSpec.hs index c18e412..21c4d5f 100644 --- a/spec/System/HapistranoSpec.hs +++ b/spec/System/HapistranoSpec.hs @@ -99,7 +99,7 @@ spec = do runHapWithShell Zsh $ do let task = mkTask deployPath repoPath release <- Hap.pushRelease task - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing -- let's check that the dir exists and contains the right files (liftIO . readFile . fromAbsFile) (rpath $(mkRelFile "foo.txt")) `shouldReturn` "Foo!\n" @@ -107,7 +107,7 @@ spec = do runHap $ do let task = mkTask deployPath repoPath release <- Hap.pushRelease task - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing -- let's check that the dir exists and contains the right files (liftIO . readFile . fromAbsFile) (rpath $(mkRelFile "foo.txt")) `shouldReturn` "Foo!\n" @@ -115,7 +115,7 @@ spec = do runHap $ do let task = mkTaskWithCustomRevision deployPath repoPath testBranchName release <- Hap.pushRelease task - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing -- let's check that the dir exists and contains the right files (liftIO . readFile . fromAbsFile) (rpath $(mkRelFile "bar.txt")) `shouldReturn` "Bar!\n" @@ -139,7 +139,7 @@ spec = do let task = mkTask deployPath repoPath release <- Hap.pushRelease task Hap.activateRelease currentSystem deployPath release - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing let rc :: Hap.Readlink Dir rc = Hap.Readlink currentSystem (Hap.currentSymlinkPath deployPath) @@ -172,7 +172,7 @@ spec = do let task = mkTask deployPath repoPath rs <- replicateM 5 (Hap.pushRelease task) Hap.rollback currentSystem deployPath 2 - rpath <- Hap.releasePath deployPath (rs !! 2) + rpath <- Hap.releasePath deployPath (rs !! 2) Nothing let rc :: Hap.Readlink Dir rc = Hap.Readlink currentSystem (Hap.currentSymlinkPath deployPath) @@ -185,7 +185,7 @@ spec = do rs <- replicateM 5 (Hap.pushRelease task) forM_ (take 3 rs) (Hap.registerReleaseAsComplete deployPath) Hap.rollback currentSystem deployPath 2 - rpath <- Hap.releasePath deployPath (rs !! 0) + rpath <- Hap.releasePath deployPath (rs !! 0) Nothing let rc :: Hap.Readlink Dir rc = Hap.Readlink currentSystem (Hap.currentSymlinkPath deployPath) @@ -202,10 +202,10 @@ spec = do Hap.dropOldReleases deployPath 5 -- two oldest releases should not survive: forM_ (take 2 rs) $ \r -> - (Hap.releasePath deployPath r >>= doesDirExist) `shouldReturn` False + (Hap.releasePath deployPath r Nothing >>= doesDirExist) `shouldReturn` False -- 5 most recent releases should stay alive: forM_ (drop 2 rs) $ \r -> - (Hap.releasePath deployPath r >>= doesDirExist) `shouldReturn` True + (Hap.releasePath deployPath r Nothing >>= doesDirExist) `shouldReturn` True -- two oldest completion tokens should not survive: forM_ (take 2 rs) $ \r -> (Hap.ctokenPath deployPath r >>= doesFileExist) `shouldReturn` False @@ -219,7 +219,7 @@ spec = do let task = mkTask deployPath repoPath sharedDir = Hap.sharedPath deployPath release <- Hap.pushRelease task - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing Hap.exec $ Hap.Rm sharedDir Hap.linkToShared currentSystem rpath deployPath "thing" `shouldReturn` () @@ -228,7 +228,7 @@ spec = do runHap (do let task = mkTask deployPath repoPath release <- Hap.pushRelease task - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing Hap.linkToShared currentSystem rpath deployPath "foo.txt") `shouldThrow` anyException context "when it attemps to link a file" $ do @@ -238,7 +238,7 @@ spec = do (do let task = mkTask deployPath repoPath sharedDir = Hap.sharedPath deployPath release <- Hap.pushRelease task - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing justExec sharedDir "mkdir foo/" justExec sharedDir "echo 'Bar!' > foo/bar.txt" Hap.linkToShared currentSystem rpath deployPath "foo/bar.txt") `shouldThrow` @@ -249,7 +249,7 @@ spec = do let task = mkTask deployPath repoPath sharedDir = Hap.sharedPath deployPath release <- Hap.pushRelease task - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing justExec sharedDir "echo 'Bar!' > bar.txt" Hap.linkToShared currentSystem rpath deployPath "bar.txt" (liftIO . readFile . fromAbsFile) @@ -262,7 +262,7 @@ spec = do (do let task = mkTask deployPath repoPath sharedDir = Hap.sharedPath deployPath release <- Hap.pushRelease task - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing justExec sharedDir "mkdir foo/" justExec sharedDir "echo 'Bar!' > foo/bar.txt" justExec sharedDir "echo 'Baz!' > foo/baz.txt" @@ -273,7 +273,7 @@ spec = do let task = mkTask deployPath repoPath sharedDir = Hap.sharedPath deployPath release <- Hap.pushRelease task - rpath <- Hap.releasePath deployPath release + rpath <- Hap.releasePath deployPath release Nothing justExec sharedDir "mkdir foo/" justExec sharedDir "echo 'Bar!' > foo/bar.txt" justExec sharedDir "echo 'Baz!' > foo/baz.txt" From 882166309b7427d9e1ed5f396110e7cbbcd6560b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Estrella?= <2049686+sestrella@users.noreply.github.com> Date: Tue, 9 Feb 2021 14:17:28 -0500 Subject: [PATCH 05/20] WIP test --- spec/System/HapistranoSpec.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/System/HapistranoSpec.hs b/spec/System/HapistranoSpec.hs index 21c4d5f..9cf2699 100644 --- a/spec/System/HapistranoSpec.hs +++ b/spec/System/HapistranoSpec.hs @@ -31,6 +31,16 @@ testBranchName = "another_branch" spec :: Spec spec = do + fdescribe "releasePath" $ do + context "when the configWorkingDir is Nothing" $ + it "..." $ do + runHap $ Hap.releasePath undefined undefined Nothing + pending + + context "when the configWorkingDir is Just" $ + it "..." $ + pending + describe "execWithInheritStdout" $ context "given a command that prints to stdout" $ it "redirects commands' output to stdout first" $ From 754918b7a8f05e8284b27de70597c44ba61b9f1b Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Thu, 4 Mar 2021 14:28:43 -0500 Subject: [PATCH 06/20] Testing releasePath --- CHANGELOG.md | 4 ++++ hapistrano.cabal | 2 +- spec/System/HapistranoSpec.hs | 37 +++++++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d6fefd..2c56c31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.2.0 +### Added +* Add support for working directory + ## 0.4.1.3 ### Changed * Allow formatting-7.0 diff --git a/hapistrano.cabal b/hapistrano.cabal index 5315d5c..e077faa 100644 --- a/hapistrano.cabal +++ b/hapistrano.cabal @@ -1,5 +1,5 @@ name: hapistrano -version: 0.4.1.3 +version: 0.4.2.0 synopsis: A deployment library for Haskell applications description: . diff --git a/spec/System/HapistranoSpec.hs b/spec/System/HapistranoSpec.hs index 9cf2699..4897c97 100644 --- a/spec/System/HapistranoSpec.hs +++ b/spec/System/HapistranoSpec.hs @@ -12,6 +12,7 @@ import Data.List (isPrefixOf) import Data.Maybe (mapMaybe) import Numeric.Natural import Path +import Path.Internal (Path(..)) import Path.IO import System.Directory (listDirectory) import qualified System.Hapistrano as Hap @@ -21,6 +22,7 @@ import System.Hapistrano.Types import System.IO import System.IO.Silently (capture_) import System.Info (os) +import qualified System.FilePath as SF import Test.Hspec hiding (shouldBe, shouldReturn) import qualified Test.Hspec as Hspec import Test.Hspec.QuickCheck @@ -29,18 +31,14 @@ import Test.QuickCheck testBranchName :: String testBranchName = "another_branch" +workingDir :: Path Rel Dir +workingDir = Path "working_dir" + +releaseDir :: FilePath +releaseDir = toFilePath (Path "releases") + spec :: Spec spec = do - fdescribe "releasePath" $ do - context "when the configWorkingDir is Nothing" $ - it "..." $ do - runHap $ Hap.releasePath undefined undefined Nothing - pending - - context "when the configWorkingDir is Just" $ - it "..." $ - pending - describe "execWithInheritStdout" $ context "given a command that prints to stdout" $ it "redirects commands' output to stdout first" $ @@ -104,6 +102,25 @@ spec = do it "returns the default value" $ fromMaybeKeepReleases Nothing Nothing `Hspec.shouldBe` 5 around withSandbox $ do + fdescribe "releasePath" $ do + context "when the configWorkingDir is Nothing" $ + it "should return the release path" $ \(deployPath, repoPath) -> do + (rpath, release) <- runHap $ do + release <- Hap.pushRelease $ mkTask deployPath repoPath + (,) <$> Hap.releasePath deployPath release Nothing + <*> pure release + + toFilePath rpath `shouldBe` toFilePath deployPath SF. releaseDir SF. (renderRelease release <> [SF.pathSeparator]) + + context "when the configWorkingDir is Just" $ + it "should return the release path with WorkingDir" $ \(deployPath, repoPath) -> do + (rpath, release) <- runHap $ do + release <- Hap.pushRelease $ mkTask deployPath repoPath + (,) <$> Hap.releasePath deployPath release (Just workingDir) + <*> pure release + + toFilePath rpath `shouldBe` toFilePath deployPath SF. releaseDir SF. renderRelease release SF. "working_dir" + describe "pushRelease" $ do it "sets up repo all right in Zsh" $ \(deployPath, repoPath) -> runHapWithShell Zsh $ do From fcac5f42bb12cffe9eb4db07d87c0b6766b9e7b1 Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Thu, 4 Mar 2021 15:00:57 -0500 Subject: [PATCH 07/20] Tests refactored --- spec/System/HapistranoSpec.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/System/HapistranoSpec.hs b/spec/System/HapistranoSpec.hs index 4897c97..12b68a5 100644 --- a/spec/System/HapistranoSpec.hs +++ b/spec/System/HapistranoSpec.hs @@ -22,7 +22,6 @@ import System.Hapistrano.Types import System.IO import System.IO.Silently (capture_) import System.Info (os) -import qualified System.FilePath as SF import Test.Hspec hiding (shouldBe, shouldReturn) import qualified Test.Hspec as Hspec import Test.Hspec.QuickCheck @@ -32,10 +31,10 @@ testBranchName :: String testBranchName = "another_branch" workingDir :: Path Rel Dir -workingDir = Path "working_dir" +workingDir = $(mkRelDir "working_dir") -releaseDir :: FilePath -releaseDir = toFilePath (Path "releases") +releaseDir :: Path Rel Dir +releaseDir = $(mkRelDir "releases") spec :: Spec spec = do @@ -110,7 +109,8 @@ spec = do (,) <$> Hap.releasePath deployPath release Nothing <*> pure release - toFilePath rpath `shouldBe` toFilePath deployPath SF. releaseDir SF. (renderRelease release <> [SF.pathSeparator]) + rel <- parseRelDir $ renderRelease release + rpath `shouldBe` deployPath releaseDir rel context "when the configWorkingDir is Just" $ it "should return the release path with WorkingDir" $ \(deployPath, repoPath) -> do @@ -119,7 +119,8 @@ spec = do (,) <$> Hap.releasePath deployPath release (Just workingDir) <*> pure release - toFilePath rpath `shouldBe` toFilePath deployPath SF. releaseDir SF. renderRelease release SF. "working_dir" + rel <- parseRelDir $ renderRelease release + rpath `shouldBe` deployPath releaseDir rel workingDir describe "pushRelease" $ do it "sets up repo all right in Zsh" $ \(deployPath, repoPath) -> From ca871c1a0769e45d3213d53de8d1ba37f506a535 Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Thu, 4 Mar 2021 15:22:20 -0500 Subject: [PATCH 08/20] example project --- example/.gitignore | 2 ++ example/ChangeLog.md | 3 ++ example/LICENSE | 30 +++++++++++++++++++ example/README.md | 1 + example/Setup.hs | 2 ++ example/app/Main.hs | 6 ++++ example/example.cabal | 62 ++++++++++++++++++++++++++++++++++++++ example/hap.yaml | 7 +++++ example/package.yaml | 48 ++++++++++++++++++++++++++++++ example/src/Lib.hs | 6 ++++ example/stack.yaml | 66 +++++++++++++++++++++++++++++++++++++++++ example/stack.yaml.lock | 12 ++++++++ example/test/Spec.hs | 2 ++ 13 files changed, 247 insertions(+) create mode 100644 example/.gitignore create mode 100644 example/ChangeLog.md create mode 100644 example/LICENSE create mode 100644 example/README.md create mode 100644 example/Setup.hs create mode 100644 example/app/Main.hs create mode 100644 example/example.cabal create mode 100644 example/hap.yaml create mode 100644 example/package.yaml create mode 100644 example/src/Lib.hs create mode 100644 example/stack.yaml create mode 100644 example/stack.yaml.lock create mode 100644 example/test/Spec.hs diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..c368d45 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,2 @@ +.stack-work/ +*~ \ No newline at end of file diff --git a/example/ChangeLog.md b/example/ChangeLog.md new file mode 100644 index 0000000..c477f69 --- /dev/null +++ b/example/ChangeLog.md @@ -0,0 +1,3 @@ +# Changelog for example + +## Unreleased changes diff --git a/example/LICENSE b/example/LICENSE new file mode 100644 index 0000000..7caa388 --- /dev/null +++ b/example/LICENSE @@ -0,0 +1,30 @@ +Copyright Author name here (c) 2021 + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + + * Neither the name of Author name here nor the names of other + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..02dc8ac --- /dev/null +++ b/example/README.md @@ -0,0 +1 @@ +# example diff --git a/example/Setup.hs b/example/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/example/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/example/app/Main.hs b/example/app/Main.hs new file mode 100644 index 0000000..de1c1ab --- /dev/null +++ b/example/app/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import Lib + +main :: IO () +main = someFunc diff --git a/example/example.cabal b/example/example.cabal new file mode 100644 index 0000000..87dd317 --- /dev/null +++ b/example/example.cabal @@ -0,0 +1,62 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.33.0. +-- +-- see: https://github.com/sol/hpack +-- +-- hash: 1f6aeb3e795c2bccaa4432822f9e5c194ffa58d28b566ac28ac0c28e11ac863c + +name: example +version: 0.1.0.0 +description: Please see the README on GitHub at +homepage: https://github.com/githubuser/example#readme +bug-reports: https://github.com/githubuser/example/issues +author: Author name here +maintainer: example@example.com +copyright: 2021 Author name here +license: BSD3 +license-file: LICENSE +build-type: Simple +extra-source-files: + README.md + ChangeLog.md + +source-repository head + type: git + location: https://github.com/githubuser/example + +library + exposed-modules: + Lib + other-modules: + Paths_example + hs-source-dirs: + src + build-depends: + base >=4.7 && <5 + default-language: Haskell2010 + +executable example-exe + main-is: Main.hs + other-modules: + Paths_example + hs-source-dirs: + app + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , example + default-language: Haskell2010 + +test-suite example-test + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Paths_example + hs-source-dirs: + test + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , example + default-language: Haskell2010 diff --git a/example/hap.yaml b/example/hap.yaml new file mode 100644 index 0000000..c2a1ed2 --- /dev/null +++ b/example/hap.yaml @@ -0,0 +1,7 @@ +deploy_path: "/tmp/hap-example" +repo: "https://github.com/stackbuilders/hapistrano.git" +revision: "origin/add_working_directory" +working_directory: example + +build_script: + - stack build diff --git a/example/package.yaml b/example/package.yaml new file mode 100644 index 0000000..26e726d --- /dev/null +++ b/example/package.yaml @@ -0,0 +1,48 @@ +name: example +version: 0.1.0.0 +github: "githubuser/example" +license: BSD3 +author: "Author name here" +maintainer: "example@example.com" +copyright: "2021 Author name here" + +extra-source-files: +- README.md +- ChangeLog.md + +# Metadata used when publishing your package +# synopsis: Short description of your package +# category: Web + +# To avoid duplicated efforts in documentation and dealing with the +# complications of embedding Haddock markup inside cabal files, it is +# common to point users to the README.md file. +description: Please see the README on GitHub at + +dependencies: +- base >= 4.7 && < 5 + +library: + source-dirs: src + +executables: + example-exe: + main: Main.hs + source-dirs: app + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - example + +tests: + example-test: + main: Spec.hs + source-dirs: test + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - example diff --git a/example/src/Lib.hs b/example/src/Lib.hs new file mode 100644 index 0000000..d36ff27 --- /dev/null +++ b/example/src/Lib.hs @@ -0,0 +1,6 @@ +module Lib + ( someFunc + ) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/example/stack.yaml b/example/stack.yaml new file mode 100644 index 0000000..c23a7da --- /dev/null +++ b/example/stack.yaml @@ -0,0 +1,66 @@ +# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# https://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-3.5 +# resolver: nightly-2015-09-21 +# resolver: ghc-7.10.2 +# +# The location of a snapshot can be provided as a file or url. Stack assumes +# a snapshot provided as a file might change, whereas a url resource does not. +# +# resolver: ./custom-snapshot.yaml +# resolver: https://example.com/snapshots/2018-01-01.yaml +resolver: lts-17.5 + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# subdirs: +# - auto-update +# - wai +packages: +- . +# Dependency packages to be pulled from upstream that are not in the resolver. +# These entries can reference officially published versions as well as +# forks / in-progress versions pinned to a git hash. For example: +# +# extra-deps: +# - acme-missiles-0.3 +# - git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# +# extra-deps: [] + +# Override default flag values for local packages and extra-deps +# flags: {} + +# Extra package databases containing global packages +# extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=2.3" +# +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor diff --git a/example/stack.yaml.lock b/example/stack.yaml.lock new file mode 100644 index 0000000..fa953b3 --- /dev/null +++ b/example/stack.yaml.lock @@ -0,0 +1,12 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + size: 565266 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/5.yaml + sha256: 78e8ebabf11406261abbc95b44f240acf71802630b368888f6d758de7fc3a2f7 + original: lts-17.5 diff --git a/example/test/Spec.hs b/example/test/Spec.hs new file mode 100644 index 0000000..cd4753f --- /dev/null +++ b/example/test/Spec.hs @@ -0,0 +1,2 @@ +main :: IO () +main = putStrLn "Test suite not yet implemented" From b48d3b644cab46ac0f93f070ec3c53705baaf21a Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Tue, 13 Apr 2021 18:05:03 -0500 Subject: [PATCH 09/20] Address comments and suggestions --- example/ChangeLog.md | 3 -- example/LICENSE | 30 ------------------- example/README.md | 17 ++++++++++- example/app/Main.hs | 2 +- example/example.cabal | 26 ++++++---------- example/hap.yaml | 2 ++ example/src/Lib.hs | 4 +-- example/stack.yaml | 66 ----------------------------------------- example/stack.yaml.lock | 12 -------- example/test/Spec.hs | 2 -- 10 files changed, 30 insertions(+), 134 deletions(-) delete mode 100644 example/ChangeLog.md delete mode 100644 example/LICENSE delete mode 100644 example/stack.yaml delete mode 100644 example/stack.yaml.lock delete mode 100644 example/test/Spec.hs diff --git a/example/ChangeLog.md b/example/ChangeLog.md deleted file mode 100644 index c477f69..0000000 --- a/example/ChangeLog.md +++ /dev/null @@ -1,3 +0,0 @@ -# Changelog for example - -## Unreleased changes diff --git a/example/LICENSE b/example/LICENSE deleted file mode 100644 index 7caa388..0000000 --- a/example/LICENSE +++ /dev/null @@ -1,30 +0,0 @@ -Copyright Author name here (c) 2021 - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - - * Neither the name of Author name here nor the names of other - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/example/README.md b/example/README.md index 02dc8ac..5c7ff95 100644 --- a/example/README.md +++ b/example/README.md @@ -1 +1,16 @@ -# example +# How to test working_dir feature in a remote server (Virtual Machine) + +We're going to test the working_dir hapistrano feature by deploying this project +to a local server (Virtual machine). To do this we need to: +We're assuming that you have this repo locally. + +1. Install virtualbox - link here +2. Install vagrant - link here +3. create a vagrant vm +4. copy our ssh keys to vagrant +5. ssh the vagrant vm +6. install stack - link here +7. go to /hapistrano/example and run `hap deploy` +8. That should be. +9. go to the terminal you have the vagrant vm and go to /tmp/hap-examle/current/example + and try running `stack build` nothing should happen since your project is already compiled. diff --git a/example/app/Main.hs b/example/app/Main.hs index de1c1ab..bdc5cad 100644 --- a/example/app/Main.hs +++ b/example/app/Main.hs @@ -3,4 +3,4 @@ module Main where import Lib main :: IO () -main = someFunc +main = helloWorld diff --git a/example/example.cabal b/example/example.cabal index 87dd317..f6dd370 100644 --- a/example/example.cabal +++ b/example/example.cabal @@ -1,25 +1,17 @@ -cabal-version: 1.12 - --- This file has been generated from package.yaml by hpack version 0.33.0. --- --- see: https://github.com/sol/hpack --- --- hash: 1f6aeb3e795c2bccaa4432822f9e5c194ffa58d28b566ac28ac0c28e11ac863c - +cabal-version: 1.12 name: example version: 0.1.0.0 -description: Please see the README on GitHub at -homepage: https://github.com/githubuser/example#readme -bug-reports: https://github.com/githubuser/example/issues -author: Author name here -maintainer: example@example.com -copyright: 2021 Author name here -license: BSD3 -license-file: LICENSE +description: + This is an example project that has been created in order to test + the deployment process using the working_dir feature of hapistrano. +author: Justin Leitgeb +maintainer: jpaucar@stackbuilders.com +copyright: 2015-Present Stack Builders Inc. +license: MIT +license-file: LICENSE (Hapistrano directory) build-type: Simple extra-source-files: README.md - ChangeLog.md source-repository head type: git diff --git a/example/hap.yaml b/example/hap.yaml index c2a1ed2..e52ec27 100644 --- a/example/hap.yaml +++ b/example/hap.yaml @@ -1,6 +1,8 @@ deploy_path: "/tmp/hap-example" repo: "https://github.com/stackbuilders/hapistrano.git" revision: "origin/add_working_directory" +host: vagrant@127.0.0.1 +port: 2222 working_directory: example build_script: diff --git a/example/src/Lib.hs b/example/src/Lib.hs index d36ff27..46c620f 100644 --- a/example/src/Lib.hs +++ b/example/src/Lib.hs @@ -2,5 +2,5 @@ module Lib ( someFunc ) where -someFunc :: IO () -someFunc = putStrLn "someFunc" +helloWorld :: IO () +helloWorld = putStrLn "Hello world!" diff --git a/example/stack.yaml b/example/stack.yaml deleted file mode 100644 index c23a7da..0000000 --- a/example/stack.yaml +++ /dev/null @@ -1,66 +0,0 @@ -# This file was automatically generated by 'stack init' -# -# Some commonly used options have been documented as comments in this file. -# For advanced use and comprehensive documentation of the format, please see: -# https://docs.haskellstack.org/en/stable/yaml_configuration/ - -# Resolver to choose a 'specific' stackage snapshot or a compiler version. -# A snapshot resolver dictates the compiler version and the set of packages -# to be used for project dependencies. For example: -# -# resolver: lts-3.5 -# resolver: nightly-2015-09-21 -# resolver: ghc-7.10.2 -# -# The location of a snapshot can be provided as a file or url. Stack assumes -# a snapshot provided as a file might change, whereas a url resource does not. -# -# resolver: ./custom-snapshot.yaml -# resolver: https://example.com/snapshots/2018-01-01.yaml -resolver: lts-17.5 - -# User packages to be built. -# Various formats can be used as shown in the example below. -# -# packages: -# - some-directory -# - https://example.com/foo/bar/baz-0.0.2.tar.gz -# subdirs: -# - auto-update -# - wai -packages: -- . -# Dependency packages to be pulled from upstream that are not in the resolver. -# These entries can reference officially published versions as well as -# forks / in-progress versions pinned to a git hash. For example: -# -# extra-deps: -# - acme-missiles-0.3 -# - git: https://github.com/commercialhaskell/stack.git -# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a -# -# extra-deps: [] - -# Override default flag values for local packages and extra-deps -# flags: {} - -# Extra package databases containing global packages -# extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true -# -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: ">=2.3" -# -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 -# -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] -# -# Allow a newer minor version of GHC than the snapshot specifies -# compiler-check: newer-minor diff --git a/example/stack.yaml.lock b/example/stack.yaml.lock deleted file mode 100644 index fa953b3..0000000 --- a/example/stack.yaml.lock +++ /dev/null @@ -1,12 +0,0 @@ -# This file was autogenerated by Stack. -# You should not edit this file by hand. -# For more information, please see the documentation at: -# https://docs.haskellstack.org/en/stable/lock_files - -packages: [] -snapshots: -- completed: - size: 565266 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/5.yaml - sha256: 78e8ebabf11406261abbc95b44f240acf71802630b368888f6d758de7fc3a2f7 - original: lts-17.5 diff --git a/example/test/Spec.hs b/example/test/Spec.hs deleted file mode 100644 index cd4753f..0000000 --- a/example/test/Spec.hs +++ /dev/null @@ -1,2 +0,0 @@ -main :: IO () -main = putStrLn "Test suite not yet implemented" From 94a56392c0f2d35669aacd97a6386c22dbc48e1d Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Tue, 13 Apr 2021 18:09:11 -0500 Subject: [PATCH 10/20] Hapistrano changes --- README.md | 4 ++-- spec/System/HapistranoSpec.hs | 2 +- stack.yaml | 6 +++--- stack.yaml.lock | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 28a1f7e..495a70f 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ * [Nix](#nix) * [License](#license) * [Contributing](#contributing) - - + + # Hapistrano Hapistrano is a deployment library for Haskell applications similar to diff --git a/spec/System/HapistranoSpec.hs b/spec/System/HapistranoSpec.hs index 12b68a5..abf784d 100644 --- a/spec/System/HapistranoSpec.hs +++ b/spec/System/HapistranoSpec.hs @@ -101,7 +101,7 @@ spec = do it "returns the default value" $ fromMaybeKeepReleases Nothing Nothing `Hspec.shouldBe` 5 around withSandbox $ do - fdescribe "releasePath" $ do + describe "releasePath" $ do context "when the configWorkingDir is Nothing" $ it "should return the release path" $ \(deployPath, repoPath) -> do (rpath, release) <- runHap $ do diff --git a/stack.yaml b/stack.yaml index c060a43..2f4dc6c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-17.7 +resolver: lts-17.9 packages: - - '.' - + - example + - . diff --git a/stack.yaml.lock b/stack.yaml.lock index d4d1cc5..348de92 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - size: 565715 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/7.yaml - sha256: 1b5e4124989399e60e7a7901f0cefd910beea546131fb07a13a7208c4cc8b7ee - original: lts-17.7 + size: 567037 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/9.yaml + sha256: d7d8d5106e53d1669964bd8bd2b0f88a5ad192d772f5376384b76738fd992311 + original: lts-17.9 From 79ed3e05564e8b2f4a2723e9519cc39c420748ac Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Fri, 16 Apr 2021 11:39:36 -0500 Subject: [PATCH 11/20] Improve vagrant procces --- example/.gitignore | 3 ++- example/README.md | 38 +++++++++++++++++++++------------- example/Vagrantfile | 11 ++++++++++ example/example.cabal | 19 +++-------------- example/package.yaml | 48 ------------------------------------------- example/src/Lib.hs | 2 +- 6 files changed, 41 insertions(+), 80 deletions(-) create mode 100644 example/Vagrantfile delete mode 100644 example/package.yaml diff --git a/example/.gitignore b/example/.gitignore index c368d45..920cda2 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,2 +1,3 @@ .stack-work/ -*~ \ No newline at end of file +*~ +.vagrant diff --git a/example/README.md b/example/README.md index 5c7ff95..12604f0 100644 --- a/example/README.md +++ b/example/README.md @@ -1,16 +1,26 @@ -# How to test working_dir feature in a remote server (Virtual Machine) +# Example project to test hapistrano's working_dir feature -We're going to test the working_dir hapistrano feature by deploying this project -to a local server (Virtual machine). To do this we need to: -We're assuming that you have this repo locally. +We're going to test the hapistrano's `working_dir` feature by deploying this project to a local server (Virtual machine). +To do this we need to: -1. Install virtualbox - link here -2. Install vagrant - link here -3. create a vagrant vm -4. copy our ssh keys to vagrant -5. ssh the vagrant vm -6. install stack - link here -7. go to /hapistrano/example and run `hap deploy` -8. That should be. -9. go to the terminal you have the vagrant vm and go to /tmp/hap-examle/current/example - and try running `stack build` nothing should happen since your project is already compiled. +1. Install [VirtualBox](virtualbox) +2. Install [Vagrant](vagrant) +4. You must have a ssh key with the name `id_rsa`. + If you're not sure this [article](ssh) can be helfpul. +5. Go to the `/hapistano/example` directory. +6. Execute in your terminal the next line. + ```bash + vagrant up + ``` + If everything went good, this should trigger the deployment procces to the virtual machine. +9. To check that the project was built you can ssh the vagrant vm, and do the folowing: + ```bash + vagrant ssh + cd /tmp/hap-examle/current/example + stack build + ``` + Nothing should happen since your project is already compiled. + +[virtualbox]: https://www.virtualbox.org/wiki/Downloads +[vagrant]: https://www.vagrantup.com/docs/installation +[ssh]: https://docs.github.com/en/github/authenticating-to-github/checking-for-existing-ssh-keys diff --git a/example/Vagrantfile b/example/Vagrantfile new file mode 100644 index 0000000..1f7eb19 --- /dev/null +++ b/example/Vagrantfile @@ -0,0 +1,11 @@ +Vagrant.configure("2") do |config| + config.vm.box = "debian/buster64" + # ~/.ssh/id_rsa.pub is a file in the host machine + config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/me.pub" + config.vm.provision "shell", inline: <<-SCRIPT + apt update + apt install -y curl + curl -sSL https://get.haskellstack.org/ | sh + cat /home/vagrant/.ssh/me.pub >> /home/vagrant/.ssh/authorized_keys + SCRIPT +end diff --git a/example/example.cabal b/example/example.cabal index f6dd370..0f81322 100644 --- a/example/example.cabal +++ b/example/example.cabal @@ -8,14 +8,14 @@ author: Justin Leitgeb maintainer: jpaucar@stackbuilders.com copyright: 2015-Present Stack Builders Inc. license: MIT -license-file: LICENSE (Hapistrano directory) +license-file: ../LICENSE build-type: Simple extra-source-files: - README.md + README.md source-repository head type: git - location: https://github.com/githubuser/example + location: https://github.com/stackbuilders/hapistrano/ library exposed-modules: @@ -39,16 +39,3 @@ executable example-exe base >=4.7 && <5 , example default-language: Haskell2010 - -test-suite example-test - type: exitcode-stdio-1.0 - main-is: Spec.hs - other-modules: - Paths_example - hs-source-dirs: - test - ghc-options: -threaded -rtsopts -with-rtsopts=-N - build-depends: - base >=4.7 && <5 - , example - default-language: Haskell2010 diff --git a/example/package.yaml b/example/package.yaml deleted file mode 100644 index 26e726d..0000000 --- a/example/package.yaml +++ /dev/null @@ -1,48 +0,0 @@ -name: example -version: 0.1.0.0 -github: "githubuser/example" -license: BSD3 -author: "Author name here" -maintainer: "example@example.com" -copyright: "2021 Author name here" - -extra-source-files: -- README.md -- ChangeLog.md - -# Metadata used when publishing your package -# synopsis: Short description of your package -# category: Web - -# To avoid duplicated efforts in documentation and dealing with the -# complications of embedding Haddock markup inside cabal files, it is -# common to point users to the README.md file. -description: Please see the README on GitHub at - -dependencies: -- base >= 4.7 && < 5 - -library: - source-dirs: src - -executables: - example-exe: - main: Main.hs - source-dirs: app - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - dependencies: - - example - -tests: - example-test: - main: Spec.hs - source-dirs: test - ghc-options: - - -threaded - - -rtsopts - - -with-rtsopts=-N - dependencies: - - example diff --git a/example/src/Lib.hs b/example/src/Lib.hs index 46c620f..1e58ef1 100644 --- a/example/src/Lib.hs +++ b/example/src/Lib.hs @@ -1,5 +1,5 @@ module Lib - ( someFunc + ( helloWorld ) where helloWorld :: IO () From 2baa121a48d06e6caffb217653cb48184ea68511 Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Thu, 22 Apr 2021 15:40:32 -0500 Subject: [PATCH 12/20] Upgrade cabal version from 3.0 to 3.4 (travis) --- .travis.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ed222b..596e633 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,20 +12,20 @@ cache: matrix: include: - - env: CABALVER=3.0 GHCVER=7.10.3 - addons: {apt: {packages: [cabal-install-3.0,ghc-7.10.3,zsh],sources: [hvr-ghc]}} - - env: CABALVER=3.0 GHCVER=8.0.2 - addons: {apt: {packages: [cabal-install-3.0,ghc-8.0.2,zsh], sources: [hvr-ghc]}} - - env: CABALVER=3.0 GHCVER=8.2.2 - addons: {apt: {packages: [cabal-install-3.0,ghc-8.2.2,zsh], sources: [hvr-ghc]}} - - env: CABALVER=3.0 GHCVER=8.4.4 - addons: {apt: {packages: [cabal-install-3.0,ghc-8.4.4,zsh], sources: [hvr-ghc]}} - - env: CABALVER=3.0 GHCVER=8.6.5 - addons: {apt: {packages: [cabal-install-3.0,ghc-8.6.5,zsh], sources: [hvr-ghc]}} - - env: CABALVER=3.0 GHCVER=8.8.3 - addons: {apt: {packages: [cabal-install-3.0,ghc-8.8.3,zsh], sources: [hvr-ghc]}} - - env: CABALVER=3.0 GHCVER=8.10.1 - addons: {apt: {packages: [cabal-install-3.0,ghc-8.10.1,zsh], sources: [hvr-ghc]}} + - env: CABALVER=3.4 GHCVER=7.10.3 + addons: {apt: {packages: [cabal-install-3.4,ghc-7.10.3,zsh],sources: [hvr-ghc]}} + - env: CABALVER=3.4 GHCVER=8.0.2 + addons: {apt: {packages: [cabal-install-3.4,ghc-8.0.2,zsh], sources: [hvr-ghc]}} + - env: CABALVER=3.4 GHCVER=8.2.2 + addons: {apt: {packages: [cabal-install-3.4,ghc-8.2.2,zsh], sources: [hvr-ghc]}} + - env: CABALVER=3.4 GHCVER=8.4.4 + addons: {apt: {packages: [cabal-install-3.4,ghc-8.4.4,zsh], sources: [hvr-ghc]}} + - env: CABALVER=3.4 GHCVER=8.6.5 + addons: {apt: {packages: [cabal-install-3.4,ghc-8.6.5,zsh], sources: [hvr-ghc]}} + - env: CABALVER=3.4 GHCVER=8.8.3 + addons: {apt: {packages: [cabal-install-3.4,ghc-8.8.3,zsh], sources: [hvr-ghc]}} + - env: CABALVER=3.4 GHCVER=8.10.1 + addons: {apt: {packages: [cabal-install-3.4,ghc-8.10.1,zsh], sources: [hvr-ghc]}} - os: osx osx_image: xcode12 From 9a01691789c18aa935aecf5b60de78eda272b61b Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Thu, 22 Apr 2021 15:52:24 -0500 Subject: [PATCH 13/20] Add comment about Docker Hub rate limits --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 596e633..c8dffc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,7 +45,10 @@ script: - cabal sdist - cabal haddock | grep "100%" | wc -l | grep -G "[45]" # Fixes issue with different haddock coverage with different ghc versions https://github.com/haskell/haddock/issues/123 # There is a single Docker image, there are no variants for different versions of GHC - - if [[ "$GHCVER" == "8.0.2" ]]; then docker build . -t hapistrano; docker run --rm hapistrano --version; fi + # Due to some rate limits we are turning this off since we need to modify the + # build script in order to run docker login first. See + # https://www.docker.com/increase-rate-limits + # - if [[ "$GHCVER" == "8.0.2" ]]; then docker build . -t hapistrano; docker run --rm hapistrano --version; fi notifications: email: false From 578327da396006a11b6f88b5b9b447ca3efdad6e Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Thu, 22 Apr 2021 15:54:54 -0500 Subject: [PATCH 14/20] Limit number of cores to 1 --- example/hap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/hap.yaml b/example/hap.yaml index e52ec27..c7b42f6 100644 --- a/example/hap.yaml +++ b/example/hap.yaml @@ -6,4 +6,4 @@ port: 2222 working_directory: example build_script: - - stack build + - stack build -j1 From 830fcbd034ce4beab0e63fcba97cc546ebbc42d2 Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Tue, 11 May 2021 17:31:11 -0500 Subject: [PATCH 15/20] requested chanages and vagrant --- example/README.md | 10 ++++++---- example/Vagrantfile | 5 +++++ example/stack.yaml | 3 +++ example/stack.yaml.lock | 12 ++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 example/stack.yaml create mode 100644 example/stack.yaml.lock diff --git a/example/README.md b/example/README.md index 12604f0..b951af5 100644 --- a/example/README.md +++ b/example/README.md @@ -3,14 +3,16 @@ We're going to test the hapistrano's `working_dir` feature by deploying this project to a local server (Virtual machine). To do this we need to: -1. Install [VirtualBox](virtualbox) -2. Install [Vagrant](vagrant) +1. Install [VirtualBox][virtualbox] +2. Install [Vagrant][vagrant] 4. You must have a ssh key with the name `id_rsa`. - If you're not sure this [article](ssh) can be helfpul. + If you're not sure this [article][ssh] can be helfpul. 5. Go to the `/hapistano/example` directory. 6. Execute in your terminal the next line. ```bash - vagrant up + #This could take a couple of minutes + $ vagrant up + $ hap deploy ``` If everything went good, this should trigger the deployment procces to the virtual machine. 9. To check that the project was built you can ssh the vagrant vm, and do the folowing: diff --git a/example/Vagrantfile b/example/Vagrantfile index 1f7eb19..612d4cf 100644 --- a/example/Vagrantfile +++ b/example/Vagrantfile @@ -1,5 +1,10 @@ Vagrant.configure("2") do |config| config.vm.box = "debian/buster64" + config.vm.provider "virtualbox" do |v| + v.memory = 2048 + v.cpus = 2 + end + # ~/.ssh/id_rsa.pub is a file in the host machine config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/me.pub" config.vm.provision "shell", inline: <<-SCRIPT diff --git a/example/stack.yaml b/example/stack.yaml new file mode 100644 index 0000000..151d745 --- /dev/null +++ b/example/stack.yaml @@ -0,0 +1,3 @@ +resolver: lts-17.10 +packages: + - . diff --git a/example/stack.yaml.lock b/example/stack.yaml.lock new file mode 100644 index 0000000..8d05737 --- /dev/null +++ b/example/stack.yaml.lock @@ -0,0 +1,12 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + size: 567241 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/10.yaml + sha256: 321b3b9f0c7f76994b39e0dabafdc76478274b4ff74cc5e43d410897a335ad3b + original: lts-17.10 From 3d00503dc8059f18ee76097bebe7aff6f9fbfd63 Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Tue, 11 May 2021 17:31:56 -0500 Subject: [PATCH 16/20] Requested changes --- src/System/Hapistrano.hs | 8 ++++---- stack.yaml | 3 +-- stack.yaml.lock | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/System/Hapistrano.hs b/src/System/Hapistrano.hs index 36f7dfa..601c7bf 100644 --- a/src/System/Hapistrano.hs +++ b/src/System/Hapistrano.hs @@ -144,8 +144,8 @@ playScript -> Maybe (Path Rel Dir) -- ^ Working directory -> [GenericCommand] -- ^ Commands to execute -> Hapistrano () -playScript deployDir release mworkingDir cmds = do - rpath <- releasePath deployDir release mworkingDir +playScript deployDir release mWorkingDir cmds = do + rpath <- releasePath deployDir release mWorkingDir forM_ cmds (execWithInheritStdout . Cd rpath) -- | Plays the given script on your machine locally. @@ -282,12 +282,12 @@ releasePath -> Release -- ^ 'Release' identifier -> Maybe (Path Rel Dir) -- ^ Working directory -> Hapistrano (Path Abs Dir) -releasePath deployPath release mworkingDir = +releasePath deployPath release mWorkingDir = let rendered = renderRelease release in case parseRelDir rendered of Nothing -> failWith 1 (Just $ "Could not append path: " ++ rendered) Just rpath -> - return $ case mworkingDir of + return $ case mWorkingDir of Nothing -> releasesPath deployPath rpath Just workingDir -> releasesPath deployPath rpath workingDir diff --git a/stack.yaml b/stack.yaml index 2f4dc6c..151d745 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,3 @@ -resolver: lts-17.9 +resolver: lts-17.10 packages: - - example - . diff --git a/stack.yaml.lock b/stack.yaml.lock index 348de92..8d05737 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - size: 567037 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/9.yaml - sha256: d7d8d5106e53d1669964bd8bd2b0f88a5ad192d772f5376384b76738fd992311 - original: lts-17.9 + size: 567241 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/10.yaml + sha256: 321b3b9f0c7f76994b39e0dabafdc76478274b4ff74cc5e43d410897a335ad3b + original: lts-17.10 From d2a0aed9cc6d3b6f8d8947cc7b0f87856e129d3f Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Wed, 12 May 2021 12:04:35 -0500 Subject: [PATCH 17/20] Reduce vagran ram --- example/Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/Vagrantfile b/example/Vagrantfile index 612d4cf..6474153 100644 --- a/example/Vagrantfile +++ b/example/Vagrantfile @@ -1,7 +1,7 @@ Vagrant.configure("2") do |config| config.vm.box = "debian/buster64" config.vm.provider "virtualbox" do |v| - v.memory = 2048 + v.memory = 1024 v.cpus = 2 end From 31fa4d117065f7c08e0adf605ae88407f693515f Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Wed, 12 May 2021 17:51:27 -0500 Subject: [PATCH 18/20] README enhacements --- example/README.md | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/example/README.md b/example/README.md index b951af5..e84cba0 100644 --- a/example/README.md +++ b/example/README.md @@ -5,17 +5,20 @@ To do this we need to: 1. Install [VirtualBox][virtualbox] 2. Install [Vagrant][vagrant] -4. You must have a ssh key with the name `id_rsa`. - If you're not sure this [article][ssh] can be helfpul. +3. Make sure you have hapistrano installed. You can install it via [stack] by running + ```bash + stack install hapistrano + ``` +4. You must have a ssh key with the name `id_rsa`.If you're not sure this [article][ssh] can be helfpul. 5. Go to the `/hapistano/example` directory. -6. Execute in your terminal the next line. +6. Execute in your terminal the next line. `*` ```bash #This could take a couple of minutes $ vagrant up $ hap deploy ``` If everything went good, this should trigger the deployment procces to the virtual machine. -9. To check that the project was built you can ssh the vagrant vm, and do the folowing: +7. To check that the project was built you can ssh the vagrant vm, and do the folowing: ```bash vagrant ssh cd /tmp/hap-examle/current/example @@ -23,6 +26,25 @@ To do this we need to: ``` Nothing should happen since your project is already compiled. +`*` A know issue occurs if you have other vagrant vms. When trying to run `hap deploy` you could get the following console result. To avoid this issue remove the line that contains the previous RSA host key and try running `hap deploy` again. + +```bash +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! +Someone could be eavesdropping on you right now (man-in-the-middle attack)! +It is also possible that the RSA host key has just been changed. +The fingerprint for the RSA key sent by the remote host is +. +Please contact your system administrator. +Add correct host key in /path/to/.ssh/known_hosts to get rid of this message. +Offending key in /path/to/.ssh/known_hosts: +RSA host key for [ip-or-host]: has changed and you have requested strict checking. +Host key verification failed. +``` + [virtualbox]: https://www.virtualbox.org/wiki/Downloads [vagrant]: https://www.vagrantup.com/docs/installation [ssh]: https://docs.github.com/en/github/authenticating-to-github/checking-for-existing-ssh-keys +[stack]: https://docs.haskellstack.org/en/stable/README/ From 00b7d2e9f1dc842960d245073ac44aabe1dce5cb Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Thu, 10 Jun 2021 17:03:26 -0500 Subject: [PATCH 19/20] Address changes --- example/README.md | 6 +++--- example/hap.yaml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example/README.md b/example/README.md index e84cba0..4480215 100644 --- a/example/README.md +++ b/example/README.md @@ -17,8 +17,8 @@ To do this we need to: $ vagrant up $ hap deploy ``` - If everything went good, this should trigger the deployment procces to the virtual machine. -7. To check that the project was built you can ssh the vagrant vm, and do the folowing: + If everything went fine, this should trigger the deployment procces to the virtual machine. +7. To check if the project was built you can ssh the vagrant vm, and do the folowing: ```bash vagrant ssh cd /tmp/hap-examle/current/example @@ -26,7 +26,7 @@ To do this we need to: ``` Nothing should happen since your project is already compiled. -`*` A know issue occurs if you have other vagrant vms. When trying to run `hap deploy` you could get the following console result. To avoid this issue remove the line that contains the previous RSA host key and try running `hap deploy` again. +`*` A known issue occurs if you have other vagrant vms. When trying to run `hap deploy` you could get the following console result. To avoid this issue remove the line that contains the previous RSA host key and try running `hap deploy` again. ```bash @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ diff --git a/example/hap.yaml b/example/hap.yaml index c7b42f6..c358ce3 100644 --- a/example/hap.yaml +++ b/example/hap.yaml @@ -1,6 +1,6 @@ deploy_path: "/tmp/hap-example" repo: "https://github.com/stackbuilders/hapistrano.git" -revision: "origin/add_working_directory" +revision: "origin" host: vagrant@127.0.0.1 port: 2222 working_directory: example From 47d5a47a8b80bf76a2e5be34099f77f3e5c2c4f5 Mon Sep 17 00:00:00 2001 From: Felix Mino Date: Fri, 11 Jun 2021 09:47:44 -0500 Subject: [PATCH 20/20] change revision in hap.yaml --- example/hap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/hap.yaml b/example/hap.yaml index c358ce3..6808b1e 100644 --- a/example/hap.yaml +++ b/example/hap.yaml @@ -1,6 +1,6 @@ deploy_path: "/tmp/hap-example" repo: "https://github.com/stackbuilders/hapistrano.git" -revision: "origin" +revision: "origin/master" host: vagrant@127.0.0.1 port: 2222 working_directory: example