ansible & gitlab ci / cd workshop 101 ( @agile tour taipei 2017)

87
Cheng Wei Chen @ Agile Tour Taipei 2017 Photo by Daniel McCullough on Unsplash Ansible & GitLab CI / CD Workshop 101

Upload: chen-cheng-wei

Post on 21-Jan-2018

98 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Cheng Wei Chen @ Agile Tour Taipei 2017Photo by Daniel McCullough on Unsplash

Ansible & GitLab CI / CD Workshop 101

Page 2: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Cheng Wei Chen 陳 正瑋

DevOps Engineer @ 得寬科技

http://chengweichen.com

Page 3: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

2013

100 % Laravel

JetBrains

( )

Page 4: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

PHP/Laravel http://www.laravel-dojo.com

Page 5: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

現場不進行詳細的操作步驟

Page 6: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

詳細步驟請參閱部落格文章

https://goo.gl/ZHKiyb

Page 7: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

在開始之前...

Page 8: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

你讀完了嗎?

Page 9: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

你讀完了嗎?

Page 10: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

沒讀完也很正常啦

Page 11: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

在開始動手之前,

你需要多想一想。

Page 12: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

code build test release deploy operateplan

Continuous Integration

Continuous Delivery

目標

Continuous Deployment

CIcommit dev stagingtest

testprod deploy

environment

dev

staging

prod

local

Page 13: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

commit

code build test release deploy operateplan

Continuous Integration

Continuous Delivery

今天的案例

Continuous Deployment

CI staging

testprod deploy

environment

staging

prod

Page 14: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

commit build

stg-deploy test

unit test

prod-deploy

今天的案例

prod-remove

Page 15: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

該選用哪些工具?

Page 16: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

使用的工具

‧Ansible

‧Docker CE

‧GitLab.com

Your Computer

Server

Free

Free

Free

Page 17: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

環境說明

你的電腦

DEMO code

GitLab .com

Public Runner

Cloud

Web Server

Your Runner

container

FreeFree

Page 18: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

環境說明

你的電腦

DEMO code

GitLab .com

Public Runner

Cloud

Web Server

Your Runner

container

FreeFree

FreeFree

Page 19: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

GitLab CI 運作狀況

GitLab .com

Public Runner

Your Runner

Docker container

CI Jobs

Page 20: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

該從何處開始著手?

Page 21: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

code build test release deploy operateplan

Automation

從痛點、小處著手

Automation

Page 22: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Deploy

從痛點、小處著手

stagingdev test test production

staging test production

Project-1

Project-2

production Project-3x10

x5

x3

Page 23: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

build

stg-deploy test

unit test

prod-deploy

今天的案例為例

prod-remove

Page 24: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

.gitlab-ci.yml

Page 25: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

build

Stage: Build

build-test

build-release

Page 26: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Stage: Buildbuild-test

Page 27: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Stage: Buildbuild-release

Page 28: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Stage: Build

build-release

Page 29: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Stage: Build

Ansible: upload_artifacts.yml

Page 30: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

build

Stage: Build

build-test

build-release

Artifacts (test)

Artifacts (release)

Artifacts Repository (release)

Artifacts Repository (release)

Page 31: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Think

: https://unsplash.com/photos/hANqC3_kTqU

Page 32: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧什麼是 Artifacts?

‧為何需要 Artifacts?

‧以及 Artifacts Repository?

延伸思考

Page 33: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

延伸思考

‧為何要在 Build 時,同步進行兩個 Jobs,一次就將測試與 Production 兩種環境的 Artifacts 給建立?

‧有沒有更好的做法?

Page 34: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

延伸思考

‧在建立給 Production 使用的 Artifacts 時,還有哪些不必要的檔案可以刪除,並不需要一起放進 Artifacts Repository?

Page 35: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧將 Ansible Playbook 與程式碼一起送進同一個 Project Repository?

‧自動化腳本應該如何存放?存放於何處?

‧該如何讓 CI Runner 可以順利取得自動化腳本呢?

延伸思考

Page 36: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

build unit test

Stage: unit-test

build-test

build-release

phpunit

Page 37: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Stage: unit-testphpunit

Page 38: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Think

: https://unsplash.com/photos/hANqC3_kTqU

Page 39: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧自動化測試?

‧What、When、How?

‧特別的測試組態該如何載入?

延伸思考

Page 40: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

build unit test

Stage: stg-deploy

build-test

build-release

phpunit

stg-deploy

Page 41: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Stage: stg-deploystg-deploy

Page 42: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Ansible: auto-deploy.yml

Page 43: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Ansible: auto-deploy.yml

Page 44: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

變數傳遞

Project

Ansible Playbook

Your Runner

Secret variable

Page 45: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Think

: https://unsplash.com/photos/hANqC3_kTqU

Page 46: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

延伸思考

‧Deploy 應該執行哪些動作?

Page 47: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧Deploy 的自動化腳本應該如何設計?

‧Server 該如何與腳本配合?

延伸思考

Page 48: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧續上,你規劃的自動 Deploy 流程可以反覆的 Re-eploy 嗎?

‧當自動 Deploy 失敗時該如何處理?

延伸思考

Page 49: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧Token、Key、inventory 或其他 CI Job 需要的機敏資料應該怎麼管理?並傳遞給 Runner?

延伸思考

Page 50: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧Zero downtime deploy?

‧DB、Files、Storages?

延伸思考

Page 51: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

build unit test

Stage: stg-test

build-test

build-release

phpunit

stg-deploy stg-test

stg server

stg server

Page 52: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Stage: stg-testtest

Page 53: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧Staging 環境應該要與 Production 環境多相像?

延伸思考

Page 54: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

延伸思考

‧在 Staging 環境中應該要執行哪些自動化測試?

Page 55: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧除了測試程式碼,還有哪些東西需要驗證?

延伸思考

Page 56: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧如何收集並回報測試的結果?

‧測試環境是否需要監控?

延伸思考

Page 57: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

build unit test

Stage: prod-deploy

build-test

build-release

phpunit

stg-deploy stg-test

stg server

stg server

prod-deploy

Page 58: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Stage: testtest

prod-deploy

Page 59: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Think

: https://unsplash.com/photos/hANqC3_kTqU

Page 60: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧Deploy 至 Staging 與 Production 的差異有哪些?

延伸思考

Page 61: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

延伸思考

‧同一個 Deploy 自動化腳本如何才能適用在不同的環境?

Page 62: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧再一次,Zero downtime deploy?

‧同樣 Files、Storages?

‧DB Migration?

延伸思考

Page 63: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧如何驗證 Deploy 確實成功?

延伸思考

Page 64: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧如何 Rollback?

延伸思考

Page 65: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

‧如何管理不同 Branch 不同 Pipeline?

‧哪些 Job 可以共用?

延伸思考

Page 66: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

build unit test

Stage: prod-deploy

build-test

build-release

phpunit

stg-deploy stg-test

stg server

stg server

prod-deploy

prod-remove

Page 67: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)
Page 68: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Summary

Page 69: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

code build test release deploy operateplan

Continuous Integration

Continuous Delivery

目標

Continuous Deployment

CIcommit dev stagingtest

testprod deploy

environment

dev

staging

prod

local

Page 70: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

: https://unsplash.com/photos/Fixg8KipOg8

Trigger ScriptsInterface ServiceFlow

注意每個環節

Page 71: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

因為坑,比你想像的多

Oooops

Page 72: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

需要的資源(人力、工時),

也比你想像的多

Page 73: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

需要的評估關鍵,

也同樣比你想像的多

Page 74: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

code build test release deploy operateplan

Automation

從痛點、小處著手

Automation

Page 75: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

• • • • •

思考並評估

Page 76: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

好書非讀不可

Page 77: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

CD

https://www.infoq.com/articles/Continuous-Delivery-Maturity-Model

Page 78: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

好書非讀不可

https://landing.google.com/sre/book.html

Page 79: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

• Operator-triggered manual action • Operator-written, system-specific automation • Externally maintained generic automation • Internally maintained, system-specific automation • Autonomous systems that need no human intervention

自動化的演進

https://landing.google.com/sre/book.html

Page 80: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

反覆評估、持續改善

Photo by Sweet Ice Cream Photography on Unsplash

迭代

Page 81: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

工商服務

Page 82: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

https://devopstw.club

Page 83: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

尋求志工、贊助

: https://pixabay.com/en/building-joy-planning-plans-1080592/ , https://pixabay.com/en/baby-hand-dad-200760/

Page 84: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

尋求講者及講題

: https://www.pexels.com/photo/man-person-suit-united-states-of-america-2281/

Page 85: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

http://fb.sre.tw

Page 86: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)
Page 87: Ansible & GitLab CI / CD Workshop 101 ( @Agile Tour Taipei 2017)

Photo by Clark Tibbs on Unsplash

Thank You