Achieving "Zero Downtime Deployment" with Automated Testing

Preview:

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.

Citation preview

Achieving “Zero Downtime Deployment” with Automated Testing

Kan OuivirachPoomjai Saeyong

BugDay Bangkok 2014

ใครมาพูดนะ?

Kan Ouivirach Research & Development Engineerkan@prontomarketing.com

Poomjai Saeyong Agile Tester

boss@prontomarketing.com

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

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

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

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

• ถาม-ตอบ

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

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

http://theyec.org/

เริ่มต้น?

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

http://inspirationlush.com/

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

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

ขั้นตอนที่ 1

Development Environment

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

ขั้นตอนที่ 2

Test-Driven Development (TDD)

ขั้นตอนที่ 3

Acceptance Test-Driven Development (ATDD)

ขั้นตอนที่ 4

Continuous Integration (CI)

Build Pipeline

Build Pipeline

Pull Code

Build Pipeline

Unit Test

Build Pipeline

Acceptance Test

Build Pipeline

Performance Test

Build Pipeline

Unit Test Again after Merge into

Master

Build Pipeline

Deploy to Demo

Build Pipeline

Deploy to Production

ถ้า Build พัง?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

–Martin Fowler

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

easier to find and remove.”

ขั้นตอนที่ 5

Automated Deployment

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

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

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

3. รัน Database Migration Script

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

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

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

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

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

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

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

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

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

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

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

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

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

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

• ช่วยทำ Regression Test

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

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

ถาม-ตอบ

Recommended