网页自动化部署(webhook方法)

实现步骤:

  1. 宝塔安装宝塔WebHook 2.5插件。

  2. github 上配置网页仓库(或可在服务器的网页根目录clone)。

  3. 配置宝塔WebHook 2.5

    • 添加hook脚本;

    • 编辑添加syncJC脚本;
bash 复制代码
#!/bin/bash
# 定义网站根目录
WEBROOT="/www/wwwroot/jessi53"
# 定义日志文件路径
LOGFILE="/www/server/panel/plugin/webhook/log/webhook.log"

# 设置 HOME 环境变量
export HOME=/root

# 将调试信息写入日志文件
echo "[$(date)] Webhook triggered. Starting deployment process..." >> $LOGFILE

# 切换到网站根目录
echo "[$(date)] Switching to directory: $WEBROOT" >> $LOGFILE
cd $WEBROOT

# 设置 Git 安全目录
echo "[$(date)] Setting Git safe directory: $WEBROOT" >> $LOGFILE
git config --global --add safe.directory $WEBROOT >> $LOGFILE 2>&1
git config --system --add safe.directory $WEBROOT >> $LOGFILE 2>&1

# 检查是否是 Git 仓库
if [ -d "$WEBROOT/.git" ]; then
    echo "[$(date)] Fetching latest changes from GitHub..." >> $LOGFILE
    git fetch origin >> $LOGFILE 2>&1
    echo "[$(date)] Resetting local branch to match remote branch..." >> $LOGFILE
    git reset --hard origin/main >> $LOGFILE 2>&1
else
    echo "[$(date)] Initializing Git repository and pulling latest changes..." >> $LOGFILE
    git init >> $LOGFILE 2>&1
    git remote add origin https://github.com/Jsvi53/jessi53.git >> $LOGFILE 2>&1
    git fetch origin >> $LOGFILE 2>&1
    git reset --hard origin/main >> $LOGFILE 2>&1
fi

# 设置目录权限
echo "[$(date)] Setting permissions for: $WEBROOT" >> $LOGFILE
chown -R www:www $WEBROOT >> $LOGFILE 2>&1

# 将请求体写入日志文件
echo "[$(date)] Webhook triggered. Pulled latest changes from GitHub." >> $LOGFILE

注意,网站的根目录为jessi53。

以上,宝塔上webhook配置完毕,可点击测试进行测试,然后查看log

  1. 配置github 上的 WebHooks:

开启ssl,开启导致配置不成功,不知道为什么。

以上配置完成,即可。

相关推荐
REDcker6 分钟前
Linux 文件描述符与 Socket 选项操作详解
linux·运维·网络
2501_9277730731 分钟前
imx6驱动
linux·运维·服务器
hy____1231 小时前
Linux_进程间通信
linux·运维·服务器
银发控、1 小时前
nginx静态资源
运维·nginx
老百姓懂点AI1 小时前
[测试工程] 告别“玄学”评测:智能体来了(西南总部)基于AI agent指挥官的自动化Eval框架与AI调度官的回归测试
运维·人工智能·自动化
德育处主任Pro1 小时前
『NAS』用SSH的方式连上NAS
运维·ssh
Meaauf2 小时前
VMware安装中科方德服务器操作系统
运维·服务器·中科方德
南宫码农2 小时前
神马影视8.5版本如意伪静态+视频教程
linux·运维·centos
j_xxx404_2 小时前
Linux:命令行参数与环境变量
linux·运维·服务器
朗宇芯工控2 小时前
注塑机械手控制系统的性能要求有哪些?
科技·自动化·制造·工业·运动控制系统