# fungo
**Repository Path**: cucy/fungo
## Basic Information
- **Project Name**: fungo
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-06-21
- **Last Updated**: 2025-06-21
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# FunGo E-commerce DevOps Project
This project implements the complete CI/CD pipeline for the FunGo e-commerce application, which consists of:
- `user-service`: A Go microservice for user management
- `order-service`: A Java Spring Boot microservice for order management
## Project Structure
```
ops/
├── terraform/ # Infrastructure as Code
├── ansible/ # Configuration Management
├── kubernetes/ # Kubernetes manifests & Helm charts
├── jenkins/ # Jenkins pipeline configuration
├── monitoring/ # Monitoring configurations
│ ├── grafana/ # Grafana dashboards
│ ├── prometheus/ # Prometheus configuration and rules
│ ├── alertmanager/ # Alertmanager configuration
│ └── kubernetes/ # Kubernetes deployment manifests
└── services/ # Application source code
├── user-service/ # User service (Go)
└── order-service/ # Order service (Java)
```
## Prerequisites
- Alibaba Cloud account with appropriate permissions
- Terraform installed
- Ansible installed
- kubectl installed
- Helm installed
- Docker installed
- Git installed
## Step-by-Step Implementation
### 1. Infrastructure Provisioning with Terraform
```bash
cd terraform
# Initialize Terraform
terraform init
# Create terraform.tfvars file with necessary variables
cat << EOF > terraform.tfvars
redis_password = "your-secure-password"
mysql_root_password = "your-secure-mysql-password"
EOF
# Plan the deployment
terraform plan -var-file=terraform.tfvars -out=tfplan
# Apply the plan to create infrastructure
terraform apply tfplan
# Save Kubernetes config
terraform output -raw k8s_kube_config > ~/.kube/config
```
### 2. Configure Servers with Ansible
```bash
cd ../ansible
# Update hosts file with actual IPs of your servers
# Then run the playbook
ansible-playbook -i hosts setup.yml
```
### 3. Set up Kubernetes Namespaces
```bash
cd ../kubernetes
kubectl apply -f namespaces.yaml
```
### 4. Building and Deploying Services
#### User Service (Go)
```bash
cd ../services/user-service
# Build the Docker image
docker build -t registry.cn-beijing.aliyuncs.com/fungo/user-service:v1.0.0 .
# Push the image to ACR
docker push registry.cn-beijing.aliyuncs.com/fungo/user-service:v1.0.0
# Deploy to Kubernetes using Helm
cd ../../kubernetes
helm upgrade --install user-service-staging ./charts/user-service \
--namespace staging \
--set image.tag=v1.0.0
```
#### Order Service (Java)
```bash
cd ../services/order-service
# Build the Docker image
docker build -t registry.cn-beijing.aliyuncs.com/fungo/order-service:v1.0.0 .
# Push the image to ACR
docker push registry.cn-beijing.aliyuncs.com/fungo/order-service:v1.0.0
# Deploy to Kubernetes using Helm
cd ../../kubernetes
helm upgrade --install order-service-staging ./charts/order-service \
--namespace staging \
--set image.tag=v1.0.0 \
--set userServiceEnvironment=staging
```
### 5. Setting up Jenkins Pipeline
```bash
cd ../jenkins
# Create a Multibranch Pipeline job in Jenkins
# Configure the job to use the Git repository URL
# Add the Jenkinsfile path to the configuration
```
### 6. Test the Services
```bash
# Port-forward the services to localhost
kubectl port-forward -n staging svc/user-service-staging 8081:8080
kubectl port-forward -n staging svc/order-service-staging 8080:8080
# Test the user service
curl http://localhost:8081/users/user1
# Test the order service
curl http://localhost:8080/api/v1/users/user1/orders
```
### 7. Monitoring and Observability
#### Deploy the Monitoring Stack
```bash
# Create the monitoring namespace if not already created
kubectl create namespace monitoring
# Deploy Prometheus, Alertmanager, and Grafana
kubectl apply -f monitoring/kubernetes/prometheus-deployment.yaml
kubectl apply -f monitoring/kubernetes/alertmanager-deployment.yaml
kubectl apply -f monitoring/kubernetes/grafana-deployment.yaml
kubectl apply -f monitoring/kubernetes/grafana-dashboards.yaml
# Port-forward Prometheus
kubectl port-forward -n monitoring svc/prometheus 9090:9090
# Port-forward Grafana
kubectl port-forward -n monitoring svc/grafana 3000:3000
# Port-forward Alertmanager
kubectl port-forward -n monitoring svc/alertmanager 9093:9093
```
#### Access the Monitoring Services
- **Prometheus**: http://localhost:9090
- View metrics, execute queries, and check alert status
- **Grafana**: http://localhost:3000 (default login: admin/admin)
- Pre-configured dashboards:
- FunGo E-commerce Overview: Overall system health and performance
- User Service Dashboard: Detailed metrics for the user-service
- Order Service Dashboard: Detailed metrics for the order-service including JVM stats
- **Alertmanager**: http://localhost:9093
- View and manage alerts
#### Alert Notifications
The monitoring system is configured to send alerts to:
- Slack channels (#monitoring, #critical-alerts, #warning-alerts)
- DingTalk for critical alerts
- Service-specific team channels (#user-service-team, #order-service-team)
To configure actual notification endpoints:
1. Edit `monitoring/alertmanager/alertmanager.yml` to add your Slack webhooks and DingTalk tokens
2. Apply the updated configuration:
```bash
kubectl apply -f monitoring/kubernetes/alertmanager-deployment.yaml
```
### 6. CI/CD流程图
下图展示了项目的CI/CD流水线流程:
```mermaid
graph TD
A[代码提交/PR] --> B[自动化代码检查]
B --> C[单元测试]
C --> D[构建 Docker 镜像]
D --> E[镜像安全扫描]
E --> F[推送到镜像仓库]
F --> G[部署到测试环境]
G --> H[自动化 API 测试]
H --> I{人工审核}
I -->|批准| J[部署到生产环境]
I -->|拒绝| K[修复问题]
K --> A
J --> L[监控服务健康]
```
### 7. 系统架构图
下图展示了FunGo电商系统的整体架构:
```mermaid
graph TD
subgraph "FunGo电商系统架构"
Client[客户端] --> ALB[阿里云负载均衡]
ALB --> API[API网关]
subgraph "微服务"
API --> UserService[用户服务
Go]
API --> OrderService[订单服务
Java Spring Boot]
OrderService --> UserService
end
subgraph "数据存储"
UserService --> Redis[(Redis缓存)]
OrderService --> MySQL[(MySQL数据库)]
end
subgraph "DevOps"
Jenkins[Jenkins CI/CD] --> DockerRegistry[Docker镜像仓库]
DockerRegistry --> K8s[Kubernetes集群]
K8s --> UserService
K8s --> OrderService
end
subgraph "监控系统"
Prometheus[Prometheus] --> UserService
Prometheus --> OrderService
Prometheus --> Alertmanager[Alertmanager]
Grafana[Grafana] --> Prometheus
end
subgraph "日志系统"
Fluentd[Fluentd] --> UserService
Fluentd --> OrderService
Fluentd --> Elasticsearch[Elasticsearch]
Kibana[Kibana] --> Elasticsearch
end
end
```
### 8. 故障排除
以下是常见问题及解决方案:
| 问题 | 可能原因 | 解决方案 |
|------|---------|---------|
| 用户服务无法访问 | Redis连接失败 | 检查Redis实例健康状态和网络连接 |
| 订单服务无法创建订单 | 用户服务不可用 | 确认用户服务状态和服务间网络通信 |
| 监控告警频繁触发 | 资源不足或错误阈值设置 | 优化资源分配或调整告警阈值 |
| 服务部署失败 | 镜像拉取问题或配置错误 | 检查容器镜像、网络和配置 |
| 数据库连接超时 | 连接池配置或网络延迟 | 调整连接池参数或检查网络性能 |
**快速恢复步骤:**
1. **服务重启**: `kubectl rollout restart deployment -n `
2. **日志检查**: 使用Kibana搜索相关错误或使用`kubectl logs`命令
3. **配置验证**: `kubectl describe configmap -n `
4. **网络诊断**: `kubectl exec -it -- curl `
### 9. 开发工作流
本项目采用以下开发工作流程:
#### 分支策略
- **main**: 生产环境分支,只接受来自release分支的合并
- **develop**: 开发主分支,功能开发完成后合并到此分支
- **feature/xxx**: 功能分支,从develop分支创建
- **hotfix/xxx**: 紧急修复分支,从main分支创建
- **release/x.y.z**: 版本发布分支,从develop分支创建
#### 代码提交规范
提交信息格式:
```
():