Automate deployment with Webhooks

Source: Internet
Author: User
Tags git client git clone

Work often use webhooks to achieve automatic deployment, the total write is placed on oneNote above, experience not to share the fun, now take out to share, I hope everyone in the work can ease

Ubuntu Install git client

sudo apt install git查看版本git --version

Cloning code from the line

git clone  git 地址

Prepare the hook file

* 创建并修改目录    mkdir -p /Data/wwwroot/hooks    chown -R root:root  /Data/wwwroot/hooks* 写入文件:每个项目两个文件 -- 入口文件+.sh文件    sudo -Hu apache touch /Data/wwwroot/hooks/funds-v1-update.php    sudo -Hu apache touch /Data/wwwroot/hooks/    chmod 700 funds-v1-update.php    chmod 700
    funds-v1-update.php 文件代码:        <?php                passthru(‘bin/sh /Data/wwwroot/hooks/‘); 文件代码:         #!/bin/bash        WEB_PATH=‘/Data/wwwroot/‘        WEB_USER=‘root‘        WEB_USERGROUP=‘root‘        echo "start master"         cd $WEB_PATH        #whoami     echo "pulling source code ..."     /usr/bin/git reset --head origin/master     /usr/bin/git clean -f     /usr/bin/git pull     /usr/bin/git checkout master     echo "changing permissions..."     chown -R $WEB_USER:$WEB_USERGROUP $WEB_PATH     echo "finished"

Deploy public key configuration

sudo -Hu apache ssh-keygen -t rsa       # 请选择 “no passphrase”,一直回车下去复制/root/.ssh/id_rsa.pub的内容并添加到部署公钥:        选择项目 > 设置 > 部署公钥 > 新建 > 粘贴到下面框并确认

Add Webhooks

选择 项目 > 设置 > Webhook >新建hook > 复制hooks/funds-v1-update.php 所在的网址 :         令牌可选,建议写上        稍过几秒,刷新页面查看hook状态,显示为绿色勾就 OK 了

Configuring Hooks and Project Server Nginx

    ? 配置 nginx        ○ nginx 钩子配置        ○ nginx 项目配置        详见:Nginx 配置虚拟主机三种方法    ? 配置远程连接        ○ sudo -u root git clone [email protected]:yourUrl/        ○ 首次必须要克隆一次,而且要给apache分配/Data/wwwroot的读写权限

Automate deployment with Webhooks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.