SlideShare una empresa de Scribd logo
1 de 43
Descargar para leer sin conexión
Continuous Delivery: automated 
testing, continuous integration 
and continuous deployment. 
持續發佈:利⽤用⾃自動化測試與持續 
集成來持續發佈⾼高品質的軟體 
Jimmy Lai 
2014.10.15 
! 
Jimmy Lai是⾃自然語⾔言處理與機器學習領域的 Python愛好者。 
更多他的分享: http://www.slideshare.net/jimmy_lai/
Outline 
1. 持續發佈的概念 
2. 持續發佈的⼯工具 
3. 以Python專案為範例建構部署流⽔水 
線 
2
Continuous Delivery 
持續發佈 
• 軟體發佈了才算做完了 
• 只有commit程式碼還不算完成 
• 提交程式碼到軟體發佈的過程必須完全⾃自動 
化 
• 可重複使⽤用的發佈與部署流程,以確保軟體 
品質 
• 程式碼與設定檔等產出必須要進⾏行版本控 
制,以便快速的追蹤與回復 
3
Version Control 
版本控制 
• 需要版本控制的項⺫⽬目 
• 原始碼 
• 套件相依管理 
• 系統參數設定 
• 主流⼯工具: Git 
4
Continuous Integration 
持續整合 
• 在合作開發的團隊中,持續地將每個⼈人的變 
更整合在⼀一起,越頻繁地整合就可以減少嚴 
重的衝突發⽣生 
• 要件: 
• 頻繁的commit原始碼 
• ⾃自動化的測試 
• 簡短的建置與測試週期,以及早獲得回饋 
• 主流⼯工具: Jenkins 
5
Testing 
測試 
• ⾃自動化測試 
• 單元測試: 針對function/class 
• 功能測試: 針對客⼾戶端需求 
• 系統整合測試: 針對⼦子系統的整合 
• 效能與覆載測試 
• 安全性測試 
• ⼿手動測試 
• 探索性測試、使⽤用者接受度測試 
• Python測試⼯工具: nosetests 
6
部署流⽔水線 
1. 建置與單元測試(當commit程式碼時) 
2. ⾃自動化的功能測試 
3. 使⽤用者接受度測試(測試⼯工程師) 
4. 發佈 
過程中有任何錯誤即⾃自動通知開發者, 
開發者應優先修復部署流⽔水線後再繼續 
開發新功能 
7
Git版本控制 
• 分散式版本控制 
• 每⼀一台機器都有⼯工作⺫⽬目錄和版本資料 
庫 
• 每⼀一台機器的版本資料庫都可以與任 
意機器同步 
• 開發時先對本地資料庫進⾏行commit, 
不需要網路連線 
http://git-scm.com/ 8
Git實務 
• ⼯工作⺫⽬目錄 <-> 暫存區 <-> 版本資料庫 
• ⼯工作⺫⽬目錄為某個版本分⽀支的狀態加上新的修改 
• git add: 將檔案當前的狀態加⼊入暫存區 
• git commit -m “commit message”: 將⺫⽬目前暫存區 
當中的所有檔案更改儲存到版本資料庫 
• git push origin master: 將當前分⽀支的本機更新推送 
到遠端(origin)版本資料庫的master分⽀支 
• git pull origin master: 將遠端(origin)版本資料庫的 
master分⽀支的更新下載到當前⼯工作⺫⽬目錄分⽀支 
http://git-scm.com/docs/gittutorial 9
Git Code Review 
• 透過Github的code review來確保軟體品質: 
1. git checkout -b branch: 在本地建⽴立分⽀支並切換到該分⽀支 
2. git commit: 在本地分⽀支提交變更 
3. git push origin branch_a: 將變更推送到Github 
4. 在Github建⽴立pull request 
5. Reviewer進⾏行審查 
6. 審查修改完善後將branch merge回master 
• master branch⽤用來發佈軟體,新的修改都先在其他分⽀支 
進⾏行,經過審查後才merge 
• Code Review有助於團隊成員互相學習並提⾼高程式碼品質 
http://nvie.com/posts/a-successful-git-branching-model/ 
10
Git Code Review 
Demo 
https://github.com/jimmylai/continuous_delivery_demo
Git Code Review 範例 
• 需求: 撰寫設定系統套件的Makefile, 
並進⾏行Code Review 
• 步驟: 
1. 於git建⽴立新分⽀支 
2. 在新分⽀支提交修改 
3. 更新到github後,建⽴立pull request 
4. Review確認後merge 
12
13 
Committed Changes 
Create a pull request
14 
Activity Stream
Post Review Message 
15
Update According to the Comments 
16 
Merge
17 
Merged
單元測試 
• 單元測試: 對程式碼單元(funtion, class)進 
⾏行撰寫測試案例 
• 被測試的程式碼必須要減少與其他程式碼 
的相依性才容易測試,通常可以透過適當 
的封裝函數來達成。必要時必須要利⽤用 
Mock技術來隔離相依性,例如呼叫資料 
庫連線、外部IO. 
• Python測試⼯工具nosetest 
18
Unit Test with 
nosetests 
https://github.com/jimmylai/continuous_delivery_demo/tree/ 
master/web/calculator
Unit Test with nosetests範例 
• 需求: 撰寫⼀一個函式,有兩個整數作為 
參數,回傳兩個參數相加之和 
• 步驟: 
1. 撰寫函式 
2. 利⽤用doctest做為說明及測試 
3. 撰寫測試函數 
20
Unit test with Nosetest 
doctest: 作為函式說明範例,也是單元測試 
21
將測試檔案以xxx_test.py命名, 測試函式以! 
test_xxx()命名, nosetests就會找出來執⾏行 
22
功能測試 
• 針對客⼾戶端要求的功能進⾏行驗證,測試 
的對象可能是由數個元件組成的系統 
• 針對不同界⾯面的系統需要使⽤用不同的⽅方 
式來測試,例如網⾴頁就必須以瀏覽器來 
測試才完整 
• 範例: 基於先前的add( ), 提供⼀一個⽤用來 
進⾏行加法RESTful API, 針對輸⼊入進⾏行檢 
查,計算後回傳結果 
23
Functional Test of 
RESTful API 
https://github.com/jimmylai/continuous_delivery_demo/tree/ 
master/functional_tests
Functional Test of RESTful API 
範例 
• 需求: 實作⼀一個Restful API, 透過HTTP GET 
輸⼊入兩個參數, 呼叫前⼀一範例的add( )進⾏行加 
總, 以json格式回傳結果 
• 步驟: 
1. 使⽤用Django rest framework撰寫API 
2. 驗證輸⼊入的兩個參數存在且為整數 
3. 將運算結果回傳 
4. 測試客⼾戶端送出HTTP GET request來 
進⾏行測試 
25
Django RESTful API - View 
26
functional test 
27
28 
start web server 
functional test 
test successfully
Jenkins 
• 廣受歡迎的持續整合軟體 
• 根據設定的條件(如提交程式碼時、定 
時排程)觸發建置,如建置發⽣生錯誤便 
⽴立即通知開發者,建置順利可繼續下⼀一 
階段建制或⾃自動發佈 
• 建置的結果報表以網⾴頁的⽅方式呈現 
• 建置的過程與產出皆有存檔,⽅方便回溯 
http://jenkins-ci.org/ 29
Unitest when Commits 
with Jenkins
Unitest when Commits with 
Jenkins範例 
• 需求:透過Jenkins Job, 當有新的程式 
碼被提交時, 便⾃自動運⾏行unit test, 輸出 
測試結果報表 
• 步驟: 
1. 設定Jenkins Job與Github的授權 
2. 設定當有新的change時, 由Github 
觸發Jenkins 
3. 設定測試結果報表資訊 
31
Github access with ssh key auth 
32
Jenkins settings 
build when new changes come in 
Github settings 
33
Unit test coverage 
Unit test report 
34
35
⾃自動部署 
• ⾃自動將建置好的軟體安裝與設定到不 
同的環境,進⾏行後續的測試、交付產 
品 
• 不同的環境可能有不同的系統相依套 
件、不同的設定 
• 設定檔與部署程式都應進⾏行版本控制 
36
Deploy after Unit Tests 
Success
Deploy after Unit Tests 
Success範例 
• 需求: 使⽤用Apache作為Web server, 設 
定Jenkins Job當unit test完成後, 發佈 
到Apache Server 
• 步驟: 
1. 準備Apache設定檔 
2. 準備deploy scripts 
3. 設定Jenkins job 
38
Apache Config 
39
Jenkins Setting 
40 
Deploy script
部署流⽔水線 
1. unittest: 由⼯工程師提交程式碼觸發 
2. deploy 
3. functional test 
4. release, … 
過程中有任何錯誤即⾃自動通知開發者, 
開發者應優先修復部署流⽔水線後再繼續 
開發新功能 
41
42
43

Más contenido relacionado

La actualidad más candente

DAE 新变化介绍
DAE 新变化介绍DAE 新变化介绍
DAE 新变化介绍Tianwei Liu
 
Deployment with Capistrano
Deployment with CapistranoDeployment with Capistrano
Deployment with Capistrano旭 張
 
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)JoXuZi
 
lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用hugo
 
Scrum gathering 2012 shanghai 精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 shanghai  精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)Scrum gathering 2012 shanghai  精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 shanghai 精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)LetAgileFly
 
NF core-workflow
NF core-workflow NF core-workflow
NF core-workflow ChenzheLuo
 
JCConf2016 Jenkins Pipeline
JCConf2016 Jenkins PipelineJCConf2016 Jenkins Pipeline
JCConf2016 Jenkins PipelineChing Yi Chan
 
快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)Will Huang
 
前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧Chu-Siang Lai
 
Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Shengyou Fan
 
從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用謝 宗穎
 
docker intro
docker introdocker intro
docker introkoji lin
 
基于OpenResty的百万级长连接推送
基于OpenResty的百万级长连接推送基于OpenResty的百万级长连接推送
基于OpenResty的百万级长连接推送OpenRestyCon
 
Apache Zookeeper 分布式服务框架
Apache Zookeeper 分布式服务框架Apache Zookeeper 分布式服务框架
Apache Zookeeper 分布式服务框架Cabin WJ
 
Laravel - 系統全攻略(續)
Laravel - 系統全攻略(續)Laravel - 系統全攻略(續)
Laravel - 系統全攻略(續)Vincent Chi
 
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊Miles Chou
 
現代 IT 人一定要知道的 Ansible 自動化組態技巧
現代 IT 人一定要知道的 Ansible 自動化組態技巧現代 IT 人一定要知道的 Ansible 自動化組態技巧
現代 IT 人一定要知道的 Ansible 自動化組態技巧Chu-Siang Lai
 

La actualidad más candente (20)

DAE 新变化介绍
DAE 新变化介绍DAE 新变化介绍
DAE 新变化介绍
 
Deployment with Capistrano
Deployment with CapistranoDeployment with Capistrano
Deployment with Capistrano
 
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 Shanghai_精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
 
Docker
DockerDocker
Docker
 
lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用lua & ngx_lua 的介绍与应用
lua & ngx_lua 的介绍与应用
 
Scrum gathering 2012 shanghai 精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 shanghai  精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)Scrum gathering 2012 shanghai  精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
Scrum gathering 2012 shanghai 精益与持续改进分会场演讲话题: 大型企业ci平台建设和实施分享(陈小光)
 
NF core-workflow
NF core-workflow NF core-workflow
NF core-workflow
 
JCConf2016 Jenkins Pipeline
JCConf2016 Jenkins PipelineJCConf2016 Jenkins Pipeline
JCConf2016 Jenkins Pipeline
 
快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)快速上手 Windows Containers 容器技術 (Docker Taipei)
快速上手 Windows Containers 容器技術 (Docker Taipei)
 
前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧
 
Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南
 
從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用從軟體開發角度
談 Docker 的應用
從軟體開發角度
談 Docker 的應用
 
docker intro
docker introdocker intro
docker intro
 
基于OpenResty的百万级长连接推送
基于OpenResty的百万级长连接推送基于OpenResty的百万级长连接推送
基于OpenResty的百万级长连接推送
 
Docker應用
Docker應用Docker應用
Docker應用
 
Ansible introduction
Ansible introductionAnsible introduction
Ansible introduction
 
Apache Zookeeper 分布式服务框架
Apache Zookeeper 分布式服务框架Apache Zookeeper 分布式服务框架
Apache Zookeeper 分布式服务框架
 
Laravel - 系統全攻略(續)
Laravel - 系統全攻略(續)Laravel - 系統全攻略(續)
Laravel - 系統全攻略(續)
 
Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊Rancher: 建立你的牧場艦隊
Rancher: 建立你的牧場艦隊
 
現代 IT 人一定要知道的 Ansible 自動化組態技巧
現代 IT 人一定要知道的 Ansible 自動化組態技巧現代 IT 人一定要知道的 Ansible 自動化組態技巧
現代 IT 人一定要知道的 Ansible 自動化組態技巧
 

Similar a Continuous Delivery: automated testing, continuous integration and continuous deployment.

Continuous integration
Continuous integrationContinuous integration
Continuous integrationnetdbncku
 
Git&Github Tutorial
Git&Github TutorialGit&Github Tutorial
Git&Github TutorialTing Wen Su
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作Bo-Yi Wu
 
把玩 Jenkins CI
把玩 Jenkins CI把玩 Jenkins CI
把玩 Jenkins CIHao Lee
 
使用 Pytest 進行單元測試 (PyCon TW 2021)
使用 Pytest 進行單元測試 (PyCon TW 2021)使用 Pytest 進行單元測試 (PyCon TW 2021)
使用 Pytest 進行單元測試 (PyCon TW 2021)Max Lai
 
Version control0221
Version control0221Version control0221
Version control0221jianhongciou
 
钱宝坤:多浏览器集成的JavaScript单元测试工具
钱宝坤:多浏览器集成的JavaScript单元测试工具钱宝坤:多浏览器集成的JavaScript单元测试工具
钱宝坤:多浏览器集成的JavaScript单元测试工具taobao.com
 
广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdf广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdfbj_qa
 
Foundation of software development 1
Foundation of software development 1Foundation of software development 1
Foundation of software development 1netdbncku
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛Edward Kuo
 
Bitbucket pipeline CI
Bitbucket pipeline CIBitbucket pipeline CI
Bitbucket pipeline CIZero Huang
 
該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?Andy Dai
 
持续交付最佳实践——百度技术沙龙201110
持续交付最佳实践——百度技术沙龙201110持续交付最佳实践——百度技术沙龙201110
持续交付最佳实践——百度技术沙龙201110Qiao Liang
 
Git Flow 管理
Git Flow 管理Git Flow 管理
Git Flow 管理Pu Lee
 
Git & git flow
Git & git flowGit & git flow
Git & git flowAmo Wu
 
Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)Will Huang
 
Crashlytics 使用教學
Crashlytics 使用教學Crashlytics 使用教學
Crashlytics 使用教學ShengWen Chiou
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922Earou Huang
 

Similar a Continuous Delivery: automated testing, continuous integration and continuous deployment. (20)

Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
Git&Github Tutorial
Git&Github TutorialGit&Github Tutorial
Git&Github Tutorial
 
Git flow 與團隊合作
Git flow 與團隊合作Git flow 與團隊合作
Git flow 與團隊合作
 
把玩 Jenkins CI
把玩 Jenkins CI把玩 Jenkins CI
把玩 Jenkins CI
 
使用 Pytest 進行單元測試 (PyCon TW 2021)
使用 Pytest 進行單元測試 (PyCon TW 2021)使用 Pytest 進行單元測試 (PyCon TW 2021)
使用 Pytest 進行單元測試 (PyCon TW 2021)
 
Version control0221
Version control0221Version control0221
Version control0221
 
Xpp
XppXpp
Xpp
 
钱宝坤:多浏览器集成的JavaScript单元测试工具
钱宝坤:多浏览器集成的JavaScript单元测试工具钱宝坤:多浏览器集成的JavaScript单元测试工具
钱宝坤:多浏览器集成的JavaScript单元测试工具
 
Git 經驗分享
Git 經驗分享Git 經驗分享
Git 經驗分享
 
广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdf广告技术部自动化测试介绍.pdf
广告技术部自动化测试介绍.pdf
 
Foundation of software development 1
Foundation of software development 1Foundation of software development 1
Foundation of software development 1
 
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
[2020 .NET Conf] 企業Azure DevOps Service 實際應用架構與秘辛
 
Bitbucket pipeline CI
Bitbucket pipeline CIBitbucket pipeline CI
Bitbucket pipeline CI
 
該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?該怎麼樣(認真的)部署你的 Python Web 應用程式?
該怎麼樣(認真的)部署你的 Python Web 應用程式?
 
持续交付最佳实践——百度技术沙龙201110
持续交付最佳实践——百度技术沙龙201110持续交付最佳实践——百度技术沙龙201110
持续交付最佳实践——百度技术沙龙201110
 
Git Flow 管理
Git Flow 管理Git Flow 管理
Git Flow 管理
 
Git & git flow
Git & git flowGit & git flow
Git & git flow
 
Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)
 
Crashlytics 使用教學
Crashlytics 使用教學Crashlytics 使用教學
Crashlytics 使用教學
 
CICD Workshop 20180922
CICD Workshop 20180922CICD Workshop 20180922
CICD Workshop 20180922
 

Más de Jimmy Lai

Python Linters at Scale.pdf
Python Linters at Scale.pdfPython Linters at Scale.pdf
Python Linters at Scale.pdfJimmy Lai
 
EuroPython 2022 - Automated Refactoring Large Python Codebases
EuroPython 2022 - Automated Refactoring Large Python CodebasesEuroPython 2022 - Automated Refactoring Large Python Codebases
EuroPython 2022 - Automated Refactoring Large Python CodebasesJimmy Lai
 
Annotate types in large codebase with automated refactoring
Annotate types in large codebase with automated refactoringAnnotate types in large codebase with automated refactoring
Annotate types in large codebase with automated refactoringJimmy Lai
 
The journey of asyncio adoption in instagram
The journey of asyncio adoption in instagramThe journey of asyncio adoption in instagram
The journey of asyncio adoption in instagramJimmy Lai
 
Data Analyst Nanodegree
Data Analyst NanodegreeData Analyst Nanodegree
Data Analyst NanodegreeJimmy Lai
 
Distributed system coordination by zookeeper and introduction to kazoo python...
Distributed system coordination by zookeeper and introduction to kazoo python...Distributed system coordination by zookeeper and introduction to kazoo python...
Distributed system coordination by zookeeper and introduction to kazoo python...Jimmy Lai
 
Build a Searchable Knowledge Base
Build a Searchable Knowledge BaseBuild a Searchable Knowledge Base
Build a Searchable Knowledge BaseJimmy Lai
 
[LDSP] Solr Usage
[LDSP] Solr Usage[LDSP] Solr Usage
[LDSP] Solr UsageJimmy Lai
 
[LDSP] Search Engine Back End API Solution for Fast Prototyping
[LDSP] Search Engine Back End API Solution for Fast Prototyping[LDSP] Search Engine Back End API Solution for Fast Prototyping
[LDSP] Search Engine Back End API Solution for Fast PrototypingJimmy Lai
 
Text classification in scikit-learn
Text classification in scikit-learnText classification in scikit-learn
Text classification in scikit-learnJimmy Lai
 
Big data analysis in python @ PyCon.tw 2013
Big data analysis in python @ PyCon.tw 2013Big data analysis in python @ PyCon.tw 2013
Big data analysis in python @ PyCon.tw 2013Jimmy Lai
 
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...Jimmy Lai
 
Software development practices in python
Software development practices in pythonSoftware development practices in python
Software development practices in pythonJimmy Lai
 
Fast data mining flow prototyping using IPython Notebook
Fast data mining flow prototyping using IPython NotebookFast data mining flow prototyping using IPython Notebook
Fast data mining flow prototyping using IPython NotebookJimmy Lai
 
Documentation with sphinx @ PyHug
Documentation with sphinx @ PyHugDocumentation with sphinx @ PyHug
Documentation with sphinx @ PyHugJimmy Lai
 
Apache thrift-RPC service cross languages
Apache thrift-RPC service cross languagesApache thrift-RPC service cross languages
Apache thrift-RPC service cross languagesJimmy Lai
 
NetworkX - python graph analysis and visualization @ PyHug
NetworkX - python graph analysis and visualization @ PyHugNetworkX - python graph analysis and visualization @ PyHug
NetworkX - python graph analysis and visualization @ PyHugJimmy Lai
 
When big data meet python @ COSCUP 2012
When big data meet python @ COSCUP 2012When big data meet python @ COSCUP 2012
When big data meet python @ COSCUP 2012Jimmy Lai
 
Nltk natural language toolkit overview and application @ PyCon.tw 2012
Nltk  natural language toolkit overview and application @ PyCon.tw 2012Nltk  natural language toolkit overview and application @ PyCon.tw 2012
Nltk natural language toolkit overview and application @ PyCon.tw 2012Jimmy Lai
 
Nltk natural language toolkit overview and application @ PyHug
Nltk  natural language toolkit overview and application @ PyHugNltk  natural language toolkit overview and application @ PyHug
Nltk natural language toolkit overview and application @ PyHugJimmy Lai
 

Más de Jimmy Lai (20)

Python Linters at Scale.pdf
Python Linters at Scale.pdfPython Linters at Scale.pdf
Python Linters at Scale.pdf
 
EuroPython 2022 - Automated Refactoring Large Python Codebases
EuroPython 2022 - Automated Refactoring Large Python CodebasesEuroPython 2022 - Automated Refactoring Large Python Codebases
EuroPython 2022 - Automated Refactoring Large Python Codebases
 
Annotate types in large codebase with automated refactoring
Annotate types in large codebase with automated refactoringAnnotate types in large codebase with automated refactoring
Annotate types in large codebase with automated refactoring
 
The journey of asyncio adoption in instagram
The journey of asyncio adoption in instagramThe journey of asyncio adoption in instagram
The journey of asyncio adoption in instagram
 
Data Analyst Nanodegree
Data Analyst NanodegreeData Analyst Nanodegree
Data Analyst Nanodegree
 
Distributed system coordination by zookeeper and introduction to kazoo python...
Distributed system coordination by zookeeper and introduction to kazoo python...Distributed system coordination by zookeeper and introduction to kazoo python...
Distributed system coordination by zookeeper and introduction to kazoo python...
 
Build a Searchable Knowledge Base
Build a Searchable Knowledge BaseBuild a Searchable Knowledge Base
Build a Searchable Knowledge Base
 
[LDSP] Solr Usage
[LDSP] Solr Usage[LDSP] Solr Usage
[LDSP] Solr Usage
 
[LDSP] Search Engine Back End API Solution for Fast Prototyping
[LDSP] Search Engine Back End API Solution for Fast Prototyping[LDSP] Search Engine Back End API Solution for Fast Prototyping
[LDSP] Search Engine Back End API Solution for Fast Prototyping
 
Text classification in scikit-learn
Text classification in scikit-learnText classification in scikit-learn
Text classification in scikit-learn
 
Big data analysis in python @ PyCon.tw 2013
Big data analysis in python @ PyCon.tw 2013Big data analysis in python @ PyCon.tw 2013
Big data analysis in python @ PyCon.tw 2013
 
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
 
Software development practices in python
Software development practices in pythonSoftware development practices in python
Software development practices in python
 
Fast data mining flow prototyping using IPython Notebook
Fast data mining flow prototyping using IPython NotebookFast data mining flow prototyping using IPython Notebook
Fast data mining flow prototyping using IPython Notebook
 
Documentation with sphinx @ PyHug
Documentation with sphinx @ PyHugDocumentation with sphinx @ PyHug
Documentation with sphinx @ PyHug
 
Apache thrift-RPC service cross languages
Apache thrift-RPC service cross languagesApache thrift-RPC service cross languages
Apache thrift-RPC service cross languages
 
NetworkX - python graph analysis and visualization @ PyHug
NetworkX - python graph analysis and visualization @ PyHugNetworkX - python graph analysis and visualization @ PyHug
NetworkX - python graph analysis and visualization @ PyHug
 
When big data meet python @ COSCUP 2012
When big data meet python @ COSCUP 2012When big data meet python @ COSCUP 2012
When big data meet python @ COSCUP 2012
 
Nltk natural language toolkit overview and application @ PyCon.tw 2012
Nltk  natural language toolkit overview and application @ PyCon.tw 2012Nltk  natural language toolkit overview and application @ PyCon.tw 2012
Nltk natural language toolkit overview and application @ PyCon.tw 2012
 
Nltk natural language toolkit overview and application @ PyHug
Nltk  natural language toolkit overview and application @ PyHugNltk  natural language toolkit overview and application @ PyHug
Nltk natural language toolkit overview and application @ PyHug
 

Continuous Delivery: automated testing, continuous integration and continuous deployment.

  • 1. Continuous Delivery: automated testing, continuous integration and continuous deployment. 持續發佈:利⽤用⾃自動化測試與持續 集成來持續發佈⾼高品質的軟體 Jimmy Lai 2014.10.15 ! Jimmy Lai是⾃自然語⾔言處理與機器學習領域的 Python愛好者。 更多他的分享: http://www.slideshare.net/jimmy_lai/
  • 2. Outline 1. 持續發佈的概念 2. 持續發佈的⼯工具 3. 以Python專案為範例建構部署流⽔水 線 2
  • 3. Continuous Delivery 持續發佈 • 軟體發佈了才算做完了 • 只有commit程式碼還不算完成 • 提交程式碼到軟體發佈的過程必須完全⾃自動 化 • 可重複使⽤用的發佈與部署流程,以確保軟體 品質 • 程式碼與設定檔等產出必須要進⾏行版本控 制,以便快速的追蹤與回復 3
  • 4. Version Control 版本控制 • 需要版本控制的項⺫⽬目 • 原始碼 • 套件相依管理 • 系統參數設定 • 主流⼯工具: Git 4
  • 5. Continuous Integration 持續整合 • 在合作開發的團隊中,持續地將每個⼈人的變 更整合在⼀一起,越頻繁地整合就可以減少嚴 重的衝突發⽣生 • 要件: • 頻繁的commit原始碼 • ⾃自動化的測試 • 簡短的建置與測試週期,以及早獲得回饋 • 主流⼯工具: Jenkins 5
  • 6. Testing 測試 • ⾃自動化測試 • 單元測試: 針對function/class • 功能測試: 針對客⼾戶端需求 • 系統整合測試: 針對⼦子系統的整合 • 效能與覆載測試 • 安全性測試 • ⼿手動測試 • 探索性測試、使⽤用者接受度測試 • Python測試⼯工具: nosetests 6
  • 7. 部署流⽔水線 1. 建置與單元測試(當commit程式碼時) 2. ⾃自動化的功能測試 3. 使⽤用者接受度測試(測試⼯工程師) 4. 發佈 過程中有任何錯誤即⾃自動通知開發者, 開發者應優先修復部署流⽔水線後再繼續 開發新功能 7
  • 8. Git版本控制 • 分散式版本控制 • 每⼀一台機器都有⼯工作⺫⽬目錄和版本資料 庫 • 每⼀一台機器的版本資料庫都可以與任 意機器同步 • 開發時先對本地資料庫進⾏行commit, 不需要網路連線 http://git-scm.com/ 8
  • 9. Git實務 • ⼯工作⺫⽬目錄 <-> 暫存區 <-> 版本資料庫 • ⼯工作⺫⽬目錄為某個版本分⽀支的狀態加上新的修改 • git add: 將檔案當前的狀態加⼊入暫存區 • git commit -m “commit message”: 將⺫⽬目前暫存區 當中的所有檔案更改儲存到版本資料庫 • git push origin master: 將當前分⽀支的本機更新推送 到遠端(origin)版本資料庫的master分⽀支 • git pull origin master: 將遠端(origin)版本資料庫的 master分⽀支的更新下載到當前⼯工作⺫⽬目錄分⽀支 http://git-scm.com/docs/gittutorial 9
  • 10. Git Code Review • 透過Github的code review來確保軟體品質: 1. git checkout -b branch: 在本地建⽴立分⽀支並切換到該分⽀支 2. git commit: 在本地分⽀支提交變更 3. git push origin branch_a: 將變更推送到Github 4. 在Github建⽴立pull request 5. Reviewer進⾏行審查 6. 審查修改完善後將branch merge回master • master branch⽤用來發佈軟體,新的修改都先在其他分⽀支 進⾏行,經過審查後才merge • Code Review有助於團隊成員互相學習並提⾼高程式碼品質 http://nvie.com/posts/a-successful-git-branching-model/ 10
  • 11. Git Code Review Demo https://github.com/jimmylai/continuous_delivery_demo
  • 12. Git Code Review 範例 • 需求: 撰寫設定系統套件的Makefile, 並進⾏行Code Review • 步驟: 1. 於git建⽴立新分⽀支 2. 在新分⽀支提交修改 3. 更新到github後,建⽴立pull request 4. Review確認後merge 12
  • 13. 13 Committed Changes Create a pull request
  • 16. Update According to the Comments 16 Merge
  • 18. 單元測試 • 單元測試: 對程式碼單元(funtion, class)進 ⾏行撰寫測試案例 • 被測試的程式碼必須要減少與其他程式碼 的相依性才容易測試,通常可以透過適當 的封裝函數來達成。必要時必須要利⽤用 Mock技術來隔離相依性,例如呼叫資料 庫連線、外部IO. • Python測試⼯工具nosetest 18
  • 19. Unit Test with nosetests https://github.com/jimmylai/continuous_delivery_demo/tree/ master/web/calculator
  • 20. Unit Test with nosetests範例 • 需求: 撰寫⼀一個函式,有兩個整數作為 參數,回傳兩個參數相加之和 • 步驟: 1. 撰寫函式 2. 利⽤用doctest做為說明及測試 3. 撰寫測試函數 20
  • 21. Unit test with Nosetest doctest: 作為函式說明範例,也是單元測試 21
  • 23. 功能測試 • 針對客⼾戶端要求的功能進⾏行驗證,測試 的對象可能是由數個元件組成的系統 • 針對不同界⾯面的系統需要使⽤用不同的⽅方 式來測試,例如網⾴頁就必須以瀏覽器來 測試才完整 • 範例: 基於先前的add( ), 提供⼀一個⽤用來 進⾏行加法RESTful API, 針對輸⼊入進⾏行檢 查,計算後回傳結果 23
  • 24. Functional Test of RESTful API https://github.com/jimmylai/continuous_delivery_demo/tree/ master/functional_tests
  • 25. Functional Test of RESTful API 範例 • 需求: 實作⼀一個Restful API, 透過HTTP GET 輸⼊入兩個參數, 呼叫前⼀一範例的add( )進⾏行加 總, 以json格式回傳結果 • 步驟: 1. 使⽤用Django rest framework撰寫API 2. 驗證輸⼊入的兩個參數存在且為整數 3. 將運算結果回傳 4. 測試客⼾戶端送出HTTP GET request來 進⾏行測試 25
  • 26. Django RESTful API - View 26
  • 28. 28 start web server functional test test successfully
  • 29. Jenkins • 廣受歡迎的持續整合軟體 • 根據設定的條件(如提交程式碼時、定 時排程)觸發建置,如建置發⽣生錯誤便 ⽴立即通知開發者,建置順利可繼續下⼀一 階段建制或⾃自動發佈 • 建置的結果報表以網⾴頁的⽅方式呈現 • 建置的過程與產出皆有存檔,⽅方便回溯 http://jenkins-ci.org/ 29
  • 30. Unitest when Commits with Jenkins
  • 31. Unitest when Commits with Jenkins範例 • 需求:透過Jenkins Job, 當有新的程式 碼被提交時, 便⾃自動運⾏行unit test, 輸出 測試結果報表 • 步驟: 1. 設定Jenkins Job與Github的授權 2. 設定當有新的change時, 由Github 觸發Jenkins 3. 設定測試結果報表資訊 31
  • 32. Github access with ssh key auth 32
  • 33. Jenkins settings build when new changes come in Github settings 33
  • 34. Unit test coverage Unit test report 34
  • 35. 35
  • 36. ⾃自動部署 • ⾃自動將建置好的軟體安裝與設定到不 同的環境,進⾏行後續的測試、交付產 品 • 不同的環境可能有不同的系統相依套 件、不同的設定 • 設定檔與部署程式都應進⾏行版本控制 36
  • 37. Deploy after Unit Tests Success
  • 38. Deploy after Unit Tests Success範例 • 需求: 使⽤用Apache作為Web server, 設 定Jenkins Job當unit test完成後, 發佈 到Apache Server • 步驟: 1. 準備Apache設定檔 2. 準備deploy scripts 3. 設定Jenkins job 38
  • 40. Jenkins Setting 40 Deploy script
  • 41. 部署流⽔水線 1. unittest: 由⼯工程師提交程式碼觸發 2. deploy 3. functional test 4. release, … 過程中有任何錯誤即⾃自動通知開發者, 開發者應優先修復部署流⽔水線後再繼續 開發新功能 41
  • 42. 42
  • 43. 43