{"id":19035656,"url":"https://github.com/schwanncheung/webhook-deployer","last_synced_at":"2026-06-17T18:34:04.550Z","repository":{"id":143797950,"uuid":"216224449","full_name":"schwanncheung/webhook-deployer","owner":"schwanncheung","description":"基于 github|gitlab|gitee 的 webhook 机制实现的服务器自动部署程序","archived":false,"fork":false,"pushed_at":"2023-02-13T09:00:10.000Z","size":164,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-02T05:25:56.222Z","etag":null,"topics":["autodeploy","gitee-webhook","github-webhook","gitlab-webhook","webhook-deployer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schwanncheung.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-19T15:04:56.000Z","updated_at":"2023-02-10T12:46:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"180844bf-4c83-4de5-809a-d668436ceeb2","html_url":"https://github.com/schwanncheung/webhook-deployer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schwanncheung%2Fwebhook-deployer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schwanncheung%2Fwebhook-deployer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schwanncheung%2Fwebhook-deployer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schwanncheung%2Fwebhook-deployer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schwanncheung","download_url":"https://codeload.github.com/schwanncheung/webhook-deployer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240089801,"owners_count":19746316,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autodeploy","gitee-webhook","github-webhook","gitlab-webhook","webhook-deployer"],"created_at":"2024-11-08T21:51:40.283Z","updated_at":"2026-05-05T16:30:16.307Z","avatar_url":"https://github.com/schwanncheung.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Webhook Deployer\n\n基于 github|gitlab|gitee 的 webhook 机制实现的服务器自动部署程序。\n\n原理是在 github 项目的 `webhook` 设置处添加本程序服务地址作为钩子，当 github 有 push 等动作时，会 POST 请求本服务接口，程序会自动校验合法请求并执行配置的 shell 文件，由 shell 文件进行项目部署的一系列处理，因此本程序支持 nodejs、java、php 等任何能通过 shell 自动部署的项目，如下图：\n\n![技术构架图](assets/architecture.png)\n\n本程序采用 [nodejs](https://nodejs.org/zh-cn/) 语言基于 [egg.js](https://eggjs.org/zh-cn/) 框架开发实现，服务器需安装 Node 9+ 版本。\n\n\n## Configuration\n\n程序配置文件 `conf/config.json` 说明\n\n* dingtalkRobot - 钉钉机器人配置（可选）\n  * enable - 是否启动，true-启用，false-停用(默认)\n  * accessToken - 机器人 token\n  * startTemplate - 开始部署时消息通知模板，仅支持模板变量 `#REPONSITORY_NAME#` ，表示仓库名\n  * endTemplate - 部署完成时消息消息模板，仅支持模板变量 `#REPONSITORY_NAME#` ，表示仓库名\n* secretToken - 在 webhook 设置的全局密钥（可选）\n* github - 项目在 github 仓库的配置，每个项目一个独立的属性 `key` ，到时需配置在 webhook 地址上\n  * event - 指定何种事件才触发，默认 push，注意 github 和 gitlab 对应的事件名不一致\n  * secret - 在 webhook 设置的密钥，如不配置则引用 `secretToken` 全局密钥\n  * cmdFile - 部署时需要自动执行的 shell 文件，用绝对全路径\n  * args - 传递给 shell 文件的固定参数，可在 shell 中用 $2、$3 ... 方式获取\n* gitlab - 项目在 gitlab 仓库的配置，同 `github`\n* gitee - 项目在 gitee 码云仓库的配置，同 `github`\n\n\n## Step 1\n\n在服务器指定目录下拉取本仓库代码\n\n```bash\n$ git clone -b master https://github.com/schwanncheung/webhook-deployer.git webhook-deployer\n```\n\n### Step 2\n\n进入 `webhook-deployer` 目录，安装依赖\n\n```bash\n$ cd webhook-deployer\n$ npm install\n```\n\n## Step 3\n\n配置需要自动部署的项目，\b在 `webhook-deployer` 根目录下创建 `conf` 目录，然后在该目录创建 `config.json` 配置文件。\n\n```bash\n$ mkdir conf\n$ touch conf/config.json\n$ vi conf/config.json\n```\n\n配置文件说明见 `Configuration`, 示例：\n\n```json\n{\n  \"dingtalkRobot\": {\n    \"enable\": true,\n    \"accessToken\": \"xxxxxxxxxxxxx\",\n    \"startTemplate\": \"开始部署 #REPONSITORY_NAME# ...\",\n    \"endTemplate\": \"#REPONSITORY_NAME# 部署完成.\"\n  },\n  \"secretToken\": \"xxxxxxxxxxxxxxxxx\",\n  \"github\": {\n    \"project1\": {\n      \"secret\": \"xxxxx\",\n      \"cmdFile\": \"/scripts/project1_deploy.sh\"\n    }\n  },\n  \"gitlab\": {\n    \"project2\": {\n      \"event\": \"push hook\",\n      \"cmdFile\": \"/scripts/project2_deploy.sh\",\n      \"args\": [ \"release\", \"argument 2\" ]\n    }\n  },\n  \"gitee\": {\n  }\n}\n```\n\n## Step 4\n\n创建上面配置文件中 `cmdFile` 指定的 shell 脚本文件，根据每个项目的实际需要创建脚本。\n\n```bash\n#/bin/bash \n\ngit clone -b $2 git@gitlab.com:xxxx/project2.git project2\ncd project2\nnpm install --production\n# 各种打包处理逻辑...\n\n```\n\n## Step 5\n\n启动服务，在 `webhook-deployer` 目录下执行以下脚本，它会占用 `7777` 端口启动。\n\n```bash\n$ npm run start\n```\n\n此时，http://你的服务器IP:7777/ 应该已经正常启动了，如果不想直接使用 IP，比如域名 `webhook.xxx.com`, 可以用 nginx 做反向代理指向 `http://127.0.0:7777` 即可。\n\n\n## Step 6\n\n* github 项目，在 Settings 中，找到 Webhooks，添加 Webhook，URL 填写 `http://webhook.xxx.com/github?key=project1` (其中 key 为配置上面配置文件中对应键值)，ContentType 选择 `application/json`，填上 secret 保存。\n* gitlab 项目，在 Settings 中，找到 Integrations，添加 Webhook，URL 填写 `http://webhook.xxx.com/gitlab?key=project2` (其中 key 为配置上面配置文件中对应键值)，填上 secret，选择 Push events 保存。\n* gitee 项目，在 管理 中，找到 Webhooks，添加 Webhook，URL 填写 `http://webhook.xxx.com/gitee?key=project3` (其中 key 为配置上面配置文件中对应键值)，密码填上 secret，选择 Push 事件保存。\n\n经过以上配置，可以尝试提交代码进行自动化部署了。\n\n## Other\n\n如果需要停止本程序服务，直接在 `webhook-deployer` 目录下执行：\n\n```bash\n$ npm run stop\n```\n\n## License\n\nMIT\n\n\n## Donate\n\n开源不易，如有帮助，就打赏一杯82年的咖啡给作者压压惊吧~\n\n| ![支付宝](https://github.com/schwanncheung/blog/blob/master/assets/qr_alipay.jpg) | ![微信](https://github.com/schwanncheung/blog/blob/master/assets/qr_weixin.jpg) |\n|----|----|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschwanncheung%2Fwebhook-deployer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschwanncheung%2Fwebhook-deployer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschwanncheung%2Fwebhook-deployer/lists"}