A previous article about the use of Git hook deployment application, hook method has a flaw is to go to the server every time to modify the hook corresponding configuration file, this profile is separated from the current warehouse, debugging will have some trouble, With the help of a Ruby deployment tool, Mina can quickly deploy NODEJS applications on the server.
Install Mina
Copy Code code as follows:
After installation, it requires a configuration file, which by default is the current directory config/deploy.rb
Simple configuration
Copy Code code as follows:
Require ' mina/git '
Require ' Mina/bundler '
Set:d omain, ' your.server.com '
Set:user, ' Flipstack '
Set:repository, ' Flipstack '
Task:d Eploy do
Deploy do
# preparations here
Invoke: ' Git:clone '
Invoke: ' Bundle:install '
End
End
Task:restart do
Queue ' sudo service restart Apache '
End
Run
Before the formal deploy, you typically need to prepare directories that you can set up by using Mina Setup, which, by default, creates the following directory structure on the specified server
Copy Code code as follows:
.
├──releases released version
└──shared Here you can put a common file, such as Node_modules
Run Mina deploy it executes the commands specified in task deploy, such as the above:
1. Log on to the server
2.git Clone to SCM directory
3. Create a build-xxxxx directory in the TMP directory, and then start executing bundle install
4. Create a release version directory in releases and move the contents of build-xxxxx
5. Soft link current to just the version number directory
Nodejs Application Publishing Example
Copy Code code as follows:
Require ' mina/git '
Set:term_mode, Nil
# Here's the IP of a virtual machine
Set:d omain, ' 192.168.56.101 '
# Log in to the user name of the machine
Set:user, ' Test ' # Username in the server to SSH to.
# published Directory
Set:d eploy_to, '/home/test/doitnow '
# The Git warehouse address released
Set:repository, ' Ssh://jb51.net@192.168.56.1/users/jb51.net/works/doitnow '
# The Git branch released
Set:branch, ' master '
# set up a directory that requires soft links
# Soft Link Node_modules to prevent a lot of time spent on NPM install every time
set:shared_paths, [' Log ', ' tmp ', ' node_modules ']
# This uses forever to manage the node process and is also recommended for use with PM2
Set:forever, "#{deploy_to}/shared/node_modules/forever/bin/forever."
# Create a directory when initializing, assign directory permissions
Task:setup do
Queue "Mkdir-p #{deploy_to}/shared/log"
Queue "chmod g+rx,u+rwx #{deploy_to}/shared/log"
Queue "Mkdir-p #{deploy_to}/shared/node_modules"
Queue "chmod g+rx,u+rwx #{deploy_to}/shared/node_modules"
End
Desc "Deploys the current version to the server."
Task:d Eploy do
Deploy do
Invoke: ' Git:clone '
# link Directory
Invoke: ' Deploy:link_shared_paths '
# Install Module
# The compilation of static resources can be put into the Package.json {scripts:{install: ' xxxxx '}}
Queue "NPM Install"
To:launch do
# Restart Application
Queue "Node_env=production #{forever} stopall"
# Pay attention to the log in shared
Queue "Node_env=production #{forever} start-o #{deploy_to}/shared/log/output.log-e #{deploy_to}/shared/log/ Error.log-a App.js "
End
End
End
Source: http://jser.me