`
sillycat
  • 浏览: 2551394 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

DevOps(9)Build the NodeJS Env

 
阅读更多
DevOps(9)Build the NodeJS Env
 
1. Memcached and Monitor
Command to start memcached
>memcached -d -m 50 -p 11211 -u carl -l 0.0.0.0
 
Install the Memcache-Top
Prepare the right directory
> mkdir /home/carl/tool/memcache-top-v0.6
> mkdir /home/carl/tool/memcache-top-v0.6/bin
> mv memcache-top-v0.6 /home/carl/tool/memcache-top-v0.6/bin/memcache-top
> chmod a+x /opt/memcache-top/bin/memcache-top
 
Start the Monitor Tool
> memcache-top --sleep 3 --instance ubuntu-dev1,ubuntu-dev2
 
The output will be as follow:
memcache-top v0.6 (default port: 11211, color: on, refresh: 3 seconds)

INSTANCE USAGE HIT % CONN TIME EVICT/s READ/s WRITE/s
ubuntu-dev1:11211 0.0%
0.0% 5 1.6ms 0.0 2 367
ubuntu-dev2:11211 0.0%
0.0% 5 1.5ms 0.0 2 367

AVERAGE: 0.0% 0.0% 5 1.6ms 0.0 2 367

TOTAL: 0B/ 0.1GB 10 3.1ms 0.0 4 733
(ctrl-c to quit.)
 
2. Prepare the NodeJS Env
follow
 
I was using version python 2.7.6 and node 0.10.28. I will try different this time on my local and VM.
> ./configure --prefix=/home/carl/tool/node-v0.12.0
make it and install that.
> node -v
v0.12.0
 
Install gulp
> sudo npm install -g gulp
 
or
 
> npm install --global gulp
 
> gulp -version
[13:31:35] CLI version 3.8.11
 
Install the NODEJS Plugin in jenkins
Install the GitHub Plugin in Jenkins
Install the  SSH plugin in Jenkins
 
3. Prepare deploy Env
 
> sudo apt-get install git
> npm install pm2 -g
> pm2 -v
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
0.12.7
 
gulp command to get the dist and deploy
>gulp serve
>gulp clean
>gulp dist
>gulp deploy
 
gulp config
/*jslint node: true */
'use strict';
 
//gulp & plugins
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var mocha = require('gulp-mocha');
var nodemon = require('gulp-nodemon');
var gutil = require('gulp-util');
var tar = require('gulp-tar');
var gzip = require('gulp-gzip');
var del = require('del');
var artifactoryUpload = require('gulp-artifactory-upload');
 
var project = {
name : ’sillycat-secure-proxy',
version : '1.0',
}
 
var artifactory = {
url : 'http://ubuntu-pilot:8080/artifactory/libs-release-local/',
username : 'deployer',
password : 'deployer',
path : ‘com/sillycat/sillycat-secure-proxy/'
}
 
var paths = {
main : 'app.js',
tests : 'test/**/*.js',
sources : [ '**/*.js', '!node_modules/**', '!gulpfile.js', '!dist/**'],
deploys : [ '**/*.*',
'!gulpfile.js',
'!package.json',
'!README.md',
'!dist/**',
'!test/**',
'!node_modules/gulp/**',
'!node_modules/gulp-*/**',
'!node_modules/del/**'],
};
 
gulp.task('clean', del.bind(null, ['dist']));
 
gulp.task('dist', function() {
gulp.src(paths.deploys)
.pipe(tar(project.name + '-' + project.version + '.tar'))
.pipe(gzip())
.pipe(gulp.dest('./dist/'));
});
 
gulp.task( 'deploy', function() {
return gulp.src('./dist/' + project.name + '-' + project.version + '.tar.gz')
.pipe( artifactoryUpload( {
url: artifactory.url + artifactory.path,
username: artifactory.username, // optional
password: artifactory.password, // optional,
rename: function( filename ) { return filename; } // optional
} ) )
.on('error', gutil.log);
} );
 
// lint all of our js source files
gulp.task('lint', function (){
return gulp.src(paths.sources)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
 
// run mocha tests
gulp.task('test', function (){
return gulp.src(paths.tests, {read: false})
.pipe(mocha({reporter: 'list'}))
.on('error', gutil.log);
});
 
//run app using nodemon
gulp.task('serve', [], function(){
return nodemon({
script: 'app.js',
watch : paths.sources
});
});
 
Package managed by npm
{
"devDependencies": {
"gulp": "^3.8.5",
"gulp-jshint": "^1.6.3",
"gulp-mocha" : "^1.1.1",
"gulp-nodemon" : "^1.0.4",
"gulp-util" : "^3.0.1",
"gulp-tar" : "^1.4.0",
"gulp-gzip" : "^1.0.0",
"del" : "^1.1.1",
"gulp-artifactory-upload" : "^1.1.0",
"express" : "^4.12.2"
},
"engines": {
"node": ">=0.11.0"
},
"private": true
}
 
Unzip the binary
>mkdir sillycat-secure-proxy-1.0
>tar zxvf sillycat-secure-proxy-1.0.tar.gz -C ./sillycat-secure-proxy-1.0
 
Deploy the binary
Download the binary from artifactory
>mkdir sillycat-secure-proxy-1.0
>tar zxvf sillycat-secure-proxy-1.0.tar.gz -C ./sillycat-secure-proxy-1.0
>pm2 start app.js --name sillycat-secure-proxy -i max
 
Stop the binary
>pm2 stop sillycat-secure-proxy
 
Restart the binary
>pm2 restart sillycat-secure-proxy
 
Watch all the node applications
>pm2 list
 
Jenkins can finish the deployer work
. ~/.profile
cd /opt/sillycat-secure-proxy
pm2 stop sillycat-secure-proxy
rm -fr *
wget --user=deployer --password=deployer http://ubuntu-pilot:8080/artifactory/libs-release-local/com/sillycat/sillycat-secure-proxy/sillycat-secure-proxy-1.0.tar.gz
tar zxf sillycat-secure-proxy-1.0.tar.gz
pm2 restart sillycat-secure-proxy
 
Or
 
. ~/.profile
cd /opt/sillycat-secure-proxy
pm2 delete sillycat-secure-proxy
rm -fr *
wget --user=deployer --password=deployer http://ubuntu-pilot:8080/artifactory/libs-release-local/com/sillycat/sillycat-secure-proxy/sillycat-secure-proxy-1.0.tar.gz
tar zxf sillycat-secure-proxy-1.0.tar.gz
pm2 start app.js --name sillycat-secure-proxy -i max
 
References:
 
 
Mongodb
 
gulp
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics