- Renamed auth-service to iam-service across various files for consistency. - Updated Dockerfiles, deployment configurations, and documentation to reflect the service name change. - Enhanced testing commands in documentation to point to the new iam-service. - Removed outdated auth-service files and configurations to streamline the project structure. - Improved bilingual documentation for clarity on the new service structure and usage.
107 lines
2.7 KiB
Markdown
107 lines
2.7 KiB
Markdown
# Hướng Dẫn Deployment
|
|
|
|
## Thiết Lập Database (Neon)
|
|
|
|
Tất cả môi trường sử dụng **Neon PostgreSQL**. Thiết lập một lần trước khi deploy:
|
|
|
|
1. Tạo Neon project tại https://neon.tech
|
|
2. Tạo branches: `main` (dev), `staging`, `production`
|
|
3. Lấy connection strings cho mỗi branch
|
|
4. Cấu hình trong environment variables (xem bên dưới)
|
|
|
|
Xem [Hướng Dẫn Thiết Lập Neon](../../infra/databases/neon/README.md) để biết chi tiết.
|
|
|
|
## Local Deployment
|
|
|
|
```bash
|
|
# Setup Neon database URL
|
|
cp deployments/local/env.local.example deployments/local/.env.local
|
|
# Chỉnh sửa .env.local và thêm Neon DATABASE_URL của bạn
|
|
|
|
# Khởi động services (không cần PostgreSQL container)
|
|
cd deployments/local
|
|
docker-compose up -d
|
|
```
|
|
|
|
## Staging Deployment
|
|
|
|
### Yêu Cầu
|
|
- Quyền truy cập Kubernetes cluster
|
|
- kubectl đã cấu hình
|
|
- KUBECONFIG đã set
|
|
- Neon staging branch đã tạo
|
|
- GitHub Secrets đã cấu hình:
|
|
- `NEON_DATABASE_URL_STAGING`
|
|
- `KUBECONFIG_STAGING`
|
|
|
|
### Thiết Lập Secrets
|
|
|
|
```bash
|
|
# Tạo Kubernetes secret
|
|
kubectl create secret generic iam-service-secrets \
|
|
--from-literal=database-url='postgresql://user:pass@ep-xxx.region.neon.tech/dbname?sslmode=require&pgbouncer=true' \
|
|
--from-literal=jwt-secret='your-staging-jwt-secret' \
|
|
--from-literal=jwt-refresh-secret='your-staging-refresh-secret' \
|
|
-n staging
|
|
```
|
|
|
|
### Deploy
|
|
|
|
```bash
|
|
./scripts/deploy/deploy-staging.sh
|
|
```
|
|
|
|
Hoặc thủ công:
|
|
```bash
|
|
kubectl apply -f deployments/staging/kubernetes/
|
|
```
|
|
|
|
**Lưu ý**: Migrations chạy tự động trong CI/CD trước khi deployment.
|
|
|
|
## Production Deployment
|
|
|
|
### Yêu Cầu
|
|
- Production Kubernetes cluster
|
|
- kubectl đã cấu hình với production context
|
|
- Neon production branch đã tạo
|
|
- GitHub Secrets đã cấu hình:
|
|
- `NEON_DATABASE_URL_PRODUCTION`
|
|
- `KUBECONFIG_PRODUCTION`
|
|
|
|
### Thiết Lập Secrets
|
|
|
|
```bash
|
|
# Tạo Kubernetes secret
|
|
kubectl create secret generic iam-service-secrets \
|
|
--from-literal=database-url='postgresql://user:pass@ep-xxx.region.neon.tech/dbname?sslmode=require&pgbouncer=true' \
|
|
--from-literal=jwt-secret='your-production-jwt-secret' \
|
|
--from-literal=jwt-refresh-secret='your-production-refresh-secret' \
|
|
-n production
|
|
```
|
|
|
|
### Deploy
|
|
|
|
```bash
|
|
./scripts/deploy/deploy-prod.sh
|
|
```
|
|
|
|
**Lưu ý**: Migrations chạy tự động trong CI/CD trước khi deployment (cần approval).
|
|
|
|
### Rollback
|
|
|
|
```bash
|
|
kubectl rollout undo deployment/iam-service -n production
|
|
```
|
|
|
|
## Health Checks
|
|
|
|
- Liveness: `GET /health/live`
|
|
- Readiness: `GET /health/ready`
|
|
- Health: `GET /health`
|
|
|
|
## Monitoring
|
|
|
|
- Prometheus: http://prometheus:9090
|
|
- Grafana: http://grafana:3000
|
|
- Traefik Dashboard: http://traefik:8080
|