Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

1,004 views

Published on

2016 CTJS conf 簡報,說明如何為 nodejs 專案建構持續整合流程

Published in: Software
  • Be the first to comment

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

  1. 1. NODE.JS 
 CT
  2. 2. SPOOKY
 trunk.studio trunk.studio/blog
  3. 3.
  4. 4.
  5. 5.
  6. 6. • • Continuous Integration •
  7. 7. = /
  8. 8. = /
  9. 9. DevOps
  10. 10. = /
  11. 11. Continuous Improvement
  12. 12. 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); }, };
  13. 13. 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
  14. 14. Edge of Tomorrow
  15. 15. 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
  16. 16. "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
  17. 17. 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
  18. 18. Jenkins 2 
 Pipeline
  19. 19. 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']) }
  20. 20. 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" }
  21. 21. CI / CD 有效溝通 累積開發能量 快速迭代驗證 永生
  22. 22. Checking
  23. 23. 
 Cobertura
  24. 24. Integration
  25. 25. Pipeline
  26. 26. Pull Request
  27. 27. Connects
  28. 28. Slack + Github + Jenkins
  29. 29. &

×