See a lot of automated construction schemes on the Internet, such as Jenkins, GitLab CI. The downside of this approach is that it requires compilation and packaging on the server, takes up server resources, and is less scalable, which is still quite inconvenient. Therefore, according to the needs of his own project, the author studied a set of CI tools with high extensibility.

First, the overall idea

We need to implement a tool that performs the following steps when a user enters a build command at a terminal

  1. Select sites such as project A and project B
  2. Clone project from remote to local (get the maximum disk space on the local, create/buildService /gitroot/A project. Git,)
  3. Select the branch to publish example :bugA branch
  4. -npm install package -npm run build (depending on the project)
  5. Use SSH to log in to the remote server
  6. Convert the selected bugA score to pinyin style as a secondary domain name, and bind the matching domain name that Nginx ubiquitously resolves to a subdirectory configuration

Buga. cloudrd.cn accesses the bugA branch, and bugb.cloudrd. cn accesses the bugB branch

  1. Disconnect the remote server

2. Technology stack

  • Making the address
  • nodegitUse the API provided by Git.
  • node-sshLog in to the remote server using SSH.
  • shelljsThe child_process child process module has been repackaged to make invoking system commands easier.
  • diskinfoDisk information tool.
  • pinyinConvert Chinese characters to pinyin.
  • inquirerCommand line interaction.
  • chalkBeautify the command line, color it, etc.
  • oraLoading effect of the command line environment.

Third, tool related

├ ─ config | └ index. Js - SSH configuration, site configuration ├ ─ utils | ├ ─ build. Js initialization -- -- -- -- -- the site directory, download the dependent and packaging methods such as | ├ ─ command. The js -- -- -- -- -- | about some command line operation method ├ ─ disk. Js - disk information | ├ ─ git. Js -- -- -- -- -- based on nodegit encapsulated git class | ├ ─ the js - logs | ├ ─ node_app. Js -- -- -- -- - | nodefs module encapsulation based method ├─ ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txt ├─ download.txtCopy the code

4. Diagram the general process

V. How to configure the project

It’s as simple as configuring some SSH addresses, user names, passwords, your project address, and installation dependencies and packaging commands

// config>index.js
module.exports = Object.freeze({
  SERVER_PATH: "".// SSH address Server address
  SSH_USER: "".// SSH user name
  PASSWORD: "".// Connect to the server with the password
  PATH: "/data/www".// Address of the server directory to be uploaded, such as /data/ WWW /
  APPLICATION_PORTAL: "/buildservice/gitroot".SITE_DATA: [{name: "buildservice1".value: "http://49.234.49.103:9090/root/buildservice1.git".install: "npm install".build: "npm run build"}, {name: "buildservice2".value: "http://49.234.49.103:9090/root/buildservice2.git".install: "npm install".// Download dependencies
      build: "npm run build".// Package the project},].// Set your own site information
});
Copy the code

To publish your site, run node app.js in the root directory of your project

~ See step 4 for details

Seven,

The benefits of this tool is that you can out of the box, no configuration in your project seven or eight bananas, just use your hands to your project address configuration that can be deployed, expanding or higher, such as enterprise can realize, of course, can according to your actual application ideas and the corresponding requirements to a certain extend.

If you want to deploy on a Windows server, you may need to use MSDeploy+IIS to implement this feature.

If you think it will help you a little bit, just like or star on GitHub, thank you very much

The author’s contact information: QQ573432332, wechat :DK573432332

What questions are welcome to harass ~