1
用 Docker 改善團隊合作模式Bo-Yi Wu
2016.07.05
2
關於我• 聯發科技工程師• Node.js• PHP• Golang• DevOps
https://blog.wu-boy.com/
DevOps開發與維運
環境建置
3
Embedded SystemBSP
(Board Support Package)
4
Porting
BuildPorting
Build
5
6
Docker 還沒出來以前
7
需要建置一台 Build Server
8
各專案所需要的工具不同gcc version
5.x
4.x
3.x 9
10
各專案所需要的作業系統不同Ubuntu version
12.04
14.04
15.04 11
12
不同作業系統不同套件管理
14.04
15.0413
傳統架構缺陷• 維護成本提高 ( 機器硬體維修汰換 )• 建置機器複雜 ( 雖然有寫 Shell Script)• 24 小時 on call ( 公司隨時都有人加班 )• 系統資源常常不夠
14
15
換另一種架構 ( 省錢 )
16
沒有共同的 Build Server
14.04
15.0417
18
各專案維護 .vdi 檔案
19
缺陷• 吃個人系統記憶體資源• 切換多重專案浪費時間• 浪費個人電腦硬碟空間• 更新 vdi 檔案後,團隊全部要重抓
20
Docker 改變了生態
21
Docker 今年三歲正式宣布支援 Mac 及 Windows
22
Dockerfile
Dockerfile
23
優勢• 不需要額外的機器及人力維護成本• 各專案維護 Dockerfile ( 可進行版本控
制 )• 任何作業系統都可執行 ( 不需要
VirtualBox)
24
來看 linkit smart 7688 開發版
25
26
linkit-smart-7688-golanghttps://github.com/appleboy/linkit-smart-7688-golang
docker build –t 7688:v1 .
27
28
程式開發frontend vs. backend
Single Page Application
29http://blog.opus.com.pk/2015/09/04/importance-of-backend-developer/
30
VS.
31
開發環境部署傳統前後端合作模式
32
Develop Server(API)
Backend Developer
Backend Developer
Backend Developer
Frontend Developer
Frontend Developer
QA Engineer
Deploy
Deploy
DeployTesting
API
API
33
如何部署 Develop Server
34
Develop
Commit
Testing
Deploy
單一環境部署
35
多重環境部署
Develop Branch
Staging Branch
Production Branch
36
缺陷• 團隊非常依賴開發環境• 不管前端後端都需要互相等待• QA 需要等待前後端完成才可測試• 多重分支讓開發者非常困擾• 多一種環境伺服器成本提高• 想搶先看其他 feature 分支功能呢?
37
如何用 Docker 改善合作模式
用 Docker 取代團隊開發環境
docker-compose.yml38
39
個人開發環境
docker-compose.ymlRD
QA
PM
40
團隊成員必學
QA, PM, Sales, RD
41
Git
• 如何更新程式– $ git pull origin master
• 如何切換分支– $ git checkout –b xx origin/feature-xx
42
Docker• 啟動 Service– $ docker-compose -p $(PROJECT) up –d
• 關閉 Service– $ docker-compose -p $(PROJECT) stop
• 移除 Service– $ docker-compose -p $(PROJECT) down
43
優勢• 大家都是獨立運作,互不影響• 減少 Develop 環境建置• 降低建置環境門檻• 可以到處 Demo• QA 可以隨時進行測試
44
獨立運作
全部服務都跑在 localhost 127.0.0.1
QA RD PM
45
減少 Develop 環境建置
Staging Branch
Production Branch
從三種環境建置變成兩種 (Staging, Production)
46
降低建置環境門檻
一行指令搞定環境部署docker-compose up -d
47在客戶面前不怕 Demo 失敗
48
QA 可以隨時進行測試
Feature
Bugs
Success
Fail
透過 git checkout origin/xxxx 測試功能
49
用 Docker 跑測試
50
Docker + JenkinsNode.js
51
API Server
OAuth Server
npm install && npm test
Node.js Testing
52
Postgres is not startedDocker 執行後
務必等相關 Container 啟動完成
53https://blog.wu-boy.com/2016/06/server-monitoring-mysql-postgres-daemon-in-docker/
54
55
Node.js Testing 問題測試時間太長
56
npm install 太慢用一行指令改善套件安裝速度
2 min -> 30 sec
57
一行指令• tar xf ../module_cache.tar • npm prune• npm install• tar cf ../module_cache.tar
node_modules
58
Build
Docker start
npm install
Database migration
npm test
Coverage
Docker stop
Deploy
59
60
61
從圖像可以觀察每個 build 及 testing time
62
軟體開發流程Git flow vs Github flow
可以從分支數量來區分
63
影響團隊部署還流程Git flow vs Github flow
64
65
Git flow 部署流程 ( 用分支 )
Staging
production
66
Github flow (Master + Tag)
Master
Tag: v1.0, v2.0
67
Git tips and flowhttp://www.slideshare.net/appleboy/git-flow-61442567
68
找出一個方法適合團隊Git flow vs Github flow
69
CI Server?
70
Docker 基礎介紹與實戰http://www.slideshare.net/appleboy/docker-
61214768
71
Any Question?