Quest 41 - CI Pipeline Builder
Quest 41: CI Pipeline Builder
hard 25 minutes🎯 Learning Objectives
- เข้าใจ concepts ของ CI/CD pipelines
- ใช้ AI ช่วยสร้าง CI configurations ที่ถูกต้อง
- ออกแบบ pipeline stages ที่เหมาะสมกับ project
- เรียนรู้ best practices ของ CI/CD
📖 Concept: CI/CD Pipeline
CI (Continuous Integration) คือ practice ที่ developers merge code changes เข้า main branch บ่อยๆ — แต่ละ merge จะถูก test โดยอัตโนมัติ
CD (Continuous Delivery/Deployment) คือการ automate ขั้นตอนหลัง tests ผ่าน — build, package, deploy
CI/CD pipeline เหมือน conveyor belt ใน factory — code changes เข้ามา → ผ่าน tests → build → deploy โดยไม่ต้องทำ manual
AI ช่วยสร้าง CI configurations ได้ดี因为它รู้ best practices จาก projects นับล้าน — แต่คุณต้อง verify ว่า config ตรงกับ needs ของ project
⚙️ How It Works
โครงสร้างของ CI/CD Pipeline
Code Push ↓┌─────────────┐│ Lint & │ ← ตรวจสอบ code quality│ Format │└──────┬──────┘ ↓┌─────────────┐│ Unit │ ← ทดสอบ individual functions│ Tests │└──────┬──────┘ ↓┌─────────────┐│ Integration │ ← ทดสอบ modules ทำงานร่วมกัน│ Tests │└──────┬──────┘ ↓┌─────────────┐│ Build │ ← สร้าง production bundle└──────┬──────┘ ↓┌─────────────┐│ Deploy │ ← deploy ไป production└─────────────┘CI Configuration Example (GitHub Actions)
name: CI Pipeline
on: push: branches: [main, develop] pull_request: branches: [main]
jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20'
- name: Install dependencies run: npm ci
- name: Lint run: npm run lint
- name: Test run: npm test
- name: Build run: npm run build💡 Example: สร้าง Pipeline Config
function generatePipelineConfig(projectType) { const configs = { node: { name: 'Node.js CI', steps: [ { name: 'Checkout', uses: 'actions/checkout@v4' }, { name: 'Setup Node', uses: 'actions/setup-node@v4', with: { 'node-version': '20' } }, { name: 'Install', run: 'npm ci' }, { name: 'Lint', run: 'npm run lint' }, { name: 'Test', run: 'npm test' }, { name: 'Build', run: 'npm run build' } ] }, python: { name: 'Python CI', steps: [ { name: 'Checkout', uses: 'actions/checkout@v4' }, { name: 'Setup Python', uses: 'actions/setup-python@v5', with: { 'python-version': '3.11' } }, { name: 'Install', run: 'pip install -r requirements.txt' }, { name: 'Lint', run: 'ruff check .' }, { name: 'Test', run: 'pytest' } ] } };
return configs[projectType] || configs.node;}
// ใช้งานconst pipeline = generatePipelineConfig('node');console.log(JSON.stringify(pipeline, null, 2));⚠️ Common Mistakes
Mistake 1: ไม่ cache dependencies
“npm install ทุกครั้งก็ได้” → Caching ลด build time ได้มาก — ใช้ actions/cache หรือ built-in caching
Mistake 2: ไม่มี failing step ที่ชัดเจน
“run ทุกอย่างใน step เดียว” → Split steps ให้ชัด — จะได้รู้ว่า step ไหน fail
Mistake 3: ไม่ test ทุก environments
“test แค่ Node 20” → ทดสอบหลาย versions — บางครั้ง code ทำงานใน version หนึ่งแต่ไม่อีก version
Mistake 4: deploy โดยไม่มี approval
“auto deploy ทุก push” → Production deployments ควรมี approval gate — ป้องกัน accidental deploy
📝 Knowledge Check
📝 Knowledge Check
Q1:CI pipeline ควรมี step ไหนบ้างเป็นอย่างน้อย?
Q2:เพราะเหตุใด CI pipeline จึงควร cache dependencies?
Q3:ทำไม production deployments ควรมี approval gate?
🏋️ Quest: CI Pipeline Builder
พร้อมแล้วสร้าง pipeline! ใช้ AI ช่วยสร้าง CI/CD configurations
-
Download ไฟล์เริ่มต้นของ quest:
Terminal window npx bluebeltdojo download quest-41-ci-pipeline-buildercd quest-41-ci-pipeline-builder -
เปิด
problem.jsใน editor ของคุณพร้อมความช่วยเหลือของ AI -
Implement
solve()ที่ create CI/CD configuration -
ตรวจสอบ solution ของคุณ:
Terminal window node test.js -
เมื่อ tests ผ่านทั้งหมด ส่งคำตอบ:
Terminal window npx bluebeltdojo submit
💡 Tip: ลองนึกว่าถ้าคุณจะ setup CI สำหรับ project จริง — คุณจะ test อะไรบ้าง?
คำใบ้
- ดู project type ใน problem.js สำหรับ pipeline structure ที่ต้องใช้
- คิดถึง stages ที่จำเป็น — lint, test, build, deploy
- อย่าลืม caching และ error handling