网页自动化部署(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,开启导致配置不成功,不知道为什么。

以上配置完成,即可。

相关推荐
wayuncn13 分钟前
影响服务器托管费用的因素
运维·服务器·数据中心·服务器托管·物理服务器租用·服务器机柜·idc机房托管
喜欢你,还有大家15 分钟前
Linux笔记10——shell编程基础-4
linux·运维·服务器·笔记
司徒轩宇27 分钟前
Python secrets模块:安全随机数生成的最佳实践
运维·python·安全
wjm051937 分钟前
jenkins使用publishover ssh 进行远程连接
运维·ssh·jenkins
✎﹏赤子·墨筱晗♪1 小时前
服务器初始化
运维·服务器
tanyongxi661 小时前
简易shell
linux·运维·服务器
df007df2 小时前
【RAGFlow代码详解-29】Docker 部署
运维·docker·容器
Clain2 小时前
如何快速建站 | 云服务器配置+公网ip部署网站全流程详解
linux·运维·服务器
白-胖-子2 小时前
RHEL8.6环境下批量验证服务器凭据并配置Ansible免密管理全流程
运维·服务器·ansible
云动雨颤3 小时前
Linux下PXE服务器搭建
linux·运维·服务器