0501n sytem 1 google otros productos o

25
Node.JS Website Deployment pH200 Software Developer @ Cytisan Software

description

e este manual describe los factores ms importantes que influyen sobre la poscosecha de las flores cortadas y otros productos ornamentales. La segunda delinea las tcnicas aplicables al manejo comercial de la mayora de las flores, incluyendo sugerencias para mejorar el manejo actual de la poscosecha. Poscosecha de las flores cortadasManejo y recomendaciones 6 La informacin que se presenta se

Transcript of 0501n sytem 1 google otros productos o

Page 1: 0501n sytem 1 google  otros productos o

Node.JS Website

DeploymentpH200

Software Developer @ Cytisan Software

Page 2: 0501n sytem 1 google  otros productos o

今天我們可以學到

• 如何把做好的node.js website放到自己的server上跑

• 而且是用git deploy

Page 3: 0501n sytem 1 google  otros productos o

me

• 第一台筆電是iBook G4

• 雖輾轉學過各種語言但樣樣不精,最後覺得C#還不賴,一年前開始研究JS

• 開了間小公司弄些Windows的App

• 把公司網站擺在Heroku (node)的免費quota下白吃白喝

• 因為用node擺網站也就順理成章開始學習node環境

Page 4: 0501n sytem 1 google  otros productos o

Cloud Computing

Page 5: 0501n sytem 1 google  otros productos o

PaaS

• 這些服務很好• 但不是今天的重點

Page 6: 0501n sytem 1 google  otros productos o

IaaS, VPS, etc.

Page 7: 0501n sytem 1 google  otros productos o

Deploy node.js app 到自己的機器

• 今天的重點

Page 8: 0501n sytem 1 google  otros productos o

啊不是複製貼上就好了嗎?

Page 9: 0501n sytem 1 google  otros productos o

啊不是複製貼上就好了嗎?

• 其實我覺得也可以

• 整合 version control (push deploy, rollback)

• Start, stop and monitor

• 自動化

Page 10: 0501n sytem 1 google  otros productos o

Let’s 複製貼上

• rsync

• rsync -arzve ssh username@host:path source

• 更新:ssh進去,stop,start node

• 當然可以寫成shell script

• 人有失手馬有亂蹄

Page 11: 0501n sytem 1 google  otros productos o

Forever

• https://github.com/nodejitsu/forever

• Nodejitsu出品

• 已經有hosting platform實際使用

• npm install -g forever

• 讓你的node application永不停止

• 記住你的env variables

Page 12: 0501n sytem 1 google  otros productos o

Git Deployment

• 手動Heroku式Deploy

• 設定有點煩,但一勞永逸

1. ssh進server

2. git init --bare

3. vim hooks/post-receive

4. chmod +x hooks/post-receive

Page 13: 0501n sytem 1 google  otros productos o

post-receive example

#!/bin/bash

APP=~/repos/app/app.js

export GIT_WORK_TREE=~/repos/app

git checkout -f

pushd $GIT_WORK_TREE

npm install

forever restart $APP

popd

Page 14: 0501n sytem 1 google  otros productos o

Step by Step

• 範例前置設定:• Local Repository名稱為nodeweb

• Remote IP為5.5.6.6

• Remote User為webadmin

• 把Remote Repository放在/home/webadmin/nodeweb.git

• Remote端已安裝forever (npm install -g forever)

Page 15: 0501n sytem 1 google  otros productos o

設定Git

1. 在local端做好git repository (git init)

2. ssh [email protected]

3. git init --bare nodeweb.git

(註:新增在/home/webadmin/nodeweb.git)

4. cd nodeweb.git/hooks

5. vim post-receive

Page 16: 0501n sytem 1 google  otros productos o

設定Git(post-receive內容)

6. #!/bin/bash

APP=~/nodeweb/app.js

export GIT_WORK_TREE=~/nodeweb

git checkout -f

pushd $GIT_WORK_TREE

npm install --production

forever restart $APP

popd

Page 17: 0501n sytem 1 google  otros productos o

設定Git(遠端)

7. chmod +x post-receive

8. mkdir ~/nodeweb

9. 遠端設定完成,回到本機

Page 18: 0501n sytem 1 google  otros productos o

設定Git

(在自己的工作用git repository)

1. git remote add cloud-deploy

[email protected]:/home/webadmin/nodeweb.git

2. 設定完成

Page 19: 0501n sytem 1 google  otros productos o

Git Deploy(第一次)

1. git push cloud-deploy master

2. ssh [email protected] "forever start ~/nodeweb/app.js"

3. 網站上線

Page 20: 0501n sytem 1 google  otros productos o

Git Deploy(之後每一次)

1. git push cloud-deploy master

2. 網站會自動restart update

Page 21: 0501n sytem 1 google  otros productos o

How about Windows?

Page 22: 0501n sytem 1 google  otros productos o

Windows (正經)

• IIS

• iisnode (強力推薦)https://github.com/tjanczuk/iisnode

• Windows Azure

• AppHarbor

• Hyper-V + Linux (CentOS, Ubuntu >=12)

Page 23: 0501n sytem 1 google  otros productos o

Uptime 監控

• https://github.com/fzaninotto/uptime

Page 24: 0501n sytem 1 google  otros productos o

延伸閱讀

• 管理你的processhttp://upstart.ubuntu.com/

• 網路上的文章談git deployhttp://sebduggan.com/blog/deploy-your-website-changes-using-git/

• Nodejistu Blog介紹Foreverhttp://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever

• 設定ssh key loginhttp://www.linuxproblem.org/art_9.html

• 設定git serverhttp://git-scm.com/book/en/Git-on-the-Server-Setting-Up-the-Server

Page 25: 0501n sytem 1 google  otros productos o

Questions?

twitter: pH_minamo (可叫我200 or pH)

Node.js 台灣 Facebook Group:http://www.facebook.com/groups/node.js.tw/