用go实现的webhook
package main
import (
"bytes"
"log"
"net/http"
"os/exec"
)func main() {
http.HandleFunc("/webhook", func(writer http.ResponseWriter, request *http.Request) {
cmd := exec.Command("/bin/bash", "-c","./pull.bash")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
log.Print(err.Error())
}
log.Print(out.String())
})
http.ListenAndServe(":8080",nil)
}
pull.bash
这只是自动拉取最新代码,要自动部署的同学,可以配合上一篇docker自动部署,加上重新启动容器
cd /opt/gopath/src/project/
git pull