{"id":41177230,"url":"https://github.com/yuedun/zhuque","last_synced_at":"2026-01-22T19:59:34.844Z","repository":{"id":50756975,"uuid":"287659002","full_name":"yuedun/zhuque","owner":"yuedun","description":"使用go开发的简单高效的发布系统，支持pm2 deploy和scp两种发布方式。","archived":false,"fork":false,"pushed_at":"2023-04-20T10:09:44.000Z","size":3233,"stargazers_count":21,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-06-19T02:02:04.149Z","etag":null,"topics":["cicd","nodejs","pm2","rsync","scp","ssh-keys"],"latest_commit_sha":null,"homepage":"https://yuedun.gitbook.io/zhuque/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuedun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-15T01:53:44.000Z","updated_at":"2024-01-26T04:06:49.000Z","dependencies_parsed_at":"2024-06-19T01:54:25.784Z","dependency_job_id":null,"html_url":"https://github.com/yuedun/zhuque","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/yuedun/zhuque","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuedun%2Fzhuque","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuedun%2Fzhuque/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuedun%2Fzhuque/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuedun%2Fzhuque/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuedun","download_url":"https://codeload.github.com/yuedun/zhuque/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuedun%2Fzhuque/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28670186,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T19:36:09.361Z","status":"ssl_error","status_checked_at":"2026-01-22T19:36:05.567Z","response_time":144,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cicd","nodejs","pm2","rsync","scp","ssh-keys"],"created_at":"2026-01-22T19:59:34.085Z","updated_at":"2026-01-22T19:59:34.837Z","avatar_url":"https://github.com/yuedun.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 朱雀发布系统\n\n\u003c!-- TOC --\u003e\n- [朱雀发布系统](#朱雀发布系统)\n    - [介绍](#介绍)\n    - [使用框架文档](#使用框架文档)\n    - [本地开发](#本地开发)\n        - [依赖项](#依赖项)\n        - [首次运行](#首次运行)\n    - [部署到服务器](#部署到服务器)\n        - [部署流程](#部署流程)\n        - [系统要求](#系统要求)\n        - [权限架构](#权限架构)\n        - [简单部署](#简单部署)\n        - [Complete tutorial](#complete-tutorial)\n        - [生态系统文件参考](#生态系统文件参考)\n        - [部署选项](#部署选项)\n    - [SCP发布](#scp发布)\n        - [发布流程](#发布流程)\n        - [配置说明](#配置说明)\n\u003c!-- /TOC --\u003e\n\n#### [文档](https://yuedun.gitbook.io/zhuque/)\n## 介绍\n朱雀发布系统是专门为nodejs发布而开发的系统，使用go语言开发，前端使用了layui mini框架，简单易上手。\n朱雀发布系统前后端分离，但又是一体的，无需部署两套服务。\n\n理论上朱雀发布系统可以发布其他语言应用程序，但其与nodejs更加相得益彰。\n原因是朱雀发布系统依赖于PM2，PM2大家都知道，与nodejs几乎是绝配，所以有nodejs的地方很大可能有PM2，所以使用朱雀发布系统就显得更加简单了，无需专门安装PM2。\n\n（推荐）同时也支持scp（rsync）发布模式。优点是一键部署发布，使用简单。\n\n\n数据库使用sqlite，无需单独安装和配置。\n\n## 使用框架文档\n[前端框架layuimini](http://layuimini.99php.cn/docs/index.html)\n\n[前端框架layuimini](http://layuimini.99php.cn/onepage/v2/index.html)\n\n[前端框架layui](https://www.layui.com/doc/)\n\n[Font Awesome图标库](https://fontawesome.dashgame.com/)\n\n[后端框架gorm](http://gorm.book.jasperxu.com/)\n[后端框架gorm](https://gorm.io/zh_CN/docs/index.html)\n[后端框架gorm](https://v1.gorm.io/zh_CN/docs/index.html)\n\n[后端框架gin](https://github.com/gin-gonic/gin#using-middleware)\n\n## 本地开发\n\n### 依赖项\n项目使用了sqlite3，需要安装gcc，参考地址：[gcc安装](https://www.jianshu.com/p/dc0fc5d8c900)\n如果只想使用mysql的话注释掉代码`github.com/jinzhu/gorm/dialects/sqlite`即可。\n### 首次运行\n1. 复制`conf-sample.yaml`文件为`conf.yaml`文件。不做任何修改也可以运行。\n2. 配置`env`变量为`debug`。可选\n3. 初始化数据库，见`zhuque.sql`。\n4. 使用`test`账号，密码`test`登录系统。\n\n\n## 部署到服务器\n### 部署流程\n1. 在服务器指定位置下载源码。\n2. [linux版本下载](https://github.com/yuedun/zhuque/releases/download/v1.3.0/zhuque)\n或者安装go环境。go可以交叉编译，但是由于sqlite的缘故，windows环境下并不能顺利的编译linux版本，所以最好还是在linux环境下编译。\n3. 配置`conf.yaml`文件，参照`conf-sample.yaml`文件。\n4. 项目目录中编译`go build`，第一次会安装依赖会慢一些。\n5. `./zhuque`启动服务。\n\n### 系统要求\n1核2G，2核4G都可以，运行时占用内存只有几M，所以对系统配置要求不高。\n### 权限架构\n该系统权限使用了基于角色的访问控制方法（RBAC）。是目前公认的解决大型企业的统一资源访问控制的有效方法。 其显著的两大特征是：1.减小授权管理的复杂性，降低管理开销。2.灵活地支持企业的安全策略，并对企业的变化有很大的伸缩性。\n\n参考文档：\n\n[官方原文](https://pm2.keymetrics.io/docs/usage/deployment/)\n\n[PM2自动部署代码流程总结](https://segmentfault.com/a/1190000017310047)\n\n[pm2 官方文档 学习笔记](https://my.oschina.net/u/4400196/blog/3283439)\n\n[通过Github与PM2部署Node应用](https://zhuanlan.zhihu.com/p/20940096)\n\n[deploy](https://github.com/Unitech/PM2/blob/0.14.7/ADVANCED_README.md#deployment-options)\n\n### 简单部署\n\n你只需要在ecosystem.json文件中添加**deploy**属性。 下面是是部署一个应用的最低要求:\n\nprocess.json:\n\n```\n{\n   \"apps\" : [{\n      \"name\" : \"HTTP-API\",\n      \"script\" : \"http.js\"\n   }],\n   \"deploy\" : {\n     // \"production\" 是环境变量名\n     \"production\" : {\n       \"user\" : \"ubuntu\",\n       \"host\" : [\"192.168.0.13\"],\n       \"ref\"  : \"origin/master\",\n       \"repo\" : \"git@github.com:Username/repository.git\",\n       \"path\" : \"/var/www/my-repository\",\n       \"post-deploy\" : \"npm install; grunt dist\"\n      },\n   }\n}\n```\n\n/bin/bash:\n```\n# 部署到远程服务\n$ pm2 deploy production setup\n\n# 更新远程版本\n$ pm2 deploy production update\n\n# 回滚到上一版本\n$ pm2 deploy production revert 1\n\n# 在远程机器上执行命令\n$ pm2 deploy production exec \"pm2 reload all\"\n```\n\n### Complete tutorial\n\n1- 生成一个样本ecosystem.json列出进程和部署环境的文件。\n\n`pm2 ecosystem`\n\n在当前文件夹会创建一个`ecosystem.json`文件:\n```\n{\n  // Applications part\n  \"apps\" : [{\n    \"name\"      : \"API\",\n    \"script\"    : \"app.js\",\n    \"env\": {\n      \"COMMON_VARIABLE\": \"true\"\n    },\n    // Environment variables injected when starting with --env production\n    // http://pm2.keymetrics.io/docs/usage/application-declaration/#switching-to-different-environments\n    \"env_production\" : {\n      \"NODE_ENV\": \"production\"\n    }\n  },{\n    \"name\"      : \"WEB\",\n    \"script\"    : \"web.js\"\n  }],\n  // 部署部分\n  // Here you describe each environment\n  \"deploy\" : {\n    \"production\" : {\n      \"user\" : \"node\",\n      // 服务器集群\n      \"host\" : [\"212.83.163.1\", \"212.83.163.2\", \"212.83.163.3\"],\n      // 分支\n      \"ref\"  : \"origin/master\",\n      // Git 地址\n      \"repo\" : \"git@github.com:repo.git\",\n      // 应用在服务器上的地址\n      \"path\" : \"/var/www/production\",\n      // Can be used to give options in the format used in the configura-\n      // tion file.  This is useful for specifying options for which there\n      // is no separate command-line flag, see 'man ssh'\n      // can be either a single string or an array of strings\n      \"ssh_options\": \"StrictHostKeyChecking=no\",\n      // To prepare the host by installing required software (eg: git)\n      // even before the setup process starts\n      // can be multiple commands separated by the character \";\"\n      // or path to a script on your local machine\n      \"pre-setup\" : \"apt-get install git\",\n      // Commands / path to a script on the host machine\n      // This will be executed on the host after cloning the repository\n      // eg: placing configurations in the shared dir etc\n      \"post-setup\": \"ls -la\",\n      // Commands to execute locally (on the same machine you deploy things)\n      // Can be multiple commands separated by the character \";\"\n      \"pre-deploy-local\" : \"echo 'This is a local executed command'\"\n      // Commands to be executed on the server after the repo has been cloned\n      \"post-deploy\" : \"npm install \u0026\u0026 pm2 startOrRestart ecosystem.json --env production\"\n      // Environment variables that must be injected in all applications on this env\n      \"env\"  : {\n        \"NODE_ENV\": \"production\"\n      }\n    },\n    \"staging\" : {\n      \"user\" : \"node\",\n      \"host\" : \"212.83.163.1\",\n      \"ref\"  : \"origin/master\",\n      \"repo\" : \"git@github.com:repo.git\",\n      \"path\" : \"/var/www/development\",\n      \"ssh_options\": [\"StrictHostKeyChecking=no\", \"PasswordAuthentication=no\"],\n      \"post-deploy\" : \"pm2 startOrRestart ecosystem.json --env dev\",\n      \"env\"  : {\n        \"NODE_ENV\": \"staging\"\n      }\n    }\n  }\n}\n```\n\nEdit the file according to your needs.\n\n2- 确保您的本地机器上有ssh公钥\n```\nssh-keygen -t rsa\nssh-copy-id node@myserver.com\n```\n\nIf you encounter any errors, please refer to the troubleshooting section below.\n\n3- 初始化远程项目:\n\n`pm2 deploy \u003cconfiguration_file\u003e \u003cenvironment\u003e setup`\n\n例如:\n\n`pm2 deploy ecosystem.json production setup`\n\n这个命令会在远程服务上创建文件夹。\n\n4- 部署代码\n\n`pm2 deploy ecosystem.json production`\n\nNow your code will be populated, installed and started with PM2.\n\n### 生态系统文件参考\n\n生态系统文件的目的是收集应用所有的配置选项和环境变量。\n\n### 部署选项\n\n选项名称|描述|类型|默认\n---|---|---|---\n`key`|`SSH`密钥的路径|`String`|`$HOME/.ssh`\n`user`|`SSH`用户|`String`|\n`host`|`SSH`主机|`[String]`|\n`ssh_options`|`SSH`选项，不包括命令行标志，查看`man ssh`|`String`，`[String]`|\n`ref`|`GIT`的`remote/branch`|`String`|\n`repo`|`GIT`的`remote`|`String`|\n`path`|服务器中的路径|`String`|\n`pre-setup`|1.远程机器拉代码之前|`String`|\n`post-setup`|2.远程服务器拉代码|`String`|\n`pre-deploy-local`|3.post-deploy前在宿主机上执行的命令|`String`|\n`post-deploy`|4.部署后执行|`String`|\n\n## SCP发布\nscp发布是较为常用的发布方式，但朱雀使用的是rsync发布，主要是利用其增量同步功能，加速代码同步。\n\n### 发布流程\n推荐的做法是在发布机上拉代码，编译。\n同步代码到远程应用服务器，重启。\n也就是说远程应用服务只需重启即可，不需要做编译操作，在发布机上编译即可。\n\n### 配置说明\n```js\n{\n      \"user\": \"root\",\n      \"host\": [\"10.11.12.13\"],\n      \"ref\":\"master\",\n      \"repo\": \"git@github.com/yuedun/zhuque.git\",\n      \"path\": \"/data/www/zhuque\",\n      \"preBuild\" : \"\",\n      \"build\":\"go build\",\n      \"preDeploy\" : \"echo '发布前置';\",\n      \"postDeploy\" : \"pm2 restart zheque;pm2 ls\",\n      \"rsyncArgs\":\"-u --delete --exclude '.git' --exclude '.env'\"\n}\n```\n\n\n- user：用户名\n- host[]：主机地址\n- ref：分支\n- repo：仓库地址\n- path：项目部署路径，需要包含项目目录\n- preBuild：编译前置，在发布机上编译代码设置的环境变量，比如前端项目设置不同的环境变量使用不同的接口地址。\n- build：编译命令，例如：npm run build\n- preDeploy：发布前置，应用服务重启前设置环境变量等操作。\n- postDeploy：发布命令，例如：pm2 reload zhuque\n- rsyncArgs：rsync参数\n\n常用rsync参数：\n- --exclude 排除不进行同步的文件，比如--exclude=\"*.iso\"\n- --delete参数删除只存在于目标目录、不存在于源目标的文件，即保证目标目录是源目标的镜像。\n如果想要排除指定的文件，即不删除某个文件，可以使用exclude指定，例如：--exclude '.env'，会删除其他文件而不会删除.env文件。\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuedun%2Fzhuque","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuedun%2Fzhuque","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuedun%2Fzhuque/lists"}