วิธีทำ Auto Deployment ด้วย Pipeline บน Bitbucket
Published in:2024-03-03 | Categories: Git Tutorial Linux Tutorial

เปิดใช้งาน Pipeline ใน Project

1. ไปที่ Repository settings -> Settings ->

2-3. เปิดใช้งาน Enable Pipelines และคลิกที่ “Configure bitbucket-pipeline.yml”

4. เลื่อนลงมาด้านล่างเลือก “Select” ในส่วนของ “Starter pipeline”

5. แก้ไข Pipeline ตามขั้นตอนที่ต้องการ deploy ตัวอย่างเป็นการ deploy NodeJS website ไปบน Linux Server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
image: node:18
steps:
- step: &dummy-step
name: dummy-step
clone:
enabled: false
script:
- echo "Dummy step"
pipelines:
branches:
master:
- step: *dummy-step
- step:
name: deploy master
trigger: manual
script:
- umask 022
- cd blog
- npm i
- npm run build
- scp -P 8022 -r dist/* pipeline@server.com:/home/pipeline/target/
- echo "Completed deploy master"

ตั้งค่า SSH Keys

6. ไปที่ Repository settings -> SSH Keys ในส่วนของ Pipeline

7. กดปุ่ม “Generate keys” เพื่อสร้าง public key ให้ Bitbucket เชื่อมต่อ Server เราได้

8. Copy public key ไปไว้ที่ “~/.ssh/authorized_keys” ของ user ที่จะให้ Bitbucket ใช้ SSH เข้าไปได้

9. ใส่ Domain หรือ IP ของ Server ถ้า SSH ไม่ได้ใช้ Port 22 ให้ใส่ “:” ตามด้วยเลข port (server.com:22)

10. คลิกที่ “Fetch” เพื่อเอา Fringerprint จาก Server

11. คลิกที่ “Add Host” เพื่อบันทึก Fringerprint

ทดสอบการทำงานของ Pipeline

6. ไปที่เมนู Pipeline เลือก commit ที่ต้องการรัน pipeline

7. คลิก “Run” เพื่อเริ่มทำงาน pipeline และดูผลลัพธ์การทำงาน

Prev:
วิธีติดตั้ง IPsec VPN Server ไว้ใช้งานแบบง่ายๆ บน Linux
Next:
วิธีใช้งาน conda เบื้องต้น