summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debian/changelog3
-rw-r--r--doc/forum/how_to_boostrap_the_initial_git_repo/comment_2_84b8e438ef86d2caf4046c6e7950698b._comment23
-rw-r--r--src/Propellor/Property/PropellorRepo.hs30
-rw-r--r--src/Propellor/Spin.hs11
4 files changed, 53 insertions, 14 deletions
diff --git a/debian/changelog b/debian/changelog
index 8265f777..42eebb96 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,9 @@ propellor (4.9.0) UNRELEASED; urgency=medium
* Code that used fromDnsInfo . fromInfo changes to use getDnsInfo.
* addDNS takes an additional Bool parameter to control whether
the DNS info should propagate out of containers. (API change)
+ * Made the PropellorRepo.hasOriginUrl property override the repository
+ url that --spin passes to a host.
+ * PropellorRepo.hasOriginUrl type changed to include HasInfo. (API change)
-- Joey Hess <id@joeyh.name> Wed, 04 Oct 2017 12:46:23 -0400
diff --git a/doc/forum/how_to_boostrap_the_initial_git_repo/comment_2_84b8e438ef86d2caf4046c6e7950698b._comment b/doc/forum/how_to_boostrap_the_initial_git_repo/comment_2_84b8e438ef86d2caf4046c6e7950698b._comment
new file mode 100644
index 00000000..91fdae32
--- /dev/null
+++ b/doc/forum/how_to_boostrap_the_initial_git_repo/comment_2_84b8e438ef86d2caf4046c6e7950698b._comment
@@ -0,0 +1,23 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 2"""
+ date="2017-10-04T17:30:30Z"
+ content="""
+I don't know what deploy branch trick you're referring to using.
+
+There is the deploy remote, which I think should do what you want:
+
+> Additionally, the url of a remote named "deploy", if it exists
+> in your ~/.propellor/ repository, is used as the origin url for
+> the other repositories.
+
+When you have a deploy remote configured in your local repository,
+the first time you spin a new host, it will clone its /usr/local/propellor
+from the url of the deploy remote. On subsequent spins, it sends the
+url over, and the host's repository's url is updated too.
+
+The PropellorRepo.hasOriginUrl property doesn't take effect until
+propellor runs with that configuration, which could be a bit of a chicken and
+egg situation. Except hmm, spin could look for that property and use
+repo url instead of the deploy remote's url. Yeah, I've done that now!
+"""]]
diff --git a/src/Propellor/Property/PropellorRepo.hs b/src/Propellor/Property/PropellorRepo.hs
index e60e7848..504ff395 100644
--- a/src/Propellor/Property/PropellorRepo.hs
+++ b/src/Propellor/Property/PropellorRepo.hs
@@ -2,18 +2,26 @@ module Propellor.Property.PropellorRepo where
import Propellor.Base
import Propellor.Git.Config
+import Propellor.Types.Info
-- | Sets the url to use as the origin of propellor's git repository.
--
--- When propellor --spin is used to update a host, the url is taken from
--- the repository that --spin is run in, and passed to the host. So, you
--- don't need to specifiy this property then.
+-- By default, the url is taken from the deploy or origin remote of
+-- the repository that propellor --spin is run in. Setting this property
+-- overrides that default behavior with a different url.
--
--- This property is useful when hosts are being updated without using
--- --spin, eg when using the `Propellor.Property.Cron.runPropellor` cron job.
-hasOriginUrl :: String -> Property UnixLike
-hasOriginUrl u = property ("propellor repo url " ++ u) $ do
- curru <- liftIO getRepoUrl
- if curru == Just u
- then return NoChange
- else makeChange $ setRepoUrl u
+-- When hosts are being updated without using -- --spin, eg when using
+-- the `Propellor.Property.Cron.runPropellor` cron job, this property can
+-- be set to redirect them to a new git repository url.
+hasOriginUrl :: String -> Property (HasInfo + UnixLike)
+hasOriginUrl u = setInfoProperty p (toInfo (InfoVal (OriginUrl u)))
+ where
+ p :: Property UnixLike
+ p = property ("propellor repo url " ++ u) $ do
+ curru <- liftIO getRepoUrl
+ if curru == Just u
+ then return NoChange
+ else makeChange $ setRepoUrl u
+
+newtype OriginUrl = OriginUrl String
+ deriving (Show)
diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs
index 88d2b473..4a945e82 100644
--- a/src/Propellor/Spin.hs
+++ b/src/Propellor/Spin.hs
@@ -29,6 +29,7 @@ import Propellor.Gpg
import Propellor.Bootstrap
import Propellor.Types.CmdLine
import Propellor.Types.Info
+import Propellor.Property.PropellorRepo (OriginUrl(..))
import qualified Propellor.Shim as Shim
import Utility.FileMode
import Utility.SafeCommand
@@ -220,7 +221,7 @@ updateServer target relay hst connect haveprecompiled privdata = do
v <- maybe Nothing readish <$> getMarked fromh statusMarker
case v of
(Just NeedRepoUrl) -> do
- sendRepoUrl toh
+ sendRepoUrl hst toh
loop
(Just NeedPrivData) -> do
sendPrivData hn toh privdata
@@ -242,8 +243,12 @@ updateServer target relay hst connect haveprecompiled privdata = do
done
Nothing -> done
-sendRepoUrl :: Handle -> IO ()
-sendRepoUrl toh = sendMarked toh repoUrlMarker =<< (fromMaybe "" <$> getRepoUrl)
+sendRepoUrl :: Host -> Handle -> IO ()
+sendRepoUrl hst toh = sendMarked toh repoUrlMarker =<< geturl
+ where
+ geturl = case fromInfoVal (fromInfo (hostInfo hst)) of
+ Nothing -> fromMaybe "" <$> getRepoUrl
+ Just (OriginUrl u) -> return u
sendPrivData :: HostName -> Handle -> PrivMap -> IO ()
sendPrivData hn toh privdata = void $ actionMessage msg $ do