frontend-prod-docker-cli

Front-end lightweight deployment scaffolding, support testing, online and other multi-environment deployment, support environment configuration expansion, achieve a command to complete the entire deployment process, and support to update resources to docker and restart docker; Supports one-click deployment of multiple environments.

The original

The traditional packaging method for front-end or server development is to execute the packaging command after development: Java relies on the mavan package command MVN package-dmaven.test. skip=true go service package command go build demo

Then open SSH tool to connect to the server, upload the packaged application package to a location on the server through FTP or SSH tool, and then restart or reload. If docker is packaged, docker CP is also required… . Copy the file to the container and run the docker restart… ,docker commit container… , Docker push, etc. It is a hassle to perform these operations with each version update.

Why can’t this fixed process work be achieved directly using a scaffold? In fact, there are a lot of mature schemes in the industry, including gitLab + Git Hook + Jenkins and other schemes; But relatively small teams or there is no such a heavy environmental conditions to build team, do the things need to do too much maintenance and building work, the next inspired by vue – cli and a lot of front-end scaffolding, developed the humble small tool, can realize the working part of the routing, using a configuration, a line of command to update, Simplify the manual operation of developers, welcome everyone to use and issue, if you like, give a star to encourage, thank you!

Current CLI Functions

1. Front-end SPA single-page application packaging, server directly update deployment; Support for Docker updates;

2. The Node server is packaged and released, and the server is directly updated and deployed; Support for Docker updates;

3. Update multiple environments together; fe-deploy all

The premise condition

Prerequisites for using this scaffold: 1. Install Node V10.0.0 or above locally. 2. Connect to your server over SSH. 3. If only the front-end and Node are packed, no other environment is required. If the package is Java, you need to install JDK, JRE, mavan; If the go base environment is packaged, you need to install and install the GO base environment.

** Note: This scaffolding currently only supports developers to update services using **

The installation

1. The node version must be 10.0.0 or later. You can download and install nodeJS from https://nodejs.org/en/. Such as local development needs to use multiple versions of nodejs, may refer to my article NVM installation, more than the local version installed node and a key switch: https://juejin.cn/post/6844904007048118280). 2. Install frontend-prod-docker- CLI globally

npm i frontend-prod-docker-cli -g

Copy the code

Check the version

fe-deploy -V
Copy the code

use

1. Initialize the deployment template

The system automatically pulls the default configuration file from the repository and generates the frontend-prod-docker- CLI folder in the current directory. The prod.config.js folder is the corresponding configuration file

Execute the following command in the current project directory:

fe-deploy init
Copy the code

You can see the configuration file generated under the current project directory as follows:

2. Configure the deployment environment

The deployment configuration file is located in the prod.config.js folder frontend-prod-docker- CLI of the current project. The configuration file can contain multiple environment configurations

For details about the configuration, see configuration file notes. The prod106 name below is optional, and you can name it yourself (you can name it at the end of your server IP, no special characters, no numbers and no special character starts)

module.exports = {
 projectName: 'XXXX system'// Project name    script: 'npm run build', // Package the script (comment out, do not execute the command, directly upload)
// Configure as needed, such as prod106 (no special characters in key names, no numbers and special character starts)// Upload the server and use docker mode to deploy the restart configuration case prod106: {  name: 'prod106 environment'. host: '192.168.78.106'// Server address, XXX indicates the end of the manually entered IP addressPort: 22, // SSH port, usually 22 by default username: 'root'// User name for logging in to the server password: ' '// Enter the server login password distPath: 'dist', // The folder that needs to be uploaded to the server in the current project (there is no forward slash to identify the relative directory of the current project, if a forward slash is added, the complete local absolute path needs to be written) webDir: '/root/temp/messageRouteApp', // Package file upload server address (the distPath folder configured on the previous line will be uploaded to this location) dockerName: 'messageroute'// Docker name dockerWebDir: '/usr/app'// The location of the file in the container // lastCmd: 'pm2 restart app'// A custom command to be executed on the server after all actions are completed (optional) }, // If there are any additional circumstances, continue in a format similar to prod106} Copy the code

3. Deploy the environment

Configure prod.config.js and run it

Fe-deploy // You can view the deployment command and configuration fileFe-deploy 106 // Directly deploy the environment 106 (fe-deploy XXX indicates the key value of the environment in prod.config.js, "106" above)
Copy the code

Multi-environment Deployment

You can manually select multiple environments configured in the configuration file to deploy them at a time by running the following command:

Fe-deploy all // Select multiple environments to deploy multiple environments in one clickCopy the code
Ng31bR.png

Initial reference https://github.com/dadaiwei/fe-deploy-cli this system, and draw lessons from the vue – cli thinking is achieved, in this thank you!

We welcome your support, and we will continue to update and support more functions. If you have any suggestions for improvement, please read more. Welcome star!

The author blog

Can focus on the nuggets homepage: https://juejin.cn/post/6844904185918390279

Making address:

https://github.com/Joseph244/frontend-prod-docker-cli

NPM address:

https://www.npmjs.com/package/frontend-prod-docker-cli

This article is formatted using MDNICE