Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git hook 实现自动部署 #8

Open
Dream4ever opened this issue May 17, 2018 · 0 comments
Open

Git hook 实现自动部署 #8

Dream4ever opened this issue May 17, 2018 · 0 comments
Labels
Back-end Where data really come and go Deployment Deploy content to server Git

Comments

@Dream4ever
Copy link
Owner

Dream4ever commented May 17, 2018

需求描述

公司所购阿里云 ECS 服务器的操作系统为 Windows 2012,想要改进项目部署的方式。但是安装了 2012 的 ECS 服务器无法安装 docker,如果启用 SSH 又担心降低服务器的安全性,于是最后考虑研究 git hook 以实现项目的自动部署。

方案调研

先以 git hook 自动部署git hook auto build 作为关键字上网搜索,对整体流程有了基本的了解,知道了 post-receive 或者 post-update是所需的 hook。

然后在此过程中,了解到 GitHub 本身提供 webhook 功能,可以监听项目的各个阶段。比如本机 push 了代码到 GitHub 之后,GitHub 将 POST 指定的内容到用户设定的 Payload URL,这个 URL 可以是用户编写的后台服务的 URL。

URL 接收 GitHub 的 POST 请求之后,可执行对应的动作,比如将最新的项目代码 pull 到服务器上的指定目录并执行编译操作,这样就可以将项目的最新版本自动部署至服务器。

既然如此,那直接用 GitHub 为每个项目提供的 webhook 其实更方便,可以用一个 Payload URL 为各个项目设置好自动发布的代码,便于集中管理。

关键字清单

还是英文的搜索结果更靠谱。

  • Google 关键字: git hook 自动部署
  • Google 关键字: git hook auto build
  • Google 关键字: github webhook 自动部署

入选方案

  • typicode / husky:typicode 的这个项目也蛮不错,可以考虑。
  • rvagg/github-webhook-handler:在 GitHub 上用 webhook 作为关键字搜索,然后只显示 JavaScript 语言为主的项目,按 Star 数排行,第一页的项目筛选了一遍之后,发现只有这个项目是靠谱的。

参考资料

应用过程

GitHub 的 Webhook 还是很省心的,只要填写的 API 能通就可以,自己写了一个 Express 的后端服务,用来自动将指定项目的代码 pull 下来,但是用 nssm 启动为服务之后,不知道为什么不管用,还得调试调试。

要点总结

@Dream4ever Dream4ever added Back-end Where data really come and go Deployment Deploy content to server labels May 17, 2018
@Dream4ever Dream4ever added the Git label Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Back-end Where data really come and go Deployment Deploy content to server Git
Projects
None yet
Development

No branches or pull requests

1 participant