Created
August 10, 2013 14:37
-
-
Save yuyarin/6200663 to your computer and use it in GitHub Desktop.
gitでcommit/pushされたファイルの内容をリモートリポジトリ側でvalidationしてOKだったらdeployする ref: http://qiita.com/yuyarin/items/3e335bc461839da3ea6a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FILE=hoge.conf | |
LOCAL_DIR=/home/hoge/work/hoge | |
REMOTE_DIR=/etc/hoged | |
REMOTE_USER=hoge | |
REMOTE_HOSTS="hoge1 hoge2 hoge3 hoge4" | |
for REMOTE_HOST in $REMOTE_HOSTS | |
do | |
CMD="scp ${LOCAL_DIR}/${FILE} ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DIR}/${FILE}" | |
echo $CMD | |
eval $CMD | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/home/yuyarin/hoge$ git commit -am 'Add string hoge' | |
[master 8519468] Add string hoge | |
1 file changed, 1 insertion(+) | |
/home/yuyarin/hoge$ git push origin master | |
Counting objects: 5, done. | |
Writing objects: 100% (3/3), 232 bytes | 0 bytes/s, done. | |
Total 3 (delta 0), reused 0 (delta 0) | |
remote: validation error | |
remote: error: hook declined to update refs/heads/master | |
To hoge@server1:/repos/hoge.git | |
! [remote rejected] master -> master (hook declined) | |
error: failed to push some refs to 'hoge@server1:/repos/hoge.git' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/home/yuyarin/hoge$ vim hoge.conf | |
/home/yuyarin/hoge$ git commit -am 'Remove strings hoge' | |
[master 3af7194] Remove strings hoge | |
1 file changed, 1 insertion(+), 2 deletions(-) | |
/home/yuyarin/hoge$ git push origin master | |
Counting objects: 8, done. | |
Delta compression using up to 4 threads. | |
Compressing objects: 100% (2/2), done. | |
Writing objects: 100% (6/6), 428 bytes | 0 bytes/s, done. | |
Total 6 (delta 0), reused 0 (delta 0) | |
remote: validation OK | |
remote: scp /home/hoge/work/hoge.conf hoge@hoge1:/etc/hoged/hoge.conf | |
remote: scp /home/hoge/work/hoge.conf hoge@hoge2:/etc/hoged/hoge.conf | |
remote: scp /home/hoge/work/hoge.conf hoge@hoge3:/etc/hoged/hoge.conf | |
remote: scp /home/hoge/work/hoge.conf hoge@hoge4:/etc/hoged/hoge.conf | |
To hoge@server1:/repos/hoge.git | |
e5aa890..3af7194 master -> master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cd /home/hoge/work/hoge | |
git --git-dir=.git pull /repos/hoge.git master | |
/usr/local/bin/deploy-hoge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
git show $3:hoge.conf | /usr/local/bin/validate_hoge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!ruby | |
fd = ARGV[0] and File.exists?(ARGV[0]) ? File::open(ARGV[0], 'r') : STDIN | |
while line = fd.gets | |
if /hoge/ =~ line | |
puts "validation ERROR" | |
exit 1 | |
end | |
end | |
puts "validation OK" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment