I'm suggest we can use Rocketeer for this case.
Here is Rocketeer
tree on my Jenkins Server for NodeJS App
$ tree .rocketeer/
.rocketeer/
├── config.php
├── hooks.php
├── logs
│ ├── develop--20170613.log
│ ├── develop--20170614.log
│ ├── develop--20170616.log
│ ├── staging--20180323.log
│ ├── staging--20180324.log
│ ├── staging--20180326.log
│ ├── production--20180223.log
│ ├── production--20180226.log
│ ├── production--20180227.log
│ ├── production--20180227.log
│ └── custom-environment--20180328.log
├── paths.php
├── remote.php
├── scm.php
├── stages.php
└── strategies.php
- You can manage remote environment of NodeJS App: Develop, Staging, Production (at
config.php
file)
- It's will pull newest source code on your Gitlab and keep releases version like
Capistrano
(at remote.php
file)
- It's can run your
pm2 command line
after deployed newest source code (at hooks.php
file)
- It's already help run
npm install
NodeJS packages.
So here is my Jenkins Job setting:
Source Code Management
Build Triggers
Build
#!/bin/bash -el
cd $JENKINS_HOME/app-deploy/app-socketio
rocketeer deploy --on="develop"
develop mean connect to Develop Remote Server (at .rocketeer\config.php
file)
'connections' => [
'develop' => [
'host' => '35.xx.xx.xx',
'username' => 'ec2-user',
'password' => '',
'key' => '/var/lib/jenkins/.ssh/foo.pem',
'keyphrase' => '',
'agent' => '',
'db_role' => true,
],
'staging' => [
'host' => '34.xx.xx.xx',
'username' => 'ec2-user',
'password' => '',
'key' => '/var/lib/jenkins/.ssh/bar.pem',
'keyphrase' => '',
'agent' => '',
'db_role' => true,
],
'production' => [
'host' => '18.xx.xx.xx:63612',
'username' => 'ec2-user',
'password' => '',
'key' => '/var/lib/jenkins/.ssh/woot.pem',
'keyphrase' => '',
'agent' => '',
'db_role' => true,
],
'custom-environment' => [
'host' => '13.xx.xx.xx:63612',
'username' => 'ec2-user',
'password' => '',
'key' => '/var/lib/jenkins/.ssh/test.pem',
'keyphrase' => '',
'agent' => '',
'db_role' => true,
],
],
And run pm2
command line configure at hooks.php
file
'after' => [
'setup' => [],
'deploy' => [
"pm2 delete mynodeproj", //Delete old pm2 task
"pm2 start src/mynodeproj.js", //Start new mynodeproj
],
'cleanup' => [],
],
Hope this can help you!!
bounty
– Quynh Nguyen