Skip to content

Buổi 10: Deploy — Đưa Website Lên Internet 🚀

Thành quả: Landing Page buổi 09 có URL thật, gửi được cho bạn bè!


🎯 Mục tiêu buổi học

  1. Hiểu deploy là gì (từ localhost ra internet)
  2. Dùng GitHub Pages hoặc Cloudflare Pages (free)
  3. Có domain/URL thật
  4. Hiểu workflow Git cơ bản
  5. Liên hệ cm-safe-deploycm-identity-guard

📖 Phần 1: Deploy = Sinh Nhật Website

Ví von

Trước deploy: Website như bài vẽ trong vở → chỉ BẠN thấy
Sau deploy:   Website như bảng quảng cáo → CẢ THẾ GIỚI thấy!

Từ localhost → Internet

localhost:3000 (máy bạn)
    ↓ push code
GitHub Repository  
    ↓ auto deploy
https://your-project.pages.dev (Internet!) 🌍

📖 Phần 2: Git — Quản Lý Phiên Bản

Git là gì?

Git = Ctrl+Z siêu cấp. Không chỉ undo 1 bước mà undo VỀ BẤT KỲ THỜI ĐIỂM nào!

5 Lệnh Git Cơ Bản

bash
# 1. Khởi tạo Git
git init

# 2. Thêm file vào "staging area"
git add .                  # Thêm tất cả file
git add index.html         # Thêm 1 file cụ thể

# 3. Lưu snapshot (commit)
git commit -m "Buổi 09: Landing page hoàn chỉnh"

# 4. Kết nối GitHub
git remote add origin https://github.com/USERNAME/REPO.git

# 5. Đẩy code lên GitHub
git push -u origin main

Ví von Git

git add    = Bỏ đồ vào hộp 📦
git commit = Dán nhãn hộp + ghi chú 🏷️
git push   = Gửi hộp lên kho (GitHub) 🚚
git pull   = Lấy hộp mới nhất về 📥

📖 Phần 3: Deploy với GitHub Pages (Free!)

Bước 1: Tạo GitHub account

  1. Vào github.com → Sign Up
  2. Xác nhận email

Bước 2: Tạo Repository

  1. Click "New Repository" (nút xanh +)
  2. Tên: my-landing-page
  3. ✅ Public
  4. Click "Create Repository"

Bước 3: Push code lên

bash
cd ~/VibeCoding/buoi-09
git init
git add .
git commit -m "Landing page v1.0"
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/my-landing-page.git
git push -u origin main

Bước 4: Bật GitHub Pages

  1. Vào Repository → Settings → Pages
  2. Source: Deploy from branch
  3. Branch: main/root
  4. Save!

Bước 5: Chờ 2-3 phút → Website live!

URL: https://YOUR_USERNAME.github.io/my-landing-page/

🎉 Gửi link cho bạn bè ngay!


📖 Phần 4: Deploy với Cloudflare Pages (Nâng cao)

Tại sao Cloudflare Pages?

GitHub PagesCloudflare Pages
FreeFree
Custom domain (thiết lập khó)Custom domain (dễ)
Chỉ staticStatic + Functions
Deploy chậmDeploy nhanh

Cách deploy

bash
# Cài Wrangler CLI
npm install -g wrangler

# Login
wrangler login

# Deploy
wrangler pages deploy ./dist --project-name=my-landing-page

→ URL: https://my-landing-page.pages.dev


📖 Phần 5: CodyMaster Skills

cm-safe-deploy

8-gate deploy pipeline:
1. ✅ Lint check
2. ✅ Type check  
3. ✅ Unit test
4. ✅ Build success
5. ✅ Bundle size check
6. ✅ Security scan
7. ✅ Preview deployment
8. ✅ Production deployment

cm-identity-guard

Trước khi push, LUÔN kiểm tra:

bash
# Đang push đúng account chưa?
git config user.email    # Email đúng?
git remote -v            # Repo đúng?

⚠️ Push nhầm account = lộ code cá nhân vào công ty, hoặc ngược lại!


🎓 Tóm tắt

BướcCông cụLệnh
1. Lưu codeGitgit add . && git commit -m "msg"
2. Đẩy lênGitHubgit push origin main
3. DeployGitHub PagesSettings → Pages → Enable
4. Chia sẻURLusername.github.io/repo

⏭️ Buổi tiếp theo

Buổi 11: Nhà Máy Nội Dung — Content Factory 📰

Powered by CodyMaster × VitePress