1. 程式人生 > >git hook自動化部署

git hook自動化部署

git add rev 地址 origin parse ini 是不是 不用 dep

一、建立本地倉庫

cd 項目路徑
git init 
git add .
git commit -m "日誌"

二、建立服務器git用戶

  yum install -y git
    groupadd git
    useradd -g git git
    #這裏沒有加git禁止登陸,因為nologin 總是報錯
    cd /home/git
    git init --bare xxx.git
    cd xxx.git

三、添加遠程連接

 git remote add origin 遠程倉庫地址

四、添加git登陸密鑰

  ssh-keygen -t rsa -P
    #-P表示密碼,-P ‘‘ 就表示空密碼,也可以不用-P參數,這樣就要三車回車,用-P就一次回車。
    
  復制 .ssh 中的id_rsa.pub 到 遠程/home/git/.ssh/authorized_keys/
  #等待添加  authorized_keys 權限 以及服務器生成
  

五、添加鉤子函數

/home/git/xxx.git/hooks/post-receive

post-receive內容:

#!/bin/sh


#判斷是不是遠端倉庫

IS_BARE=$(git rev-parse --is-bare-repository)
if [ -z "$IS_BARE" ]; then
echo >&2 "fatal: post-receive: IS_NOT_BARE"
exit 1
fi

unset GIT_DIR
DeployPath="/alidata/www/jkdzz"

echo "==============================================="
cd $DeployPath
echo "deploying the test web"

六、git文件夾修改權限

chmod -R git:git /home/git/xxx.git

七、新建部署倉庫

 cd www
    git init XXX
    chown -R git:www ../XXX
    git remote add origin www/XXX

八、推送一下自己的項目到遠程服務器

git push origin master 

九、www可能會無法創建文件,所以要設置資源區7,臨時文件,777權限好一點

git hook自動化部署