achieving "zero downtime deployment" with automated testing

38
Achieving “Zero Downtime Deployment” with Automated Testing Kan Ouivirach Poomjai Saeyong BugDay Bangkok 2014

Upload: kan-ouivirach-phd

Post on 11-Jun-2015

466 views

Category:

Technology


4 download

DESCRIPTION

This talk covers how the R&D team at Pronto Marketing approach Continuous Delivery through automated testing and deployment. It also covers our approach to development environments, test strategies, and automated test environments.

TRANSCRIPT

Page 1: Achieving "Zero Downtime Deployment" with Automated Testing

Achieving “Zero Downtime Deployment” with Automated Testing

Kan OuivirachPoomjai Saeyong

BugDay Bangkok 2014

Page 2: Achieving "Zero Downtime Deployment" with Automated Testing

ใครมาพูดนะ?

Kan Ouivirach Research & Development [email protected]

Poomjai Saeyong Agile Tester

[email protected]

Page 3: Achieving "Zero Downtime Deployment" with Automated Testing

หัวข้ออะไรบ้าง?

• เกริ่นเล็กน้อย

• เริ่มต้นอย่างไร?

• Automate กันไปทำเพื่อ?

• ถาม-ตอบ

Page 4: Achieving "Zero Downtime Deployment" with Automated Testing

Downtime ในมุมมองของใคร?

Page 5: Achieving "Zero Downtime Deployment" with Automated Testing

ปัจจัยที่สำคัญที่สุด

Page 6: Achieving "Zero Downtime Deployment" with Automated Testing

http://theyec.org/

Page 7: Achieving "Zero Downtime Deployment" with Automated Testing

เริ่มต้น?

Page 8: Achieving "Zero Downtime Deployment" with Automated Testing

ขอ 5 ขั้นตอนพอ

http://inspirationlush.com/

Page 9: Achieving "Zero Downtime Deployment" with Automated Testing

–มิตรสหายท่านหนึ่ง

“บนเครื่องผมมันเวิร์คอ่ะ”

Page 10: Achieving "Zero Downtime Deployment" with Automated Testing

ขั้นตอนที่ 1

Development Environment

Page 11: Achieving "Zero Downtime Deployment" with Automated Testing

http://www.digitalforreallife.com/2012/11/boosting-teamwork-with-vagrant/

Page 12: Achieving "Zero Downtime Deployment" with Automated Testing

ขั้นตอนที่ 2

Test-Driven Development (TDD)

Page 13: Achieving "Zero Downtime Deployment" with Automated Testing

ขั้นตอนที่ 3

Acceptance Test-Driven Development (ATDD)

Page 14: Achieving "Zero Downtime Deployment" with Automated Testing

ขั้นตอนที่ 4

Continuous Integration (CI)

Page 15: Achieving "Zero Downtime Deployment" with Automated Testing

Build Pipeline

Page 16: Achieving "Zero Downtime Deployment" with Automated Testing

Build Pipeline

Pull Code

Page 17: Achieving "Zero Downtime Deployment" with Automated Testing

Build Pipeline

Unit Test

Page 18: Achieving "Zero Downtime Deployment" with Automated Testing

Build Pipeline

Acceptance Test

Page 19: Achieving "Zero Downtime Deployment" with Automated Testing

Build Pipeline

Performance Test

Page 20: Achieving "Zero Downtime Deployment" with Automated Testing

Build Pipeline

Unit Test Again after Merge into

Master

Page 21: Achieving "Zero Downtime Deployment" with Automated Testing

Build Pipeline

Deploy to Demo

Page 22: Achieving "Zero Downtime Deployment" with Automated Testing

Build Pipeline

Deploy to Production

Page 23: Achieving "Zero Downtime Deployment" with Automated Testing

ถ้า Build พัง?

Page 24: Achieving "Zero Downtime Deployment" with Automated Testing

เครื่อง Demo (Staging) ก็สำคัญนะเออ

• จะมี Database เหมือนกับเครื่อง Production ซึ่งเราสามารถทดสอบ Migration Script ได้

• เอาไว้ทดสอบของใหม่ๆ ก่อนเอาเข้า Production

Page 25: Achieving "Zero Downtime Deployment" with Automated Testing

แนวทางปฏิบัติ

• เก็บโค้ดไว้ที่เดียวกัน ทำงานบน Branch เดียวกัน (สมมุติว่าใช้ Git)

• เวลาจะแก้ไข หรือเพิ่ม Feature

1. เอาโค้ดจาก Remote มาเป็น Working Copy บนเครื่อง

2. เขียนโค้ดเขียนเทสให้เสร็จ

3. อัพเดท Working Copy จาก Remote ดูว่ามีอะไรเปลี่ยนแปลงหรือไม่

4. รันเทส ถ้าพังก็แก้ ถ้าไม่พังก็เอาโค้ดเข้า Remote

Page 26: Achieving "Zero Downtime Deployment" with Automated Testing

ทีมควรจะต้อง

• หมั่น Check-in บ่อยๆ

• อย่า Check-in โค้ดพัง

• อย่า Check-in โค้ดที่ไม่มีเทส

• อย่า Check-in ตอนที่ Build พัง

Page 27: Achieving "Zero Downtime Deployment" with Automated Testing

–Martin Fowler

“Continuous Integration doesn’t get rid of bugs, but it does make them dramatically

easier to find and remove.”

Page 28: Achieving "Zero Downtime Deployment" with Automated Testing

ขั้นตอนที่ 5

Automated Deployment

Page 30: Achieving "Zero Downtime Deployment" with Automated Testing

ขั้นตอน Deployment ของ Mina

1. สร้าง Folder ใหม่

2. เอาโค้ดล่าสุดใส่ Folder นั้น

3. รัน Database Migration Script

4. ย้าย Symbolic Link ไปชี้ที่ Directory นั้น

Page 31: Achieving "Zero Downtime Deployment" with Automated Testing

/var/www/welovebug.com/ |- releases/ |- |- 1/ |- |- 2/ |- |- 3/ |- |- shared/ |- current/

เอา Document Root มาชี้ตรงนี้

เอา current มาชี้ตรงนี้

Page 32: Achieving "Zero Downtime Deployment" with Automated Testing

/var/www/welovebug.com/ |- releases/ |- |- 1/ |- |- 2/ |- |- 3/ |- |- 4/ |- |- shared/ |- current/

เอาโค้ดใหม่ใส่ที่นี่

Page 33: Achieving "Zero Downtime Deployment" with Automated Testing

/var/www/welovebug.com/ |- releases/ |- |- 1/ |- |- 2/ |- |- 3/ |- |- 4/ |- |- shared/ |- current/

สุดท้ายค่อย Restart Services

แล้วย้าย current มาชี้ที่นี่

Page 34: Achieving "Zero Downtime Deployment" with Automated Testing

Automate กันไปทำเพื่อ?

Page 35: Achieving "Zero Downtime Deployment" with Automated Testing
Page 36: Achieving "Zero Downtime Deployment" with Automated Testing

ส่วนหนึ่งก็เพื่อ

• ส่งมอบงานที่มีคุณภาพได้เร็วขึ้น และบ่อยขึ้น

• เอาเวลาไปพัฒนาสิ่งใหม่ๆ แทนที่จะเอาไปแก้บั๊ก

• ลดความเสียหายที่เกิดจากคน

• ช่วยทำ Regression Test

Page 37: Achieving "Zero Downtime Deployment" with Automated Testing

http://www.xkcd.com/974/

ทำให้ถูกตั้งแต่ตอนนี้

Page 38: Achieving "Zero Downtime Deployment" with Automated Testing

ถาม-ตอบ