Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
NODE.JS 

CT
SPOOKY

trunk.studio
trunk.studio/blog
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
•
•
•
•
• Continuous Integration
•
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
= /
= /
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
DevOps
= /
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
Continuous
Improvement
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
Sequelize
module.exports = {
attributes: {
username: {
type: Sequelize.STRING,
allowNull: false
},
email: {
type: Sequelize.STRING,
allowNull: false
},
age: {
type: Sequelize.INTEGER
}
},
associations: function() {
User.hasMany(Post);
User.hasMany(Passport);
},
};
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
FROM mhart/alpine-node:4
RUN apk add --update git
RUN apk add --update build-base libffi-dev ruby ruby-dev 
&& gem install sass compass --no-ri --no-rdoc 
&& apk del build-base libffi-dev ruby-dev 
&& rm -rf /var/cache/apk/*
Dockerfile
Edge of Tomorrow
it('register user should success.', async (done) => {
try {
let newUser = {
username: 'newUser',
email: 'newUser@gmail.com',
password: 'newUser'
}
let result = await request(sails.hooks.http.app)
.post('/auth/local/register').send(newUser);
let {email} = newUser;
let checkUser = await User.findOne({
where: {email}, include: Passport}
);
checkUser.email.should.be.equal(newUser.email);
result.status.should.be.equal(302);
result.headers.location.should.be.equal('/');
done();
} catch (e) {
done(e);
}
});
Mocha
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
"scripts": {
"debug": "node debug app.js",
"test": "grunt test",
"test-junit": "mocha test --reporter mocha-junit-reporter",
"build": "npm i && node_modules/grunt-cli/bin/grunt build",
"start": "node app.js",
"pm2-start": "pm2 start -f app.js --name 'sailsSample'",
"pm2-stop": "pm2 stop sailsSample",
"start-prod": "NODE_ENV=production node app.js",
"build-prod": "grunt prod",
"build-docker-env": "docker build -t agileworks/sails_sample_env dockers/node",
"build-docker-prod-image": "docker build -t agileworks/sails_sample_prod .",
}
Package.json
deploy-production-docker:
- ssh jenkins@localhost docker rm -f sails_sample_prod
ssh jenkins@localhost docker run -d --name sails_sample_prod -p 8800:1337
agileworks/sails_sample_prod
deploy-production-legacy:
ssh jenkins@localhost mkdir -p ~/deploy/production
scp sailsSampleProd.tar.gz jenkins@localhost:~/deploy/production
tar -C ~/deploy/production/ -vxf ~/deploy/production/
sailsSampleProd.tar.gz
package-production:
- rm sailsSampleProd.tar.gz
tar cvf ./sailsSampleProd.tar.gz ./
restart-production:
- ssh jenkins@localhost cd ~/deploy/production && pm2 delete production
ssh jenkins@localhost cd ~/deploy/production && NODE_ENV=production pm2
start -f app.js --name 'production'
Makefile
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
Jenkins 2 

Pipeline
node {
stage 'checkout project'
git url: 'https://github.com/TrunkWorkshop/sailsSample.git'
stage 'check env'
sh "node -v"
stage 'install pm2'
sh "npm install pm2 -g"
stage 'build project'
sh "npm install"
stage 'test project'
sh "npm run test-junit"
step([$class: 'JUnitResultArchiver',
testResults: 'test-results.xml'])
}
node {
stage 'run project'
sh "npm run pm2-start"
try{
stage 'Approve, go production'
def url = 'http://localhost:1337/'
input message: "$url look good? ", ok: "Deploy to production"
}finally{
sh "npm run pm2-stop"
}
stage 'package production'
sh "make package-production"
step([$class: 'ArtifactArchiver', artifacts: 'prod.tar.gz'])
stage 'deploy production'
sh "make deploy-production-legacy"
stage 'restart production'
sh "make restart-production"
}
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
CI / CD
有效溝通
累積開發能量
快速迭代驗證
永生
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
Checking
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測


Cobertura
Integration
Pipeline
Pull Request
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
Connects
Slack + Github + Jenkins
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測
&

More Related Content

為 Node.js 專案打造專屬管家進行開發流程整合及健康檢測

  • 4.
  • 5.
  • 6.
  • 13. = /
  • 14. = /
  • 17. = /
  • 24. Sequelize module.exports = { attributes: { username: { type: Sequelize.STRING, allowNull: false }, email: { type: Sequelize.STRING, allowNull: false }, age: { type: Sequelize.INTEGER } }, associations: function() { User.hasMany(Post); User.hasMany(Passport); }, };
  • 26. FROM mhart/alpine-node:4 RUN apk add --update git RUN apk add --update build-base libffi-dev ruby ruby-dev && gem install sass compass --no-ri --no-rdoc && apk del build-base libffi-dev ruby-dev && rm -rf /var/cache/apk/* Dockerfile
  • 28. it('register user should success.', async (done) => { try { let newUser = { username: 'newUser', email: 'newUser@gmail.com', password: 'newUser' } let result = await request(sails.hooks.http.app) .post('/auth/local/register').send(newUser); let {email} = newUser; let checkUser = await User.findOne({ where: {email}, include: Passport} ); checkUser.email.should.be.equal(newUser.email); result.status.should.be.equal(302); result.headers.location.should.be.equal('/'); done(); } catch (e) { done(e); } }); Mocha
  • 30. "scripts": { "debug": "node debug app.js", "test": "grunt test", "test-junit": "mocha test --reporter mocha-junit-reporter", "build": "npm i && node_modules/grunt-cli/bin/grunt build", "start": "node app.js", "pm2-start": "pm2 start -f app.js --name 'sailsSample'", "pm2-stop": "pm2 stop sailsSample", "start-prod": "NODE_ENV=production node app.js", "build-prod": "grunt prod", "build-docker-env": "docker build -t agileworks/sails_sample_env dockers/node", "build-docker-prod-image": "docker build -t agileworks/sails_sample_prod .", } Package.json
  • 31. deploy-production-docker: - ssh jenkins@localhost docker rm -f sails_sample_prod ssh jenkins@localhost docker run -d --name sails_sample_prod -p 8800:1337 agileworks/sails_sample_prod deploy-production-legacy: ssh jenkins@localhost mkdir -p ~/deploy/production scp sailsSampleProd.tar.gz jenkins@localhost:~/deploy/production tar -C ~/deploy/production/ -vxf ~/deploy/production/ sailsSampleProd.tar.gz package-production: - rm sailsSampleProd.tar.gz tar cvf ./sailsSampleProd.tar.gz ./ restart-production: - ssh jenkins@localhost cd ~/deploy/production && pm2 delete production ssh jenkins@localhost cd ~/deploy/production && NODE_ENV=production pm2 start -f app.js --name 'production' Makefile
  • 34. node { stage 'checkout project' git url: 'https://github.com/TrunkWorkshop/sailsSample.git' stage 'check env' sh "node -v" stage 'install pm2' sh "npm install pm2 -g" stage 'build project' sh "npm install" stage 'test project' sh "npm run test-junit" step([$class: 'JUnitResultArchiver', testResults: 'test-results.xml']) }
  • 35. node { stage 'run project' sh "npm run pm2-start" try{ stage 'Approve, go production' def url = 'http://localhost:1337/' input message: "$url look good? ", ok: "Deploy to production" }finally{ sh "npm run pm2-stop" } stage 'package production' sh "make package-production" step([$class: 'ArtifactArchiver', artifacts: 'prod.tar.gz']) stage 'deploy production' sh "make deploy-production-legacy" stage 'restart production' sh "make restart-production" }
  • 48. Slack + Github + Jenkins
  • 53. &