PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

110
瑽粙㬵რ: https://unsplash.com/photos/qAShc5SV83M Cheng Wei Chen @ PHPConf 2016.10.29 PHPConf 2016 自動化與持續整合實作工作坊

Transcript of PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Page 1: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://unsplash.com/photos/qAShc5SV83M

Cheng Wei Chen @ PHPConf 2016.10.29

PHPConf 2016自動化與持續整合實作工作坊

Page 2: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Cheng Wei Chen 陳 正瑋

DevOps Engineer @ TheQwan 得寬科技

chengweichen.com

Page 3: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

DevOps TaiwanFB 社團 - https://www.facebook.com/

groups/DevOpsTaiwan/

: https://stock.tookapic.com/photos/17849

個人目前會浮出水面的社群

Page 4: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

四位助教

如在操作上遇到障礙,

可立即尋求助教協助!

Page 5: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

如果還未建置環境

請立即建立 !!

Page 6: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

工作坊範例檔案

讓你少打一些字,複製貼上即可。

https://goo.gl/Vcvag7

Page 7: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

實作環境說明

Page 8: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

實作環境說明

Local VM

Azure

Page 9: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

Page 10: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

Page 11: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

CI Server

Selenium Server

CI Worker

Web Server

Docker Container

Page 12: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

CI Server

Selenium Server

CI Worker

Web Server

Page 13: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

CI Server

Selenium Server

CI Worker

Web Server

Page 14: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

CI Server

Selenium Server

CI Worker

Web ServerVM (80) <-> 容器 (80)

Page 15: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

CI Server

Selenium Server

CI Worker

Web ServerVM (80) <-> 容器 (80)

Host (10080) <-> VM (80)

Page 16: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

GitLab

Selenium ServerRunner

測試機VM (80) <-> 容器 (80)

Host (10080) <-> VM (80)

Page 17: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

GitLab

Selenium ServerRunner

測試機VM (80) <-> 容器 (80)

Host (10080) <-> VM (80) DEMO code

Page 18: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

GitLab

Selenium ServerRunner

測試機VM (80) <-> 容器 (80)

Host (10080) <-> VM (80) DEMO code

Page 19: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

GitLab

Selenium ServerRunner

測試機VM (80) <-> 容器 (80)

Host (10080) <-> VM (80) DEMO code

Page 20: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

GitLab

Selenium ServerRunner

測試機VM (80) <-> 容器 (80)

Host (10080) <-> VM (80) DEMO code

Page 21: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Local VM你的筆電 (Host)

VM (Guest)

GitLab

Selenium ServerRunner

測試機VM (80) <-> 容器 (80)

Host (10080) <-> VM (80) DEMO code

172.17.0.4172.17.0.7

172.17.0.6 172.17.0.8

Page 22: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

你的筆電

DEMO code

Azure VM

GitLab

Selenium ServerRunner

測試機

Cloud (Azure)

VM

Page 23: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

你的筆電

DEMO code

Azure VM

GitLab

Selenium ServerRunner

測試機

Cloud (Azure)

Page 24: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

你的筆電

DEMO code

Azure VM

GitLab

Selenium ServerRunner

測試機

Cloud (Azure)

Page 25: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

你的筆電

DEMO code

Azure VM

GitLab

Selenium ServerRunner

測試機

Cloud (Azure)

Page 26: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://www.pexels.com/photo/coffee-writing-computer-blogging-34600/

工程師 自動化 (

Page 27: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

實際狀況

: https://www.pexels.com/photo/photo-33343/

你以為會是 現實情況是 更多真實的狀況是

很多時候是 經常期待是 目標是

: https://www.pexels.com/photo/photo-64609/: https://www.pexels.com/photo/photo-65050/

: https://picjumbo.com/real-mens-tools/: https://pixabay.com/photo-1510561/: https://pixabay.com/en/photo-593313/

Page 28: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://www.pexels.com/photo/coffee-writing-computer-blogging-34600/

DevOps

Page 29: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

code build test deploy operateplan

Measurement

Monitor Metrics Analytics

Continuous IntegrationContinuous Delivery

DevOps

MonitoringAutomation

Dev

release

Ops Sharing

FastIteration

Feedback

break silos

LEAN

CultureAgile

Page 30: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

資訊 透明度 文化

自動化

Page 31: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

自動化

Continuous Integration

Continuous Delivery

Automated Build

Continuous Deployment

Continuous Testing

Continuous Monitoring

Automated Testing

Release Automation

Page 32: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

code buildplan

Continuous Integration

Continuous Delivery

deploy

Feedback

releasetest

Feedback

operate

Automation

Page 33: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

最簡單的自動化

單元一

Page 34: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

shell scripts

單元一 示範一

Page 35: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

cron + shell scripts

Page 36: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

Job Queue

Page 37: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

Job Queue

Page 38: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

Trigger Action

Page 39: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

Trigger Action

Page 40: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

讓很多事都能自動化

API單元一

示範二

Page 41: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Think

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

Page 42: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Trigger

Scripts

Interface

Service

Flow

Page 43: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

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

Bots IM Voice CMD

Interface

舉例

Page 44: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

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

BotsCI PaaS

Service

Worker

舉例

Page 45: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

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

DateTime Trigger Webhook Event

Trigger

舉例

Page 46: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

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

shell scripts

Ansible Azure Functions

hubot scripts

Scripts

舉例

Page 47: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

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

Flow

Page 48: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Trigger

Scripts

Interface

Service

Flow

Page 49: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Trigger

Scripts

Interface

Service

Flow環境設置與安裝軟體的先後順序

Command Line

bash xxx.sh

VM, BASH process

xxx.sh

shell script

Page 50: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Trigger

Scripts

Interface

Service

Flow執行動作的先後順序, Crontab 觸發的條件

Command Line

Crontab

VM, BASH process

xxx.sh

shell + cron

Page 51: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Trigger

Scripts

Interface

Service

FlowJob 的生命週期, Job 內程式執行的流程

Web

Job Queue

VM, php process, worker

xxx.php

Job Queue

Page 52: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Trigger

Scripts

Interface

Service

Flow呼叫 API 的順序, 流程

Command Line

ansible-playbook …

VM, ansible process

ansible-playbook.yml

Gitlab API

Page 53: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Trigger

Scripts

Interface

Service

Flow開發流程, 自動化動作的流程

CI Server 的 GUI

code push

CI Server, Worker, Runner

設定於 CI Server 上的自動化腳本

CI / CD

Page 54: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

開發流程

: https://www.pexels.com/photo/black-and-white-industry-factory-lamp-5004/

Page 55: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

開發流程code build test release deploy operateplan

Page 56: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

開發流程code build test release deploy operateplan

Page 57: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

開發流程code build test release deploy operateplan

CIcommit dev stagingtest

testprod deploy

Page 58: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

開發流程code build test release deploy operateplan

CIcommit dev stagingtest

testprod deploy

Page 59: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

開發流程code build test release deploy operateplan

CIcommit dev stagingtest

testprod deploy

environment

dev

staging

prod

local

Page 60: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

開發流程code build test release deploy operateplan

CIcommit dev stagingtest

testprod deploy

environment

dev

staging

prod

localMore Automation ?

Page 61: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

今日練習流程

VCScommit CI build devdeploy test

mergeprod deploy

trigger

Page 62: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

自動化建置單元二

Page 63: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程build devdeploy test

mergeprod deploy

VCScommit

Code .gitlab-ci.yml

CI

Page 64: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程build devdeploy test

mergeprod deploy

VCScommit

GitLab

Code

git push

.gitlab-ci.yml

CI

Page 65: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程build devdeploy test

mergeprod deploy

VCScommit

Runner

GitLab

Code

git push

Trigger

.gitlab-ci.yml

CI

Page 66: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程

VM

build devdeploy test

mergeprod deploy

VCScommit

Runner

GitLab

Code

git push

Trigger

.gitlab-ci.yml

Job

CI

Page 67: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程

VM

Docker

build devdeploy test

mergeprod deploy

VCScommit CI

Runner

GitLab

Code

git push

Trigger

.gitlab-ci.yml

RunnerTrigger

Job

Job

Page 68: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

建立 .gitlab-ci.yml

單元二

練習一

Page 69: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程devdeploy test

mergeprod deploy

VCScommit CI

Code + Vendor

Code

composer install

build

Page 70: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

composer install

單元二

練習二

Page 71: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程devdeploy test

mergeprod deploy

VCScommit CI

master-12345.tarCode + Vendor

Code

composer install

tar

build

Page 72: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

將程式碼打包

單元二

練習三

Page 73: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程devdeploy test

mergeprod deploy

VCScommit CI

master-12345.tarCode + Vendor

Code

composer install

tar

build

Artifactsupload

Page 74: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

送入 Artifacts 歸檔

單元二

練習四

Page 75: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

自動化部署單元三

Page 76: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程test

mergeprod deploy

VCScommit CI build devdeploy

Page 77: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

新增 stages: deploy-dev

單元三

練習一

Page 78: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程test

mergeprod deploy

VCScommit CI build devdeploy

Temp Container

Runner

code

run

Ansible playbook dev server

Artifacts

deploy

Page 79: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程test

mergeprod deploy

VCScommit CI build devdeploy

Temp Container

Runner

code

run

Ansible playbook dev server

Artifacts

1.upload artifact

2.unarchive

deploy

3.setup .env

4.composer dump-autoload

5.update nginx config

6.nginx reload

Page 80: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

設定自動化部署動作

單元三

練習二

Page 81: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Think

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

env code

Page 82: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程test

mergeprod deploy

VCScommit CI build devdeploy

Temp Container

Runner

code

run

Ansible playbook dev server

Artifacts

deploy

驗證 deploy

Page 83: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

驗證部署是否成功

單元三

練習三

Page 84: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Think

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

code

Page 85: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

共用的自動化腳本

單元三

練習四

Page 86: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

自動化測試單元四

Page 87: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程

mergeprod deploy

VCScommit CI build devdeploy test

Page 88: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程

mergeprod deploy

VCScommit CI build devdeploy test

Temp Container

Runner

SSH

dev server phpunitrun

Page 89: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

新增 stages: test-dev

單元四

練習一

Page 90: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程

mergeprod deploy

VCScommit CI build devdeploy test

Temp Container

Runner

SSH

dev server run phpunit

Selenium server

Page 91: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

設定 Selenium Server

單元四

練習二

Page 92: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Think

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

phpunit.xml code

Page 93: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

顯示測試覆蓋率

單元四

練習三

Page 94: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

GUI 顯示測試覆蓋率

單元四

練習四

Page 95: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

從 dev 至 master

單元五

Page 96: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程

mergeprod deploy

VCScommit CI build devdeploy test

Page 97: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

新增 dev branch

單元五

練習一

Page 98: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程

mergeprod deploy

VCScommit CI build devdeploy test

dev branch

dev -> master

CI

git push

git push CI

autoauto

Page 99: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

區分 dev 與 master 的 CI 流程

單元五

練習二

Page 100: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程

mergeprod deploy

VCScommit CI build devdeploy test

Curl CItrigger

deploy

prod

trigger

Page 101: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://stock.tookapic.com/photos/10628

透過 Trigger 驅動 Master 部署

單元五

示範三

Page 102: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

流程

VCScommit CI build devdeploy test

mergeprod deploy

trigger

Page 103: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Think

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

Page 104: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

: https://unsplash.com/photos/j0g8taxHZa0

Summary

Page 105: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

開發流程code build test release deploy operateplan

CIcommit dev stagingtest

testprod deploy

environment

dev

staging

prod

local

Page 106: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Trigger

Scripts

Interface

Service

Flow

Page 107: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

code buildplan

Continuous Integration

Continuous Delivery

deploy

Feedback

releasetest

Feedback

operate

Automation

Page 108: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

實際狀況

: https://www.pexels.com/photo/photo-33343/

你以為會是 現實情況是 更多真實的狀況是

很多時候是 經常期待是 目標是

: https://www.pexels.com/photo/photo-64609/: https://www.pexels.com/photo/photo-65050/

: https://picjumbo.com/real-mens-tools/: https://pixabay.com/photo-1510561/: https://pixabay.com/en/photo-593313/

Page 109: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

團隊規模

流程

產品\架構

找出你的最佳實踐

最佳 實踐

文化轉變

工具\平台

跨職能人才

Page 110: PHP Conf Taiwan 2016 自動化與持續整合實作工作坊

Thank You

: https://unsplash.com/photos/oxjo1IQBK7M