Use webhook to deploy Hugo

First, make sure your hugo blog files are hosted on Github or any other git hosting server where you can access to through network. Github is suggested.

in your server

1
2
3
4
5
6
apt-get install hugo
wget https://github.com/adnanh/webhook/releases/download/2.6.8/webhook-linux-amd64.tar.gz
tar -zxvf webhook-linux-amd64.tar.gz
mv webhook-linux-amd64 webhook && cd webhook
chmod +x webhook
vim hooks.json
1
2
3
4
5
6
7
[
  {
    "id": "redeploy-webhook",
    "execute-command": "/pathto/hookscripts.sh",
    "command-working-directory": "/directory/to/webhook"
  }
]
1
2
cd ~/webhook
./webhook -hooks hooks.json -verbose -port 1234 -hotreload &

or add

1
/pathto/webhook -hooks /pathto/hooks.json -verbose -port 1234 -hotreload &

to /etc/rc.local

when started, you can test it use

1
curl -X POST http://example.com:1234/hooks/redeploy-webhook

here is my hugo.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#!/bin/sh
GIT_REPO=https://github.com/kirileec/llinx.me
TMP_GIT_CLONE=/tmp/blog
NGINX_HTML=/var/www
rm -rf ${TMP_GIT_CLONE}
git clone $GIT_REPO $TMP_GIT_CLONE
cd $TMP_GIT_CLONE/llinx.me
hugo
rm -rf ${NGINX_HTML}/*
cp -rf ${TMP_GIT_CLONE}/llinx.me/public/* ${NGINX_HTML}
记录平时瞎折腾遇到的各种问题, 方便查找
使用 Hugo 构建
主题 Stack 3.29.0Jimmy 设计