@xsin/x.deploy
v1.4.13
Published
基于 Shell 脚本和 CI/CD 工作流的自动化部署解决方案,支持应用部署至阿里云多台主机、 Certbot 证书生成和自动续期、Nginx 配置、Docker 容器管理等。
Downloads
52
Maintainers
Readme
X.Deploy
基于 Shell 脚本和 CI/CD 工作流的自动化部署解决方案。
- 目标用户: 开发者、运维工程师
- 核心价值: 简化应用程序的部署流程,支持多环境、多服务器、Docker 集成、NGINX 配置、SSL 证书管理等功能。
使用方法
安装
使用 bun 安装:
bun add -g @aispin/x.deploy或使用 npm 安装:
npm install -g @aispin/x.deploy初始化项目
在项目根目录下初始化 x.deploy:
x.deploy init这将创建 .xdeploy 目录并生成默认的生产环境配置。
添加其他环境(可选)
添加测试环境:
x.deploy init -e test配置环境
初始化后,编辑环境配置文件:
vim .xdeploy/production.yml # 或其他环境的配置文件注意:根据需要修改 .xdeploy 目录下的其他配置文件,确认无误后将 XDP_DEPLOY_READY 设置为 true。
Github Token 配置
对于基于 Github Actions 工作流进行部署的项目,需要设置 XDP_GITHUB_OWNER、XDP_GITHUB_REPO 和 XDS_GITHUB_TOKEN 三个变量(密钥)。
XDS_GITHUB_TOKEN 需要有读写 Github 环境变量的权限。
Fine-grained access tokens for "Create or update an environment"
This endpoint works with the following fine-grained token types:
- GitHub App user access tokens
- GitHub App installation access tokens
- Fine-grained personal access tokens
The fine-grained token must have the following permission set:
"Administration" repository permissions (write)构建生成部署文件
生成或更新指定环境的工作流、配置及脚本文件:
x.deploy build -e production # 默认为 production 环境这将根据配置文件生成相应的部署文件和 GitHub Actions 工作流文件。
使用 GitHub Actions 部署
配置完成后,推送代码到 GitHub 仓库即可触发自动部署流程,或手动在 GitHub Actions 页面触发工作流。
更新 .gitignore 文件
添加以下内容至 .gitignore,避免机密和无用文件传到 git 仓库。
# X.Deploy
.xdeploy/templates
.xdeploy/*.yml
.xdeploy/.backup项目文档
Pkg Registry
常见问题
xdeploy-init-server 工作流出现 Connection Time out 错误
fatal: unable to access 'https://github.com/aiblaze/linux.init.git/': Failed to connect to github.com port 443: Connection timed out解决办法:
通过覆盖 GitHub 域名的 DNS 解析,绕过污染或延迟高的 DNS 服务器:
- 获取最新 IP 地址
使用工具(如 IPAddress.com)分别查询以下域名当前最快的 IP:
github.com、api.github.com、assets-cdn.github.com、github.global.ssl.fastly.net。
- 修改 hosts 文件
在阿里云主机上执行:
sudo vim /etc/hosts添加如下内容(示例 IP 需替换为查询到的最新值):
140.82.114.4 github.com
140.82.114.5 api.github.com
185.199.108.153 assets-cdn.github.com
199.232.69.194 github.global.ssl.fastly.net- 刷新 DNS 缓存
sudo systemctl restart NetworkManager # AlmaLinux参考文章:https://developer.aliyun.com/article/1077240
