🍭 Using WebHooks to automatically pull code.
- GitHub
- Gitee
- Gitea
- GitLab
- php >= 7.1
- ext-swoole (可以直接使用 swoole-cli)
composer create-project sy-records/git-deploy
- 修改配置文件
config.json
server
对应的是Swoole\Http\Server
的相关配置
ip
:IP地址port
:端口mode
:启动模式SWOOLE_BASE/SWOOLE_PROCESS
settings
:Server的配置
正式运行时需要启动守护进程,将
daemonize
修改为1
"server": {
"ip": "0.0.0.0",
"port": 9666,
"mode": 1,
"settings": {
"worker_num": 1,
"daemonize": 0
}
},
sites
对应的是项目的仓库等信息
分为github
和gitee
,key
是仓库名称,支持多个仓库。
secret
/password
:密钥/密码;github
使用secret
,gitee
的 WebHook 密码使用password
,签名密钥使用secret
ref
:分支event_name
:事件名称;github
为push
,gitee
为push_hooks
shells
:需要执行的脚本
"sites": {
"github": {
"sy-records/git-deploy": {
"secret": "password",
"ref": "refs/heads/master",
"event_name": "push",
"shells": [
"git -C /yourpath/git-deploy pull"
]
}
},
"gitee": {
"sy-records/git-deploy": {
"password": "password",
"ref": "refs/heads/master",
"event_name": "push_hooks",
"shells": [
"git -C /yourpath/git-deploy pull"
]
}
},
"gitea": {
"sy-records/git-deploy": {
"secret": "password",
"ref": "refs/heads/master",
"event_name": "push",
"shells": [
"git -C /yourpath/git-deploy pull"
]
}
},
"gitlab": {
"sy-records/git-deploy": {
"secret": "password",
"ref": "refs/heads/master",
"event_name": "push",
"shells": [
"git -C /yourpath/git-deploy pull"
]
}
}
}
- 填写WebHook
URL:http://ip:port/github
or http://ip:port/gitee
Secret/PassWord:对应config.json
中的secret/password
php start.php
[Unit]
Description=Git Depoly Service
After=network.target
[Service]
ExecStart=/usr/bin/php /workspace/git-deploy/start.php
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target