1. Deployment
Traffic Tool
  • Traffic Tool Docs
    • Tổng quan
      • Tổng Quan
      • Setup Guide
      • System Architecture
      • Code Structure
      • Logs and Monitoring
      • Environment & Configuration
      • Deployment
        • Local
        • Staging
        • Product
    • Bussiness | Logic
      • 1. Thống kê hàng ngày (Daily Statistics)
      • 2. Thống kê hệ thống (System Statistics)
      • 3. Tìm kiếm tự động (Automated Discovery)
      • 4. Trung tâm Báo cáo (Report Center)
      • 5. Quản lý tài khoản (Account Management)
      • 6. Quản lý Hệ thống (System Management)
      • 7. Quản lý tài khoản Google (Google Account Management)
    • Project
      • ADMIN
        • Tổng quan
        • Hướng dẫn sử dung
          • Đăng Nhập & Xác Thực Hai Bước
          • Thống Kê Hệ Thống
          • Thống Kê Hàng Ngày
          • Tìm Kiếm Tự Động
          • Trung Tâm Báo Cáo
          • Quản Lý Tài Khoản
          • Quản Lý Server
          • Quản Lý Proxy
          • Quản Lý Gói Proxy
          • Quản Lý Nhà Cung Cấp Proxy
          • Quản Lý Backup Proxy
          • Quản Lý Tài Khoản Google
          • User Guide
        • Architecture
          • System Architecture
          • Code Structure
          • Environment & Configuration
          • Logs and Monitoring
        • Deployment
          • Local
          • Staging
          • Production
      • API
        • Tổng quan
        • Architecture
          • Database Schema
          • System Architecture
          • Code Structure
          • Environment & Configuration
          • Logs and Monitoring
        • Deployment
          • Local
          • Staging
          • Production
        • API Interface
          • 🔑 Identity & Session
            • Đăng nhập hệ thống (Login)
            • Đăng ký tài khoản mới (Public)
            • Lấy danh sách người dùng (Phân trang)
            • Admin tạo người dùng mới
            • Lấy thông tin cá nhân hiện tại
            • Khởi tạo bảo mật 2FA
            • Xác thực mã OTP
            • Chi tiết người dùng theo ID
            • Cập nhật thông tin người dùng
            • Xóa tài khoản người dùng
            • Đổi mật khẩu
            • Kiểm tra Cấu hình Thông báo Telegram Toàn hệ thống
            • Bật/Tắt Thông báo Telegram Toàn cục
          • 📁 Campaign Management
            • Danh sách Chiến dịch Toàn cầu
            • Khởi tạo Chiến dịch Mới
            • Chi tiết Chiến dịch
            • Cập nhật Chiến dịch
            • Xóa Chiến dịch
            • Tắt/Mở Chiến dịch (Hàng loạt)
            • Dữ liệu Hình mẫu SEO (Negative SEO)
          • ⚙️ Project Mechanics
            • Danh sách Dự án (Projects List)
            • Khởi tạo Kịch bản Mô phỏng
            • Lấy chi tiết cấu hình Dự án
            • Cập nhật Kịch bản chạy
            • Xóa Dự án
            • Chỉnh sửa Hàng loạt (Bulk)
            • Bật/Tắt Dự án
          • 👤 Profile Management
            • Danh sách Vân tay số (Profiles Data)
            • Tạo Hồ sơ Đơn lẻ (Tạo Vân tay mới)
            • Nhập kho Tài khoản Email (Bulk Import)
            • Chi tiết Session/Cookies
            • Chỉnh sửa Hồ sơ/Ghi chú
            • Xóa Vân tay số và Dữ liệu Local
            • Mở khóa Captcha/Trạng thái Blocked
            • Tra cứu Kho Profile Khả dụng
            • Báo cáo Sức khỏe Kho Tài Khoản
          • 🦾 Worker Interface
            • Đăng ký Khởi tạo Node (Handshake)
            • Nhịp Tim Khảo Sát Tình Trạng (Heartbeat)
            • Nhận Cấu hình Bypass & Hệ thống
            • Kéo (PULL) Nhiệm vụ Traffic SEO
            • Báo cáo Sự cố Node (Crash Report)
          • 📊 Report: Execution
            • Kéo Công việc Báo cáo (Worker Pull)
            • Quản lý Giám sát Nhiệm vụ (Task Dashboard)
            • Bắn Lại Báo Cáo Thất Bại (Manual Retry)
          • 📊 Report: Discovery
            • Danh sách Tên miền Chờ Xử Lý (Discovery Pool)
            • Nhập Mục Tiêu Thủ Công (Manual Insert)
            • Kích hoạt Heuristic Scanner (Cào tự động)
            • Chi tiết Bằng Chứng (Evidence Data)
            • Dán nhãn Vi Phạm / Cập nhật Screenshot
            • Loại Bỏ Mục Tiêu
            • Duyệt Yêu Cầu (Approve to Execution)
          • 📊 Report: Platforms Configuration
            • Truy vấn Danh sách Nền tảng Đối tác (Vendor)
            • Tạo Nền tảng Vendor Báo cáo Mới
            • Bật/Tắt Trang báo cáo theo Loại
            • Cập nhật Metadata Trang
            • Xóa Trang Báo Cáo
            • Lấy Cài đặt LLM cho Vendor cụ thể
            • Cập nhật Cài đặt Tạo mẫu LLM
            • Lấy Cấu hình Schema Biểu mẫu cho Vendor
            • Cập nhật Yêu cầu Trường Biểu mẫu
          • 📊 Report: Email Automation
            • Danh sách SMTP/Mailer Server
            • Thêm kết nối SMTP Mới
            • Nhật ký Nhiệm vụ Gửi Mail (Email Log)
            • Phân tích Tỉ lệ Chuyển đổi (Email Delivery Analytics)
          • 🌐 Global Proxies
            • Danh sách Kho Proxy Phân trang (Proxy Pool)
            • Thêm mới Tuyến IP (Bulk Import)
            • Cập nhật Thông tin máy chủ Proxy
            • Xóa Proxy (Thu hồi tài nguyên)
            • Kích hoạt Xoay vòng (Rotate IP) Cưỡng bức
          • 📈 System Intelligence
            • Báo cáo Luồng Bảo mật Hợp nhất (Colossal Report)
            • Bản Đồ Lưu Lượng GeoIP (Heatmap)
          • 🪝 Webhook Integrations
            • Callback Hoàn tất Gói Lưu lượng SEO (Traffic Node)
            • Callback Thông báo Hoàn tất Bắn Report AI
      • Tool
        • Tổng quan
        • Architecture
          • System Architecture
          • Code Structure
          • Environment & Configuration
          • Logs And Monitoring
          • Database Schema
        • Deployment
          • Local
          • Staging
          • Production
        • API interface
          • Tasks
            • Lấy tasks có phân trang và lọc
            • Xóa tất cả tasks
            • Get all tasks
            • Cập nhật một task
            • Xóa một task theo ID
            • Get all tasks
          • Group task
            • Tạo nhiều task groups
            • Lấy tất cả task groups
            • Xóa tất cả task groups
            • Xóa một task group theo ID
            • Endpoint /api/task-traffics/
            • Test parse proxy string
            • Endpoint /api/task-traffics/
          • Test
            • Mock proxy endpoint cho development
            • Mock profile endpoint cho development
            • Endpoint /api/test
            • Endpoint /api/test/account-stats
            • Endpoint /api/test/session-recommendation
            • Endpoint /api/test/check-browser
            • Endpoint /api/test/clear-browser-sessions
          • Proxies
            • Lấy tất cả proxy records
            • Tạo proxy record mới
            • Xóa tất cả proxies
            • Get all proxies
            • Xóa một proxy theo ID
            • Reset proxy process counter
            • Get all proxies
            • Get all proxies
          • Report Platforms
            • Submit report to multiple platforms
            • Submit report to specific platform
            • Get available platforms
            • Get platform statistics
            • Health check
          • Reports
            • Create a new report
            • Create a new report
            • Get report by ID
            • Get report by ID
            • Get report statistics
            • Get report groups
            • Get report groups
            • Get report group
            • Add report to group
            • Bulk add reports to group
            • Get report group statistics
            • Get analytics data
            • Get platform success rates
            • Get reports by platform
            • Get reports by group
            • Create test reports in bulk
            • Tạo PC report CSV
            • Lấy PC report JSON
            • Lấy report tasks
            • Giám sát report tasks
            • Report tasks đang hoạt động
            • Chi tiết report task
            • Thống kê reports
            • Dữ liệu biểu đồ reports
            • Lấy danh sách report sites
            • Tạo report site
            • Thống kê sites
            • Toggle site enabled/disabled
            • Toggle tất cả sites
            • Toggle sites theo type
            • Cập nhật hàng loạt AI prompts
            • Cập nhật site
            • Xóa site
            • Lấy cấu hình đầy đủ của site
            • Lấy AI prompt của site
            • Cập nhật AI prompt của site
            • Lấy GPT config của site
            • Cập nhật GPT config
            • Lấy response config của site
            • Cập nhật response config
            • Lấy security vendors đang bật
            • Phân tích keywords
            • Top keywords
            • Thống kê analytics
            • PC report dashboard
            • Lấy report domains
            • Thêm report domain
            • Chi tiết report domain
            • Thống kê hàng ngày
            • Cập nhật hàng loạt reports
          • Test Report
            • Test Microsoft report submission
            • Test AdGuard report submission
            • Test Google Ads report submission
            • Test Spamhaus report submission
            • Test ESET report submission
            • Test multi-platform report submission
            • Get available platforms
          • ESET Test
            • Simple test
            • Minimal POST test
            • Generate ESET report content
            • Get sample test data
            • Test form filling
            • Test full form submission
          • Spamhaus Test
            • Simple test
            • Minimal POST test
            • Generate Spamhaus report content
            • Get sample test data
            • Test Spamhaus form filling
            • Test full Spamhaus form submission
          • Report Scheduler
            • Get report scheduler statistics
            • Process ad detection result
            • Submit a scheduled report
            • Start report scheduler
            • Stop report scheduler
            • Get scheduler status
            • Process scheduled reports
            • Test browser session (non-headless)
            • Test report submission (non-headless)
          • Comprehensive Analytics
            • Get comprehensive dashboard analytics
            • Get overview statistics
            • Get brand-wise statistics
            • Get daily statistics
            • Get platform success rates
            • Get account performance
            • Get summary report
          • Search
            • Tạo nhiều search tasks
            • Lấy tổng số search tasks
          • Report Tasks
            • Tạo report tasks cho một domain
            • Tạo report tasks trực tiếp (hỗ trợ profileCountry và domainType rõ ràng)
            • Tạo report tasks cho nhiều domains cùng lúc
            • Tạo email-based report tasks
            • Lấy report task PENDING tiếp theo
            • Cập nhật status của report task
            • Lấy danh sách platforms có sẵn
            • Thống kê report tasks
            • Kích hoạt thực thi thủ công
          • Monitor
            • Thông tin tài nguyên hệ thống
          • System
            • Hello World
            • Health check
            • Đọc file log từ xa
            • Monitor worker status
          • Auth
            • Đăng nhập
            • Đăng ký tài khoản
          • User Management
            • Danh sách users có phân trang
            • Tạo user mới (Admin only)
            • Lấy tất cả users (không phân trang)
            • Lấy thông tin profile của user hiện tại
            • Tạo QR code TOTP cho 2FA
            • Xác thực TOTP để bật 2FA
            • Lấy user theo ID
            • Cập nhật thông tin user
            • Xóa user
            • Đổi mật khẩu user
          • Campaign Management
            • Danh sách campaigns có phân trang
            • Tạo campaign mới
            • Lấy tất cả campaigns
            • Thống kê tổng hợp campaigns
            • Xuất campaigns ra Excel
            • Lấy dữ liệu Negative SEO
            • Xuất dữ liệu Negative SEO ra Excel
            • Xuất Negative SEO theo IDs
            • Lấy dữ liệu Home Traffic
            • Xuất Home Traffic ra Excel
            • Xuất Home Traffic theo IDs
            • Lấy báo cáo campaigns (Public)
            • Lấy tất cả báo cáo campaigns (Public)
            • Lấy chi tiết campaign
            • Cập nhật campaign
            • Xóa campaign
            • Lấy campaigns đã fired theo type
          • Server Management
            • Danh sách servers có phân trang
            • Tạo server mới
            • Lấy tất cả servers
            • Lấy servers từ MongoDB
            • Báo cáo hiệu suất server
            • Thống kê health check
            • Thống kê task monitor
            • Lịch sử lỗi server
            • Thống kê lỗi server
            • Thay đổi trạng thái server
            • Xóa nhiều servers
            • Lấy server theo ID
            • Cập nhật server
            • Xóa server
            • Báo cáo servers (Public)
          • Project Management
            • Lấy tất cả projects
            • Tạo project mới
            • Lấy projects theo campaign
            • Cập nhật dữ liệu traffic
            • Cập nhật nhiều projects
            • Xóa nhiều projects
            • Lấy project theo ID
            • Cập nhật project
            • Cập nhật state của project
            • Cập nhật status của project
            • Tính lại chi tiết project
          • Task Management
            • Worker yêu cầu tasks
            • Reset task creation
          • Proxy Management
            • Danh sách proxies
            • Tạo proxy mới
            • Xóa tất cả proxies
            • Xuất proxies ra Excel
            • Tải template Excel mẫu
            • Tạo nhiều proxies
            • Import proxies từ Excel
            • Import từ tất cả providers
            • Xóa nhiều proxies
            • Lấy proxy theo ID
            • Cập nhật proxy
            • Xóa proxy
            • Toggle trạng thái proxy
          • Backup Proxy
            • Lấy danh sách backup proxies
            • Tạo backup proxy
            • Xóa nhiều backup proxies
            • Import từ Proxifly
            • Chạy health check
            • Lấy backup proxy theo ID
            • Cập nhật backup proxy
            • Xóa backup proxy
            • Test backup proxy
          • Proxy Providers
            • Lấy danh sách proxy providers
            • Tạo proxy provider
            • Xóa nhiều providers
            • Lấy provider theo ID
            • Cập nhật provider
            • Xóa provider
          • Proxy Packages
            • Lấy danh sách proxy packages
            • Tạo proxy package
            • Xóa nhiều packages
            • Lấy package theo ID
            • Cập nhật package
            • Xóa package
          • Profiles
            • Lấy profiles khả dụng (Public)
            • Lấy profile ngẫu nhiên (Public)
            • Danh sách profiles có phân trang
            • Phân tích profiles
            • Health check profiles
            • Tạo profile session
            • Lấy profile session
            • Cập nhật profile session
            • Xóa profile session
            • Đánh dấu profile đã dùng
            • Cập nhật nhiều profiles
            • Tạo nhiều profiles
            • Dọn dẹp sessions hết hạn
            • Dọn dẹp toàn diện
            • Tạo profile mới
            • Lấy profile theo ID
            • Cập nhật profile
            • Xóa profile
            • Thống kê profile
            • Sessions của profile (phân trang)
            • Report tasks của profile
            • Domains đã report bởi profile
            • Tasks theo domain của profile
            • Reset cooldown của profile
            • Test kết nối profile
            • Reset số lần đăng nhập thất bại
            • Ghi nhận đăng nhập thất bại
          • Keywords
            • Danh sách keywords
            • Tạo keyword mới
            • Xuất keywords ra Excel
            • Xác nhận fire keyword
            • Reset tất cả keywords
            • Lấy keyword theo ID
            • Cập nhật keyword
            • Xóa keyword
            • Reset keyword
            • Cập nhật status keyword
            • Kết quả SERP của keyword
          • Dashboard
            • Dữ liệu tổng hợp dashboard
            • Thống kê hệ thống
            • Thống kê traffic theo ID
            • Dữ liệu bảng biểu đồ traffic
            • Xuất báo cáo ra Excel
            • Lấy dữ liệu báo cáo
            • Cập nhật hàng loạt dashboard
            • Tính lại chi tiết projects (Admin only)
          • System Settings
            • Toggle Telegram notifications
            • Trạng thái Telegram notification
          • Activity Logs
            • Lấy activity logs
          • Locations
            • Lấy tất cả locations
            • Tạo location mới
            • Lấy location theo ID
            • Cập nhật location
            • Xóa location
          • Evidence
            • Kiểm tra evidence tồn tại
            • Kiểm tra evidence hàng loạt
            • Lấy evidence mới nhất
          • Files
            • Upload file
            • Download file
          • Server Hourly Reports
            • Lấy server hourly reports
          • Task Logs
            • Lấy task logs
          • Webhooks - Proxy
            • Lấy proxy cho task (Worker webhook)
            • Lấy proxies có thể rotate (Worker webhook)
            • Báo cáo kết quả proxy rotation (Worker webhook)
            • Lấy backup proxy (Worker webhook)
          • Webhooks - Profile
            • Lấy profiles (admin view, webhook)
            • Lấy profile ngẫu nhiên (Worker webhook)
            • Profiles khả dụng (webhook)
            • Lấy profile session (webhook)
            • Tạo profile session (webhook)
            • Đánh dấu profile đã dùng (webhook)
            • Lấy profile tags (webhook)
            • Lấy tất cả profile sessions (webhook)
          • Webhooks - Task
            • Cập nhật kết quả thực thi task (Worker webhook)
          • Webhooks - Search
            • Báo cáo domains đã click (webhook)
            • Lấy clicked domains (webhook)
            • Báo cáo domains (webhook)
            • Third party callback (webhook)
          • Webhooks - Logs
            • Lấy file logs (webhook)
            • Xóa nội dung log (webhook)
            • Kiểm tra IP address (webhook)
          • Webhooks - Keyword
            • Gửi kết quả SERP keyword (webhook)
          • Webhooks - Report
            • Cập nhật trạng thái report task (webhook)
          • Webhooks - CocCoc Token
            • Lấy CocCoc tokens (webhook)
            • Lock CocCoc token (webhook)
            • Unlock CocCoc token (webhook)
    • Schemas
      • LoginRequest
      • UpdateTask
      • WorkerStatus
      • StandardResponse
      • UserResponseDto
      • CreateTaskGroupRequest
      • HealthResponse
      • UserModel
      • CreateProxy
      • ErrorResponse
      • Pagination
      • CreateUserRequest
      • ReportTaskCreation
      • ErrorResponseFull
      • BulkDeleteRequest
      • UpdateUserRequest
      • CreateEmail
      • MessageResponse
      • UserResponse
      • PagingInfo
      • CreateMultipleSearchRequest
      • TrafficType
      • CampaignResponse
      • ProfileModel
      • CreateMultipleReportRequest
      • ServerResponse
      • CreateProfileRequest
      • UpdateReportStatusRequest
      • Task
      • BulkImportProfileReq
      • TestProxyRequest
      • TaskGroup
      • ProxyResponse
      • UpdateProfileRequest
      • CreateTask
      • UpdateTaskBody
      • KeywordResponse
      • CampaignModel
      • CreateSearch
      • TaskPaginatedResponse
      • LocationResponse
      • CreateCampaignRequest
      • ProxyTestResult
      • UpdateCampaignRequest
      • CreateReportTaskBody
      • BulkUpdateCampaignStatusReq
      • CreateEmailReportTaskBody
      • NegativeSeoData
      • BatchReportTaskItem
      • CreateProjectRequest
      • CreateReportTaskResponse
      • UpdateProjectRequest
      • BatchReportTaskResponse
      • ProjectModel
      • BulkUpdateProjectRequest
      • ReportTask
      • WorkerHandshakeRequest
      • UpdateReportTaskStatusBody
      • WorkerHandshakeResponse
      • UpdateReportTaskStatusResponse
      • WorkerHeartbeatPayload
      • PlatformsListResponse
      • WorkerGlobalSettings
      • ReportTaskStatsResponse
      • TaskPullRequest
      • ExecuteReportTaskResponse
      • WorkerFatalLog
      • CreateSearchTask
      • TaskModel
      • Proxy
      • TaskUpdateDto
      • CreateProxyBody
      • ReportTaskModel
      • CreateProxyResponse
      • ReportTaskResult
      • ResetProcessResponse
      • PCReportResponse
      • MonitorResponse
      • ReportSiteItem
      • CreateReportSiteRequest
      • TestProxyResponse
      • GPTConfig
      • TestProfileResponse
      • ResponseConfig
      • ReportDomainsResponse
      • ReportDomainItem
      • AddReportDomainRequest
      • UpdateReportDomainRequest
      • BulkUpdateDashboardRequest
      • ProxyModel
      • CreateProxyRequest
      • UpdateProxyRequest
      • SMTPServerConfig
      • EmailTaskLog
      • GeoLocation
      • CampaignConfigs
      • ProjectAttribute
      • TaskTrafficType
      • ReportTaskItem
      • SummaryStats
      • DailyStats
      • BrandStats
      • ProfileStats
      • FieldConfig
  1. Deployment

Staging

Tài Liệu Triển Khai Môi Trường Staging — Admin Dashboard Traffic Tools V2#


1. Tổng Quan Môi Trường Staging#

Môi trường Staging là khu vực kiểm thử trước khi đưa tính năng lên Production. Đặc điểm phân biệt với môi trường Local:
Frontend được build tĩnh (minified, chunked) và phục vụ bởi Nginx, không chạy trực tiếp trên Node.js dev server.
Source map bị loại bỏ để bảo vệ mã nguồn.
Kết nối với Backend API Engine thuộc nhánh staging, dữ liệu hoàn toàn tách biệt với môi trường Local.
Build diễn ra trực tiếp trên server (on-server build) thay vì build trên máy CI runner rồi push image.

2. Cấu Trúc Pipeline CI/CD#

2.1. Các Stage Trong .gitlab-ci.yml#

2.2. Điều Kiện Kích Hoạt#

StageNhánh GitMôi Trường
deploy-developdevelopServer Develop
deploy-stagingstagingServer Staging
deploy-releasereleaseServer Release (AWS EC2)
build-mastermasterBastion Build Server
deploy-mastermasterServer Production (AWS EC2)

3. Triển Khai Môi Trường Develop#

3.1. Cấu Hình#

3.2. Quy Trình Tự Động#

Khi có commit mới vào nhánh develop, pipeline thực hiện các bước sau trên server Develop:
Bước 1 — Xác thực SSH:
GitLab Runner giải mã SSH private key từ biến CI/CD TRAFFIC_DEV_77_37_47_88_KEY (được lưu dạng base64) và nạp vào SSH agent.
Bước 2 — Kết nối SSH đến server và thực thi script:
Bước 3 — Docker Compose Build:
Lệnh docker compose up --build -d thực hiện:
Đọc file docker-compose.yml trong thư mục deploy.
Build Docker image mới từ Dockerfile, bao gồm: cài đặt Node.js dependencies, chạy npm run build:dev, copy output vào Nginx container.
Khởi động container mới với image vừa build.
Chạy ở chế độ detached (-d).
Bước 4 — Restart Nginx:
docker container restart nginx-service khởi động lại Nginx để áp dụng cấu hình mới và phục vụ file tĩnh mới nhất.
Bước 5 — Dọn dẹp:
docker image prune -f xóa tất cả Docker image không được sử dụng bởi bất kỳ container nào. Ngăn ổ cứng server bị đầy do tích lũy image cũ.

4. Triển Khai Môi Trường Staging#

4.1. Cấu Hình#

4.2. Quy Trình Tự Động#

Quy trình tương tự Develop, nhưng:
Kết nối đến cùng server (TRAFFIC_DEV_77_37_47_88_*) nhưng thư mục deploy khác (/stg/ thay vì /dev/).
Checkout nhánh staging thay vì develop.
Sử dụng repository riêng cho môi trường Staging.

4.3. Sự Khác Biệt Giữa Develop Và Staging#

Khía CạnhDevelopStaging
Nhánh Gitdevelopstaging
Thư mục deploy/home/traffic/project/traffic/dev/admin/home/traffic/project/traffic/stg/admin
Repositorydevops/develop/traffic/admin.gitdevops/staging/traffic/admin.git
Mục đíchKiểm thử tính năng đang phát triểnKiểm thử UAT trước khi release
Dữ liệuDữ liệu test của developerDữ liệu test gần với production

5. Triển Khai Môi Trường Release#

5.1. Cấu Hình#

5.2. Điểm Khác Biệt So Với Staging#

Môi trường Release chạy trên AWS EC2, do đó pipeline cần thêm bước lấy địa chỉ IP động:
Kỹ thuật lấy IP qua AWS tag thay vì hardcode IP giúp pipeline hoạt động đúng ngay cả khi EC2 instance bị thay thế hoặc IP thay đổi.

6. Cấu Hình Nginx Trong Container#

6.1. Cấu Hình SPA Fallback#

Vì Admin Dashboard sử dụng HTML5 History Mode, Nginx cần cấu hình try_files để xử lý SPA routing:
Không có cấu hình này, khi người dùng làm mới trang tại URL như /system-management/proxy-management, Nginx sẽ tìm file vật lý tương ứng và trả về 404.

6.2. Cấu Hình Cache#


7. Dockerfile Cho Môi Trường Development/Staging#

Lưu ý: Dockerfile này sử dụng npm run preview (Vite preview server) thay vì Nginx thuần túy. Đây là cách tiếp cận đơn giản cho môi trường non-production.

8. Xử Lý Sự Cố Triển Khai#

8.1. Pipeline Thất Bại Do Lỗi SSH#

Triệu chứng: Pipeline báo lỗi Permission denied (publickey).
Kiểm tra:
Biến CI/CD TRAFFIC_DEV_77_37_47_88_KEY có được cấu hình đúng không.
Public key tương ứng có được thêm vào ~/.ssh/authorized_keys trên server không.
Lệnh decode base64 có hoạt động đúng không: echo "$KEY" | base64 -d | tr -d '\r'.

8.2. Pipeline Thất Bại Do Lỗi Docker Build#

Triệu chứng: Lỗi trong bước docker compose up --build.
Đăng nhập SSH vào server và thực hiện:

8.3. Lỗi npm install Trong Docker Build#

Triệu chứng: npm install thất bại do lỗi mạng hoặc registry timeout.
Giải pháp:
Hoặc cấu hình npm registry mirror trong Dockerfile:

8.4. Kiểm Tra Cấu Hình Nginx Trong Container#

Để xem file cấu hình và biến môi trường đang được áp dụng:
Nếu runtime.config.js trỏ về sai địa chỉ API, cần sửa file public/runtime.config.js trong mã nguồn và deploy lại. Không sửa trực tiếp trong container vì thay đổi sẽ mất khi container restart.

8.5. Ổ Cứng Server Đầy#

Triệu chứng: Docker build thất bại với lỗi no space left on device.
Giải pháp:

9. Quy Trình Triển Khai Thủ Công#

Trong trường hợp pipeline CI/CD gặp sự cố, có thể triển khai thủ công:

9.1. Kết Nối SSH Đến Server#

9.2. Cập Nhật Code Và Build#

9.3. Kiểm Tra Sau Khi Deploy#


10. Quy Trình Kiểm Thử Trên Staging#

10.1. Checklist Kiểm Thử Sau Deploy#

Sau mỗi lần deploy lên Staging, thực hiện kiểm tra theo checklist:
Kiểm tra cơ bản:
Truy cập URL Staging và trang đăng nhập hiển thị đúng.
Đăng nhập với tài khoản test thành công.
Trang reportDaily hiển thị dữ liệu.
Sidebar menu hiển thị đầy đủ các mục.
Breadcrumb cập nhật đúng khi chuyển trang.
Kiểm tra tính năng mới:
Thực hiện các test case cho tính năng vừa được deploy.
Kiểm tra các tính năng liên quan có bị ảnh hưởng không (regression testing).
Kiểm tra kỹ thuật:
DevTools → Console → Không có lỗi JavaScript.
DevTools → Network → Không có request nào trả về 4xx hoặc 5xx.
Kiểm tra responsive trên màn hình 1280px và 1920px.

10.2. Quy Trình Báo Cáo Lỗi#

Khi phát hiện lỗi trên Staging:
Tạo issue trên GitLab với tiêu đề mô tả ngắn gọn.
Đính kèm screenshot hoặc video ghi lại lỗi.
Mô tả các bước tái hiện lỗi.
Đính kèm log từ DevTools Console và Network tab.
Gán issue cho developer phụ trách tính năng liên quan.

10.3. Môi Trường Staging Vs Production#

Khía CạnhStagingProduction
Phương thức buildOn-server build (Docker Compose)Pre-built image từ ECR
Kích thước imageLớn (bao gồm Node.js)Nhỏ (chỉ Nginx + file tĩnh)
Thời gian deploy5-10 phút (bao gồm npm install và build)1-2 phút (chỉ pull image và restart)
RollbackCần build lạiChỉ cần đổi tag image
Bảo mậtMã nguồn có trên serverKhông có mã nguồn trên server
Mục đíchKiểm thử tính năngPhục vụ người dùng thực tế

11. Quản Lý Nhánh Git Và Môi Trường#

11.1. Chiến Lược Nhánh#

Dự án sử dụng chiến lược nhánh theo môi trường:
NhánhMôi TrườngMục Đích
developDevelopTích hợp tính năng đang phát triển
stagingStagingKiểm thử UAT trước khi release
releaseReleaseKiểm thử cuối cùng trước production
masterProductionPhiên bản đang chạy cho người dùng thực tế

11.2. Quy Trình Merge#

feature/ten-tinh-nang
        |
        v (Merge Request)
    develop
        |
        v (Merge Request sau khi test xong)
    staging
        |
        v (Merge Request sau khi UAT xong)
    release
        |
        v (Merge Request sau khi kiểm thử cuối)
    master

11.3. Quy Tắc Bảo Vệ Nhánh#

Nhánh master, staging, release được bảo vệ (Protected Branch).
Không ai được push trực tiếp vào các nhánh này, phải qua Merge Request.
Merge Request cần ít nhất 1 approval từ Tech Lead hoặc Senior Developer.
Pipeline CI/CD phải pass trước khi được phép merge.

12. Tối Ưu Hóa Pipeline CI/CD#

12.1. Giảm Thời Gian Build#

Các kỹ thuật tối ưu thời gian build trên server:
Sử dụng npm ci thay vì npm install trong Dockerfile để cài đặt dependencies nhanh hơn và nhất quán hơn.
Cache node_modules giữa các lần build bằng Docker layer caching.
Sử dụng .dockerignore để loại trừ các file không cần thiết khỏi build context.
File .dockerignore:
node_modules
dist
.git
.gitignore
*.md
docs/

12.2. Parallel Jobs#

Nếu cần tăng tốc pipeline, có thể chạy các job song song:

12.3. Thông Báo Kết Quả Pipeline#

Cấu hình GitLab để gửi thông báo khi pipeline thành công hoặc thất bại:
Vào GitLab project → Settings → Integrations → Slack notifications.
Cấu hình Slack webhook URL.
Chọn các sự kiện cần thông báo: Pipeline succeeded, Pipeline failed.

13. Bảo Mật Môi Trường Staging#

13.1. Hạn Chế Truy Cập#

Môi trường Staging không nên được truy cập công khai. Các biện pháp bảo vệ:
Cấu hình Nginx với HTTP Basic Authentication để yêu cầu username/password khi truy cập.
Giới hạn IP được phép truy cập qua firewall hoặc Security Group của AWS.
Sử dụng VPN để chỉ cho phép truy cập từ mạng nội bộ của công ty.

13.2. Dữ Liệu Test#

Môi trường Staging nên sử dụng dữ liệu test, không phải dữ liệu production thực tế:
Tài khoản test với quyền hạn đầy đủ để kiểm thử mọi tính năng.
Dữ liệu proxy test (không phải proxy thực đang sử dụng).
Dữ liệu chiến dịch test với số lượng nhỏ.

13.3. Không Commit Thông Tin Nhạy Cảm#

Kiểm tra trước khi commit:
Không commit file .env.local hay bất kỳ file chứa thông tin nhạy cảm.
Không commit SSH key hay AWS credentials.
Sử dụng git-secrets hoặc detect-secrets để tự động phát hiện secret trong code.
Modified at 2026-03-27 04:37:32
Previous
Local
Next
Production
Built with