設定Git Hook

透過Git Hook偵測push事件,達到自動化部屬Gitbook

執行nginx_git_gitbook Container

docker run -d -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup --name nginx_git_gitbook -it -p 10080:80 -p 10081:81 -p 14000:4000 nginx_git_gitbook /usr/sbin/init
docker exec -it nginx_git_gitbook bash

刪掉之前測試用的Gitbook

怕有權限問題,之前的gitbook是用root權限建制

cd /home/gitbook/
rm -rf shark_book

前往Git Repository設定hook事件

post-receive在push事件會被啟動,內容在下方

cd /usr/share/nginx/git/shark_book.git/hooks
vi post-receive
chmod +x post-receive
chown -R git.git post-receive

post-receive

rm -rf /home/gitbook/shark_book
mkdir /home/gitbook/shark_book
git clone /usr/share/nginx/git/gitbook_want2.git /home/gitbook/shark_book
nohup gitbook serve /home/gitbook/shark_book >/dev/null 2>&1 &

測試

隨便改改電腦中的shark_book README.md,然後commit + push,建議第一次push是透過bash指令來打,有錯誤就會顯示出來,一般錯誤都是權限錯誤,把之前root身分建制的gitbook砍到就好。push成功的話,就可以在http://localhost:14000 看到自己剛修改的內容。

results matching ""

    No results matching ""