惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
C
Cisco Blogs
The Hacker News
The Hacker News
T
Threatpost
S
Schneier on Security
K
Kaspersky official blog
Spread Privacy
Spread Privacy
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
NISL@THU
NISL@THU
量子位
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
News and Events Feed by Topic
爱范儿
爱范儿
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Project Zero
Project Zero
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Cisco Talos Blog
Cisco Talos Blog
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
T
Tenable Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
Forbes - Security
Forbes - Security
博客园 - 三生石上(FineUI控件)
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
V
V2EX
Webroot Blog
Webroot Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale
M
MIT News - Artificial intelligence
Scott Helme
Scott Helme
Simon Willison's Weblog
Simon Willison's Weblog
L
LangChain Blog
W
WeLiveSecurity
Cloudbric
Cloudbric

mephisto.cc

修复rime-ice无法弹出候选框的问题 开机滚动字体显示优化 个人网站安全防护 树莓派上部署Vaultwarden 使用goaccess实时分析Caddy日志 个人网站监控 Hugo全站AVIF记 Linux下尝试使用Godot开发小游戏 Arch linux dae 透明代理 Airflow接管galler-dl下载任务 如何使用gallery-dl批量下载图像 Arch核显下如何愉快玩Dota2和CS2 Arch/labwc 环境网络相关设置 Rime添加dota2词库 Arch 重装记录 Supertuxkart iOS版终于发布了 打造自己的流媒体音乐服务 剪切板管理工具clipcat推荐 MangoHud性能监控 微信小程序开发记 Rofi试用 解决Arch下VSCode无法输入中文的问题 独立窗口管理器下无法录屏问题处理 上海市二手房成交数据监控 OpenLDAP监控 Arch linux如何顺畅连接蓝牙设备 使用Git和Ansible管理配置文件 Arch Linux SSL VPN 客户端配置 简单获取celery任务实时结果 Arch linux下iNode客户端的安装和使用方法 券商费率调整记 迷你主机组装记 Labwc更换定制皮肤 树莓派跑分流代理 实用自动代理配置示例 九年老鼠标复活记 Openvpn示例 Mac下如何旋转webp图片 如何隐藏Vscode中Markdown PDF插件的头部内容 解决Linux下网络配置无法变更保存的问题 labwc环境启用wlogout Ubuntu下新官方微信尝鲜 简单检测用户是否开启广告屏蔽 Atuin ZFS下卡顿问题解决 Wine安装64位微信 Fish 和 Atuin使用记 Fastapi简单实现临时下载链接 Fastapi微信公众号开发简要 Hugo根据语种展示不同内容 如何修复Waybar微信图标错误 信封加密简要 Linux环境下维护公众号记录 快速隐藏和呼出终端 Wayland环境自动切换壁纸 SuperTuxKart 试玩 简单抓取雪球股票快讯 为什么你的kill命令不能列出信号表 Wine安装微信保姆教程 Hysteria科学上网简要 Ubuntu 23.10 钉钉无法启动解决方法 网站导航栏防止插入Adsense自动广告 Linux环境按键检测 Hugo文末添加最后修改时间 Wayland环境ksnip无法复制问题解决 我眼中的股票市场 Caddy简单图片防盗链 greetd和regreet使用教程 Wayland环境下截图加后期修改 Wayland 环境下gif录屏 Firefox的一些有趣功能 Ubuntu 切换系统语言 Firefox 标题栏高度调整 网站添加回到顶部功能 Hugo自定义字体 Labwc 便捷配置 Wofi使用教程 窗口管理器labwc使用记 文件共享软件Dufs推荐 Hugo静态站点接入Adsense广告 Fcitx5配置详解 Ubuntu安装chrome的方法总结 一种Xterm.js的全屏方案 Google网址收录api Python示例 手机听离线音乐 Snipe it资产导入 应用启动器yofi使用配置 Snipe it资产管理系统安装使用 Ubuntu开机启动加速 Vue3 vite TypeScript跨域等相关设置 Ubuntu手动升级Libreoffice Ubuntu设置alacritty为默认终端 简体文章批量转换为繁体 使用Inkscape调整svg图片大小 实用命令 使用mitmproxy给手机app抓包 Python中rstrip方法细解 Github同主机多仓库部署deploy key问题处理 Linux安装最新版本Python KeePassXC使用教程 Ubuntu 22.10连接蓝牙耳机报错br-connection-profile-unavailable解决方法
利用github webhook和Fastapi自动更新网站
2022-06-06 · via mephisto.cc

我的的小破站放在国外机房的一个乞丐主机上面,代码托管在 github 私有仓库,push 代码的时候希望自动更新网站,github 有 action,可以自己编写相关逻辑在 github 的 runner 上面实现代码更新,最简单的是 ssh 到服务器上面,执行相关操作,但是这样要填写 Actions secrets,老实说有点不太放心,想自己编写个简单服务更新代码,毕竟自己全部掌控,真理在手,天下我有,减少依赖,供应链安全^_^

编写供 github webhook 使用的接口

  • 如下所示,利用 Fastapi 的 Background Tasks 功能,向/api/update/mephistocc 提交 post 请求的时候, 执行更新网站的脚本
1def update_site(script_name=""):
2    subprocess.run(["/bin/bash", script_name])
3
4
5@app.post("/api/update/mephistocc")
6async def update_mephisto_cc(background_tasks: BackgroundTasks):
7    background_tasks.add_task(update_site, script_name="update_mephisto.cc.sh")
8    return {"message": "update site in the background"}
  • 超级简单的更新脚本, pull main 仓库即可
 1(.venv) ➜  stock.mephisto.cc git:(main) cat update_mephisto.cc.sh
 2#!/bin/sh
 3echo '开始执行webhook钩子'
 4
 5HOME_DIR=/data/mephisto.cc #此目录为服务器页面展示目录
 6cd $HOME_DIR
 7
 8echo '清除git缓存'
 9git clean -df
10
11echo '拉取远程代码'
12git pull origin main
13
14echo 'Job Done!'%
  • 服务跑在 gunicorn 上面
 1root@tokyo:/data/mephisto.cc# systemctl status gunicorn
 2● gunicorn.service - gunicorn daemon
 3    Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
 4    Active: active (running) since  xxxxx CST; 15min ago
 5Main PID: 2467813 (gunicorn)
 6    Status: "Gunicorn arbiter booted"
 7    Tasks: 5 (limit: 1036)
 8    Memory: 91.2M
 9    CGroup: /system.slice/gunicorn.service
10            ├─2467813 /usr/bin/python3 /usr/local/bin/gunicorn -c api/gunicorn.py api.main:app
11            ├─2467814 /usr/bin/python3 /usr/local/bin/gunicorn -c api/gunicorn.py api.main:app
12            ├─2467815 /usr/bin/python3 /usr/local/bin/gunicorn -c api/gunicorn.py api.main:app
13            ├─2467816 /usr/bin/python3 /usr/local/bin/gunicorn -c api/gunicorn.py api.main:app
14            └─2467817 /usr/bin/python3 /usr/local/bin/gunicorn -c api/gunicorn.py api.main:app
  • 在 github 仓库的配置 Payload URL,如下图所示

    github webhook
  • push 触发下 webhook,再去后台查看结果,看下图触发成功,返回了代码定义的结果

    github webhook result

当然, 网站的更新方式千千万,你直接远古 scp ssh ftp rsync 更新都可以,我是因为登录外国服务器卡,也不想老是登录,这样够用也够灵活,同时只依赖 github 的 webhook,github 挂了,gitlab 类的也有 webhook,不用去学 action 的语法,个人觉得简单易用可控, 复杂的动态站点更新,可以自己定义格外的逻辑