开发者

How to push code to multiple servers by Mercurial?

开发者 https://www.devze.com 2023-01-08 18:18 出处:网络
H开发者_如何转开发ow can we push code to multiple servers? We have many servers which needs to have the same copy of the code. It is difficult to push to individual server. I know mercurial has hooks

H开发者_如何转开发ow can we push code to multiple servers? We have many servers which needs to have the same copy of the code. It is difficult to push to individual server. I know mercurial has hooks but none of them gives a proper solution.


In your central server you create a changegroup hook.

So your central server would have the following hgrc:

[paths]
server2=http://server2
server3=http://server3
[hooks]
changegroup.server2 = hg push -f server2
changegroup.server3 = hg push -f server3

You can have multiple hooks for the same event, so that shouldn't be an issue.
The advantage of the changegroup hook over the changeset hook is that it is run far less often.


In your .hg/hgrc file you should have a [paths] directive, which contains your default location. What about adding something like:

[paths]
default = http://server1
server2 = http://server2

And then do a:

hg push default
hg push server2


i assume that one of the servers is a master repo, the rest are deployments. in such a situation, i would interact with just the master and leave the deployments up to cron:

cat >$HOME/bin/dist <<'EOM'
#!/bin/sh
cd ${1:?}
tip=$(hg tip --template '{node}')
for r in $remotes; do
  hg push -r $tip $r
done
EOM

chmod +x $HOME/bin/dist
(crontab -l; echo '*/5 * * * * $HOME/bin/dist /var/repos/master') | crontab -
0

精彩评论

暂无评论...
验证码 换一张
取 消