mirror of
https://github.com/veops/oneterm.git
synced 2025-09-26 19:31:14 +08:00
feat(deploy): add development environment startup script
This commit is contained in:
278
deploy/DEV_README.md
Normal file
278
deploy/DEV_README.md
Normal file
@@ -0,0 +1,278 @@
|
||||
# OneTerm Development Environment Setup Guide
|
||||
|
||||
> **Language**: [English](DEV_README.md) | [中文](DEV_README.zh.md)
|
||||
|
||||
This guide helps developers quickly set up OneTerm's development environment for independent frontend and backend development.
|
||||
|
||||
## Environment Options
|
||||
|
||||
### 🎨 Frontend Development Environment
|
||||
**For**: Vue.js frontend development, UI debugging, frontend feature development
|
||||
- **Containers**: MySQL, Redis, ACL-API, Guacd, OneTerm-API (optional)
|
||||
- **Local**: Frontend project
|
||||
|
||||
### ⚙️ Backend Development Environment
|
||||
**For**: Go backend development, API development, protocol connector development
|
||||
- **Containers**: MySQL, Redis, ACL-API, Guacd, OneTerm-UI
|
||||
- **Local**: Backend project
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Prerequisites
|
||||
- Docker & Docker Compose
|
||||
- Node.js 14.17.6+ (for frontend development)
|
||||
- Go 1.21.3+ (for backend development)
|
||||
- Git
|
||||
|
||||
### 1. Clone the Project
|
||||
```bash
|
||||
git clone <your-repo-url>
|
||||
cd oneterm
|
||||
```
|
||||
|
||||
### 2. Choose Your Development Environment
|
||||
|
||||
#### 🎨 Frontend Development Environment
|
||||
|
||||
1. **Start Backend Dependencies**
|
||||
```bash
|
||||
cd deploy
|
||||
# Start necessary backend services
|
||||
docker compose -f docker-compose.frontend-dev.yaml up -d
|
||||
|
||||
# Check service status
|
||||
docker compose -f docker-compose.frontend-dev.yaml ps
|
||||
```
|
||||
|
||||
2. **Run Frontend Locally**
|
||||
```bash
|
||||
cd oneterm-ui
|
||||
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Start development server
|
||||
npm run serve
|
||||
```
|
||||
|
||||
3. **Access the Application**
|
||||
- Frontend dev server: http://localhost:8080
|
||||
- OneTerm API: http://localhost:18888
|
||||
- ACL API: http://localhost:15000
|
||||
|
||||
#### ⚙️ Backend Development Environment
|
||||
|
||||
1. **Start Frontend and Dependencies**
|
||||
```bash
|
||||
cd deploy
|
||||
# Start frontend and necessary services
|
||||
docker compose -f docker-compose.backend-dev.yaml up -d
|
||||
|
||||
# Check service status
|
||||
docker compose -f docker-compose.backend-dev.yaml ps
|
||||
```
|
||||
|
||||
2. **Configure Backend**
|
||||
```bash
|
||||
cd backend/cmd/server
|
||||
# Copy development configuration (pre-configured for dev environment)
|
||||
cp ../../deploy/dev-config.example.yaml config.yaml
|
||||
```
|
||||
|
||||
3. **Run Backend Locally**
|
||||
```bash
|
||||
cd backend/cmd/server
|
||||
|
||||
# Install dependencies
|
||||
go mod tidy
|
||||
|
||||
# Run server
|
||||
go run main.go config.yaml
|
||||
```
|
||||
|
||||
4. **Access the Application**
|
||||
- Frontend UI: http://localhost:8666
|
||||
- Backend API: http://localhost:8888
|
||||
- SSH port: localhost:2222
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Frontend Development
|
||||
|
||||
```bash
|
||||
# Development
|
||||
cd oneterm-ui
|
||||
npm run serve # Start development server
|
||||
npm run lint # Code linting
|
||||
npm run lint:nofix # Check only without fixing
|
||||
npm test:unit # Run unit tests
|
||||
|
||||
# Build
|
||||
npm run build # Production build
|
||||
npm run build:preview # Preview build
|
||||
```
|
||||
|
||||
### Backend Development
|
||||
|
||||
```bash
|
||||
# Development
|
||||
cd backend/cmd/server
|
||||
go run main.go config.yaml # Run server
|
||||
|
||||
# Build and test
|
||||
cd backend
|
||||
go mod tidy # Update dependencies
|
||||
go build ./... # Build all packages
|
||||
go test ./... # Run tests
|
||||
|
||||
# Production build
|
||||
cd backend/cmd/server
|
||||
./build.sh # Build Linux binaries
|
||||
```
|
||||
|
||||
## Database Management
|
||||
|
||||
### Connection Info
|
||||
- **MySQL**: localhost:13306
|
||||
- **Username**: root
|
||||
- **Password**: 123456
|
||||
- **Databases**: oneterm, acl
|
||||
|
||||
### Common Operations
|
||||
```bash
|
||||
# Connect to MySQL
|
||||
mysql -h localhost -P 13306 -u root -p123456
|
||||
|
||||
# View databases
|
||||
show databases;
|
||||
use oneterm;
|
||||
show tables;
|
||||
|
||||
# Reset database (use with caution)
|
||||
cd deploy
|
||||
docker compose -f docker-compose.frontend-dev.yaml down -v
|
||||
docker compose -f docker-compose.frontend-dev.yaml up -d
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Port Conflicts
|
||||
If you encounter port conflicts, modify the port mappings in docker-compose files:
|
||||
```yaml
|
||||
ports:
|
||||
- "new-port:container-port"
|
||||
```
|
||||
|
||||
### Database Connection Failed
|
||||
1. Ensure MySQL container is started and healthy
|
||||
2. Check database connection parameters in config file
|
||||
3. Verify port mappings are correct
|
||||
|
||||
### Frontend Proxy Issues
|
||||
Check proxy configuration in `oneterm-ui/vue.config.js`:
|
||||
```javascript
|
||||
devServer: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:18888', // Ensure correct backend address
|
||||
changeOrigin: true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ACL Permission Issues
|
||||
1. Ensure ACL-API service is running normally
|
||||
2. Check if initialization is complete
|
||||
3. View container logs: `docker logs oneterm-acl-api-dev`
|
||||
|
||||
## Quick Start Script
|
||||
|
||||
Use the convenient startup script:
|
||||
|
||||
```bash
|
||||
cd deploy
|
||||
|
||||
# Frontend development mode
|
||||
./dev-start.sh frontend
|
||||
|
||||
# Backend development mode
|
||||
./dev-start.sh backend
|
||||
|
||||
# Full environment mode
|
||||
./dev-start.sh full
|
||||
|
||||
# Stop all services
|
||||
./dev-start.sh stop
|
||||
|
||||
# Show help
|
||||
./dev-start.sh help
|
||||
```
|
||||
|
||||
## Environment Cleanup
|
||||
|
||||
```bash
|
||||
# Stop development environment
|
||||
cd deploy
|
||||
docker compose -f docker-compose.frontend-dev.yaml down
|
||||
# or
|
||||
docker compose -f docker-compose.backend-dev.yaml down
|
||||
|
||||
# Clean all data (including database)
|
||||
docker compose -f docker-compose.frontend-dev.yaml down -v
|
||||
```
|
||||
|
||||
## Debugging Tips
|
||||
|
||||
### View Logs
|
||||
```bash
|
||||
# View all service logs
|
||||
docker compose -f docker-compose.frontend-dev.yaml logs
|
||||
|
||||
# View specific service logs
|
||||
docker compose -f docker-compose.frontend-dev.yaml logs mysql
|
||||
docker compose -f docker-compose.frontend-dev.yaml logs acl-api
|
||||
|
||||
# Follow logs in real-time
|
||||
docker compose -f docker-compose.frontend-dev.yaml logs -f
|
||||
```
|
||||
|
||||
### Enter Containers
|
||||
```bash
|
||||
# Enter MySQL container
|
||||
docker exec -it oneterm-mysql-dev bash
|
||||
|
||||
# Enter ACL-API container
|
||||
docker exec -it oneterm-acl-api-dev bash
|
||||
```
|
||||
|
||||
## Configuration Files
|
||||
|
||||
### Backend Configuration
|
||||
Use the development configuration template:
|
||||
```bash
|
||||
cd backend/cmd/server
|
||||
cp ../../deploy/dev-config.example.yaml config.yaml
|
||||
# Configuration is pre-configured for development environment
|
||||
```
|
||||
|
||||
### Frontend Configuration
|
||||
The frontend automatically proxies to the backend. For custom proxy settings, edit `oneterm-ui/vue.config.js`.
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork the project
|
||||
2. Create a feature branch: `git checkout -b feature/new-feature`
|
||||
3. Commit changes: `git commit -am 'Add new feature'`
|
||||
4. Push branch: `git push origin feature/new-feature`
|
||||
5. Create Pull Request
|
||||
|
||||
## Support
|
||||
|
||||
- Project Documentation: See README.md in project root
|
||||
- Issue Reporting: Create GitHub Issues
|
||||
- Development Discussion: Participate in project discussions
|
||||
|
||||
---
|
||||
|
||||
**Happy Coding! 🚀**
|
278
deploy/DEV_README.zh.md
Normal file
278
deploy/DEV_README.zh.md
Normal file
@@ -0,0 +1,278 @@
|
||||
# OneTerm 开发环境快速搭建指南
|
||||
|
||||
> **语言**: [English](DEV_README.md) | [中文](DEV_README.zh.md)
|
||||
|
||||
本指南帮助开发者快速搭建 OneTerm 的开发环境,支持前端和后端独立开发。
|
||||
|
||||
## 环境选择
|
||||
|
||||
### 🎨 前端开发环境
|
||||
适用于:Vue.js 前端开发、UI 调试、前端功能开发
|
||||
- 启动:MySQL、Redis、ACL-API、Guacd、OneTerm-API(可选)
|
||||
- 本地运行:前端项目
|
||||
|
||||
### ⚙️ 后端开发环境
|
||||
适用于:Go 后端开发、API 开发、协议连接器开发
|
||||
- 启动:MySQL、Redis、ACL-API、Guacd、OneTerm-UI
|
||||
- 本地运行:后端项目
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 前置要求
|
||||
- Docker & Docker Compose
|
||||
- Node.js 14.17.6+ (前端开发)
|
||||
- Go 1.21.3+ (后端开发)
|
||||
- Git
|
||||
|
||||
### 1. 克隆项目
|
||||
```bash
|
||||
git clone <your-repo-url>
|
||||
cd oneterm
|
||||
```
|
||||
|
||||
### 2. 选择你的开发环境
|
||||
|
||||
#### 🎨 前端开发环境
|
||||
|
||||
1. **启动后端依赖服务**
|
||||
```bash
|
||||
cd deploy
|
||||
# 启动必要的后端服务
|
||||
docker compose -f docker-compose.frontend-dev.yaml up -d
|
||||
|
||||
# 查看服务状态
|
||||
docker compose -f docker-compose.frontend-dev.yaml ps
|
||||
```
|
||||
|
||||
2. **本地运行前端**
|
||||
```bash
|
||||
cd oneterm-ui
|
||||
|
||||
# 安装依赖
|
||||
npm install
|
||||
|
||||
# 启动开发服务器
|
||||
npm run serve
|
||||
```
|
||||
|
||||
3. **访问应用**
|
||||
- 前端开发服务器: http://localhost:8080
|
||||
- OneTerm API: http://localhost:18888
|
||||
- ACL API: http://localhost:15000
|
||||
|
||||
#### ⚙️ 后端开发环境
|
||||
|
||||
1. **启动前端和依赖服务**
|
||||
```bash
|
||||
cd deploy
|
||||
# 启动前端和必要服务
|
||||
docker compose -f docker-compose.backend-dev.yaml up -d
|
||||
|
||||
# 查看服务状态
|
||||
docker compose -f docker-compose.backend-dev.yaml ps
|
||||
```
|
||||
|
||||
2. **配置后端**
|
||||
```bash
|
||||
cd backend/cmd/server
|
||||
# 复制开发环境配置文件(已预配置好开发环境)
|
||||
cp ../../deploy/dev-config.example.yaml config.yaml
|
||||
```
|
||||
|
||||
3. **本地运行后端**
|
||||
```bash
|
||||
cd backend/cmd/server
|
||||
|
||||
# 安装依赖
|
||||
go mod tidy
|
||||
|
||||
# 运行服务器
|
||||
go run main.go config.yaml
|
||||
```
|
||||
|
||||
4. **访问应用**
|
||||
- 前端界面: http://localhost:8666
|
||||
- 后端API: http://localhost:8888
|
||||
- SSH端口: localhost:2222
|
||||
|
||||
## 开发工作流
|
||||
|
||||
### 前端开发
|
||||
|
||||
```bash
|
||||
# 开发环境
|
||||
cd oneterm-ui
|
||||
npm run serve # 启动开发服务器
|
||||
npm run lint # 代码检查
|
||||
npm run lint:nofix # 仅检查不修复
|
||||
npm test:unit # 运行单元测试
|
||||
|
||||
# 构建
|
||||
npm run build # 生产构建
|
||||
npm run build:preview # 预览构建
|
||||
```
|
||||
|
||||
### 后端开发
|
||||
|
||||
```bash
|
||||
# 开发环境
|
||||
cd backend/cmd/server
|
||||
go run main.go config.yaml # 运行服务器
|
||||
|
||||
# 构建和测试
|
||||
cd backend
|
||||
go mod tidy # 更新依赖
|
||||
go build ./... # 构建所有包
|
||||
go test ./... # 运行测试
|
||||
|
||||
# 生产构建
|
||||
cd backend/cmd/server
|
||||
./build.sh # 构建 Linux 二进制文件
|
||||
```
|
||||
|
||||
## 数据库管理
|
||||
|
||||
### 连接信息
|
||||
- **MySQL**: localhost:13306
|
||||
- **用户名**: root
|
||||
- **密码**: 123456
|
||||
- **数据库**: oneterm, acl
|
||||
|
||||
### 常用操作
|
||||
```bash
|
||||
# 连接 MySQL
|
||||
mysql -h localhost -P 13306 -u root -p123456
|
||||
|
||||
# 查看数据库
|
||||
show databases;
|
||||
use oneterm;
|
||||
show tables;
|
||||
|
||||
# 重置数据库(谨慎使用)
|
||||
cd deploy
|
||||
docker compose -f docker-compose.frontend-dev.yaml down -v
|
||||
docker compose -f docker-compose.frontend-dev.yaml up -d
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
|
||||
### 端口冲突
|
||||
如果遇到端口冲突,修改 docker-compose 文件中的端口映射:
|
||||
```yaml
|
||||
ports:
|
||||
- "新端口:容器端口"
|
||||
```
|
||||
|
||||
### 数据库连接失败
|
||||
1. 确保 MySQL 容器已启动并健康
|
||||
2. 检查配置文件中的数据库连接参数
|
||||
3. 验证端口映射是否正确
|
||||
|
||||
### 前端代理问题
|
||||
检查 `oneterm-ui/vue.config.js` 中的代理配置:
|
||||
```javascript
|
||||
devServer: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:18888', // 确保指向正确的后端地址
|
||||
changeOrigin: true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### ACL 权限问题
|
||||
1. 确保 ACL-API 服务正常运行
|
||||
2. 检查初始化是否完成
|
||||
3. 查看容器日志: `docker logs oneterm-acl-api-dev`
|
||||
|
||||
## 清理环境
|
||||
|
||||
```bash
|
||||
# 停止开发环境
|
||||
cd deploy
|
||||
docker compose -f docker-compose.frontend-dev.yaml down
|
||||
# 或
|
||||
docker compose -f docker-compose.backend-dev.yaml down
|
||||
|
||||
# 清理所有数据(包括数据库)
|
||||
docker compose -f docker-compose.frontend-dev.yaml down -v
|
||||
```
|
||||
|
||||
## 调试技巧
|
||||
|
||||
### 查看日志
|
||||
```bash
|
||||
# 查看所有服务日志
|
||||
docker compose -f docker-compose.frontend-dev.yaml logs
|
||||
|
||||
# 查看特定服务日志
|
||||
docker compose -f docker-compose.frontend-dev.yaml logs mysql
|
||||
docker compose -f docker-compose.frontend-dev.yaml logs acl-api
|
||||
|
||||
# 实时跟踪日志
|
||||
docker compose -f docker-compose.frontend-dev.yaml logs -f
|
||||
```
|
||||
|
||||
### 进入容器
|
||||
```bash
|
||||
# 进入 MySQL 容器
|
||||
docker exec -it oneterm-mysql-dev bash
|
||||
|
||||
# 进入 ACL-API 容器
|
||||
docker exec -it oneterm-acl-api-dev bash
|
||||
```
|
||||
|
||||
## 快速启动脚本
|
||||
|
||||
使用便捷的启动脚本:
|
||||
|
||||
```bash
|
||||
cd deploy
|
||||
|
||||
# 前端开发模式
|
||||
./dev-start.sh frontend
|
||||
|
||||
# 后端开发模式
|
||||
./dev-start.sh backend
|
||||
|
||||
# 完整环境模式
|
||||
./dev-start.sh full
|
||||
|
||||
# 停止所有服务
|
||||
./dev-start.sh stop
|
||||
|
||||
# 显示帮助
|
||||
./dev-start.sh help
|
||||
```
|
||||
|
||||
## 配置文件
|
||||
|
||||
### 后端配置
|
||||
使用开发环境配置模板:
|
||||
```bash
|
||||
cd backend/cmd/server
|
||||
cp ../../deploy/dev-config.example.yaml config.yaml
|
||||
# 配置已预设好开发环境
|
||||
```
|
||||
|
||||
### 前端配置
|
||||
前端会自动代理到后端。如需自定义代理设置,编辑 `oneterm-ui/vue.config.js`。
|
||||
|
||||
## 贡献指南
|
||||
|
||||
1. Fork 项目
|
||||
2. 创建特性分支: `git checkout -b feature/new-feature`
|
||||
3. 提交更改: `git commit -am 'Add new feature'`
|
||||
4. 推送分支: `git push origin feature/new-feature`
|
||||
5. 创建 Pull Request
|
||||
|
||||
## 技术支持
|
||||
|
||||
- 项目文档: 查看项目根目录的 README.md
|
||||
- 问题反馈: 创建 GitHub Issue
|
||||
- 开发讨论: 参与项目讨论
|
||||
|
||||
---
|
||||
|
||||
**开发愉快! 🚀**
|
70
deploy/dev-config.example.yaml
Normal file
70
deploy/dev-config.example.yaml
Normal file
@@ -0,0 +1,70 @@
|
||||
# OneTerm Development Environment Configuration Example
|
||||
# Copy this file to your backend/cmd/server/ directory as config.yaml and modify as needed
|
||||
|
||||
# Debug mode for development
|
||||
mode: debug
|
||||
|
||||
# HTTP API server configuration
|
||||
http:
|
||||
host: 0.0.0.0
|
||||
port: 8888
|
||||
|
||||
# SSH server configuration
|
||||
ssh:
|
||||
host: 0.0.0.0
|
||||
port: 2222
|
||||
# SSH private key for the server (generate your own for production)
|
||||
privateKey: |
|
||||
-----BEGIN OPENSSH PRIVATE KEY-----
|
||||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
|
||||
QyNTUxOQAAACBg490b4zqumtizCyM4RWtzJnPEsPIInBFugk8+UCb8XgAAAKCc1yKrnNci
|
||||
qwAAAAtzc2gtZWQyNTUxOQAAACBg490b4zqumtizCyM4RWtzJnPEsPIInBFugk8+UCb8Xg
|
||||
AAAECvd1Yj+bQxyxJtU3PirLK68CD3MWqBv0/shlFKS6wmbWDj3RvjOq6a2LMLIzhFa3Mm
|
||||
c8Sw8gicEW6CTz5QJvxeAAAAGnJvb3RAbG9jYWxob3N0LmxvY2FsZG9tYWluAQID
|
||||
-----END OPENSSH PRIVATE KEY-----
|
||||
|
||||
# Guacamole daemon configuration (for RDP/VNC support)
|
||||
# Point to containerized guacd or localhost for development
|
||||
guacd:
|
||||
host: localhost # Change to 'localhost' for development environment
|
||||
port: 14822 # Mapped port for development (container port 4822 -> host 14822)
|
||||
|
||||
# MySQL database configuration
|
||||
# Point to containerized MySQL or localhost for development
|
||||
mysql:
|
||||
host: localhost # Change to 'localhost' for development environment
|
||||
port: 13306 # Mapped port for development (container port 3306 -> host 13306)
|
||||
user: root
|
||||
password: 123456
|
||||
|
||||
# Redis configuration
|
||||
# Point to containerized Redis or localhost for development
|
||||
redis:
|
||||
host: localhost # Change to 'localhost' for development environment
|
||||
port: 16379 # Mapped port for development (container port 6379 -> host 16379)
|
||||
password: ""
|
||||
|
||||
# Logging configuration
|
||||
log:
|
||||
level: debug # Use debug level for development
|
||||
format: json # json or text
|
||||
maxSize: 1 # Log file max size in MB
|
||||
consoleEnable: true # Enable console output
|
||||
|
||||
# Authentication and ACL configuration
|
||||
auth:
|
||||
acl:
|
||||
appId: 5867e079dfd1437e9ae07576ab24b391
|
||||
secretKey: 2qlTA4z@#KyigJLYHGrev?0WD6hjX*8E
|
||||
url: http://localhost:15000/api/v1 # Point to development ACL API port
|
||||
aes:
|
||||
key: thisis32bitlongpassphraseimusing # 32-character AES key
|
||||
iv: 0123456789abcdef # 16-character AES IV
|
||||
|
||||
# Secret key for JWT and other security features
|
||||
# IMPORTANT: Change this in production!
|
||||
secretKey: xW2FAUfgffjmerTEBXADmURDOQ43ojLN
|
||||
|
||||
# Session configuration
|
||||
session:
|
||||
replayDir: /replay/ # Directory for session recordings
|
227
deploy/dev-start.sh
Executable file
227
deploy/dev-start.sh
Executable file
@@ -0,0 +1,227 @@
|
||||
#!/bin/bash
|
||||
|
||||
# OneTerm Development Environment Startup Script
|
||||
# Usage: ./dev-start.sh [frontend|backend|full|stop]
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Color definitions
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Print colored messages
|
||||
print_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check Docker and Docker Compose
|
||||
check_requirements() {
|
||||
print_info "Checking environment requirements..."
|
||||
|
||||
if ! command -v docker &> /dev/null; then
|
||||
print_error "Docker is not installed or not in PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
|
||||
print_error "Docker Compose is not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_success "Environment check passed"
|
||||
}
|
||||
|
||||
# Wait for service startup
|
||||
wait_for_service() {
|
||||
local service_name=$1
|
||||
local max_attempts=30
|
||||
local attempt=1
|
||||
|
||||
print_info "Waiting for $service_name service to start..."
|
||||
|
||||
while [ $attempt -le $max_attempts ]; do
|
||||
if docker compose -f "$compose_file" ps | grep -q "healthy"; then
|
||||
print_success "$service_name service is ready"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo -n "."
|
||||
sleep 2
|
||||
((attempt++))
|
||||
done
|
||||
|
||||
print_error "$service_name service startup timeout"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Start frontend development environment
|
||||
start_frontend_dev() {
|
||||
print_info "Starting frontend development environment..."
|
||||
local compose_file="docker-compose.frontend-dev.yaml"
|
||||
|
||||
# Stop any existing services
|
||||
docker compose -f "$compose_file" down 2>/dev/null || true
|
||||
|
||||
# Start services
|
||||
print_info "Starting backend dependencies (MySQL, Redis, ACL-API, Guacd, OneTerm-API)..."
|
||||
docker compose -f "$compose_file" up -d
|
||||
|
||||
# Wait for services to be ready
|
||||
sleep 10
|
||||
|
||||
# Show service status
|
||||
print_info "Service status:"
|
||||
docker compose -f "$compose_file" ps
|
||||
|
||||
print_success "Frontend development environment started!"
|
||||
echo ""
|
||||
print_info "Next steps:"
|
||||
echo "1. cd ../oneterm-ui"
|
||||
echo "2. npm install (first time setup)"
|
||||
echo "3. npm run serve"
|
||||
echo ""
|
||||
print_info "Service access URLs:"
|
||||
echo "- OneTerm API: http://localhost:18888"
|
||||
echo "- ACL API: http://localhost:15000"
|
||||
echo "- MySQL: localhost:13306 (root/123456)"
|
||||
echo "- Redis: localhost:16379"
|
||||
}
|
||||
|
||||
# Start backend development environment
|
||||
start_backend_dev() {
|
||||
print_info "Starting backend development environment..."
|
||||
local compose_file="docker-compose.backend-dev.yaml"
|
||||
|
||||
# Stop any existing services
|
||||
docker compose -f "$compose_file" down 2>/dev/null || true
|
||||
|
||||
# Start services
|
||||
print_info "Starting frontend and dependencies (MySQL, Redis, ACL-API, Guacd, OneTerm-UI)..."
|
||||
docker compose -f "$compose_file" up -d
|
||||
|
||||
# Wait for services to be ready
|
||||
sleep 10
|
||||
|
||||
# Show service status
|
||||
print_info "Service status:"
|
||||
docker compose -f "$compose_file" ps
|
||||
|
||||
print_success "Backend development environment started!"
|
||||
echo ""
|
||||
print_info "Next steps:"
|
||||
echo "1. cd ../backend/cmd/server"
|
||||
echo "2. cp ../../../deploy/dev-config.example.yaml config.yaml"
|
||||
echo "3. go mod tidy (first time setup)"
|
||||
echo "4. go run main.go config.yaml"
|
||||
echo ""
|
||||
print_info "Service access URLs:"
|
||||
echo "- Frontend UI: http://localhost:8666 (admin/123456))
|
||||
echo "- MySQL: localhost:13306 (root/123456)"
|
||||
echo "- Redis: localhost:16379"
|
||||
echo "- ACL API: http://localhost:15000"
|
||||
}
|
||||
|
||||
# Start full environment
|
||||
start_full_dev() {
|
||||
print_info "Starting full development environment..."
|
||||
local compose_file="docker-compose.yaml"
|
||||
|
||||
# Stop any existing services
|
||||
docker compose -f "$compose_file" down 2>/dev/null || true
|
||||
|
||||
# Start all services
|
||||
print_info "Starting all services..."
|
||||
docker compose -f "$compose_file" up -d
|
||||
|
||||
# Wait for services to be ready
|
||||
sleep 15
|
||||
|
||||
# Show service status
|
||||
print_info "Service status:"
|
||||
docker compose -f "$compose_file" ps
|
||||
|
||||
print_success "Full development environment started!"
|
||||
echo ""
|
||||
print_info "Service access URLs:"
|
||||
echo "- OneTerm Application: http://localhost:8666 (admin/123456)"
|
||||
echo "- SSH Port: localhost:2222"
|
||||
echo "- MySQL: localhost:13306 (root/123456)"
|
||||
echo "- Redis: localhost:16379"
|
||||
}
|
||||
|
||||
# Stop all development environments
|
||||
stop_dev() {
|
||||
print_info "Stopping all development environments..."
|
||||
|
||||
# Stop various possible environments
|
||||
docker compose -f "docker-compose.frontend-dev.yaml" down 2>/dev/null || true
|
||||
docker compose -f "docker-compose.backend-dev.yaml" down 2>/dev/null || true
|
||||
docker compose -f "docker-compose.yaml" down 2>/dev/null || true
|
||||
|
||||
print_success "All development environments stopped"
|
||||
}
|
||||
|
||||
# Show usage help
|
||||
show_help() {
|
||||
echo "OneTerm Development Environment Management Script"
|
||||
echo ""
|
||||
echo "Usage: $0 [option]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " frontend Start frontend dev environment (local frontend, containerized backend deps)"
|
||||
echo " backend Start backend dev environment (local backend, containerized frontend and deps)"
|
||||
echo " full Start full environment (all services in containers)"
|
||||
echo " stop Stop all development environments"
|
||||
echo " help Show this help message"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 frontend # Frontend development mode"
|
||||
echo " $0 backend # Backend development mode"
|
||||
echo " $0 full # Full experience mode"
|
||||
echo " $0 stop # Stop all services"
|
||||
}
|
||||
|
||||
# Main function
|
||||
main() {
|
||||
case "${1:-help}" in
|
||||
"frontend")
|
||||
check_requirements
|
||||
start_frontend_dev
|
||||
;;
|
||||
"backend")
|
||||
check_requirements
|
||||
start_backend_dev
|
||||
;;
|
||||
"full")
|
||||
check_requirements
|
||||
start_full_dev
|
||||
;;
|
||||
"stop")
|
||||
stop_dev
|
||||
;;
|
||||
"help"|*)
|
||||
show_help
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Execute main function
|
||||
main "$@"
|
150
deploy/docker-compose.backend-dev.yaml
Normal file
150
deploy/docker-compose.backend-dev.yaml
Normal file
@@ -0,0 +1,150 @@
|
||||
# Docker Compose Configuration - Backend Development Environment
|
||||
# Start frontend and necessary containers, run backend locally
|
||||
|
||||
services:
|
||||
# MySQL Database
|
||||
mysql:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/mysql:8.2.0
|
||||
container_name: oneterm-mysql-dev
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
MYSQL_ROOT_PASSWORD: '123456'
|
||||
MYSQL_DATABASE: 'oneterm'
|
||||
volumes:
|
||||
- ./volume/mysql:/var/lib/mysql
|
||||
- ./mysqld.cnf:/etc/mysql/conf.d/mysqld.cnf
|
||||
- ./acl.sql:/docker-entrypoint-initdb.d/2-acl.sql
|
||||
- ./create-users.sql:/docker-entrypoint-initdb.d/1-create-users.sql
|
||||
ports:
|
||||
- "13306:3306"
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-P", "3306", "-u", "root", "-p123456"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
restart: always
|
||||
networks:
|
||||
new:
|
||||
aliases:
|
||||
- mysql
|
||||
|
||||
# Redis Cache
|
||||
redis:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/redis:7.2.3
|
||||
container_name: oneterm-redis-dev
|
||||
restart: always
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
ports:
|
||||
- "16379:6379"
|
||||
networks:
|
||||
new:
|
||||
aliases:
|
||||
- redis
|
||||
|
||||
# Guacamole Daemon (RDP/VNC Support)
|
||||
oneterm-guacd:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/oneterm-guacd:1.5.4
|
||||
container_name: oneterm-guacd-dev
|
||||
user: root
|
||||
restart: always
|
||||
volumes:
|
||||
- ./volume/replay:/replay
|
||||
- ./volume/rdp:/rdp
|
||||
healthcheck:
|
||||
test: ["CMD", "nc", "-z", "localhost", "4822"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
ports:
|
||||
- "14822:4822"
|
||||
networks:
|
||||
new:
|
||||
aliases:
|
||||
- oneterm-guacd
|
||||
|
||||
# ACL API Service
|
||||
acl-api:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/acl-api:2.2
|
||||
container_name: oneterm-acl-api-dev
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
WAIT_HOSTS: mysql:3306, redis:6379
|
||||
SYSTEM_DEFAULT_LANGUAGE: # en-US, zh-CN
|
||||
volumes:
|
||||
- ./.env:/data/apps/acl/.env
|
||||
restart: always
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
if [ ! -f /var/run/.initialized ]; then
|
||||
flask db-setup
|
||||
flask common-check-new-columns
|
||||
flask init-acl
|
||||
flask init-department
|
||||
touch /var/run/.initialized
|
||||
fi
|
||||
|
||||
nohup bash -c 'flask db-setup && flask common-check-new-columns' >/dev/null 2>&1 &
|
||||
|
||||
gunicorn --workers=3 autoapp:app -b 0.0.0.0:5000 -D --access-logfile logs/access.log --error-logfile logs/error.log
|
||||
|
||||
celery -A celery_worker.celery worker -E -Q acl_async --logfile=one_acl_async.log --autoscale=2,1
|
||||
healthcheck:
|
||||
test: ["CMD", "nc", "-z", "127.0.0.1", "5000"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
ports:
|
||||
- "15000:5000" # Expose port for local backend access
|
||||
networks:
|
||||
new:
|
||||
aliases:
|
||||
- acl-api
|
||||
|
||||
# Frontend UI Service
|
||||
oneterm-ui:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/oneterm-ui:v25.8.2
|
||||
container_name: oneterm-ui-dev
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
# Modified to local backend address
|
||||
ONETERM_API_HOST: "host.docker.internal:8888" # Point to local backend
|
||||
ACL_API_HOST: "acl-api:5000"
|
||||
NGINX_PORT: "80"
|
||||
volumes:
|
||||
- ./nginx.oneterm.conf.example:/etc/nginx/conf.d/nginx.oneterm.conf.example
|
||||
restart: always
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
envsubst '$$ONETERM_API_HOST $$ACL_API_HOST $$NGINX_PORT' < /etc/nginx/conf.d/nginx.oneterm.conf.example > /etc/nginx/conf.d/oneterm.conf
|
||||
nginx -g 'daemon off;'
|
||||
nginx -s reload
|
||||
networks:
|
||||
- new
|
||||
ports:
|
||||
- "8666:80"
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway" # Allow container to access host
|
||||
|
||||
networks:
|
||||
new:
|
||||
driver: bridge
|
||||
name: oneterm_dev_network
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.31.0.0/24
|
156
deploy/docker-compose.frontend-dev.yaml
Normal file
156
deploy/docker-compose.frontend-dev.yaml
Normal file
@@ -0,0 +1,156 @@
|
||||
# Docker Compose Configuration - Frontend Development Environment
|
||||
# Start necessary backend containers, run frontend locally
|
||||
|
||||
services:
|
||||
# MySQL Database
|
||||
mysql:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/mysql:8.2.0
|
||||
container_name: oneterm-mysql-dev
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
MYSQL_ROOT_PASSWORD: '123456'
|
||||
MYSQL_DATABASE: 'oneterm'
|
||||
volumes:
|
||||
- ./volume/mysql:/var/lib/mysql
|
||||
- ./mysqld.cnf:/etc/mysql/conf.d/mysqld.cnf
|
||||
- ./acl.sql:/docker-entrypoint-initdb.d/2-acl.sql
|
||||
- ./create-users.sql:/docker-entrypoint-initdb.d/1-create-users.sql
|
||||
ports:
|
||||
- "13306:3306"
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-P", "3306", "-u", "root", "-p123456"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
||||
restart: always
|
||||
networks:
|
||||
new:
|
||||
aliases:
|
||||
- mysql
|
||||
|
||||
# Redis Cache
|
||||
redis:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/redis:7.2.3
|
||||
container_name: oneterm-redis-dev
|
||||
restart: always
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
ports:
|
||||
- "16379:6379"
|
||||
networks:
|
||||
new:
|
||||
aliases:
|
||||
- redis
|
||||
|
||||
# Guacamole Daemon (RDP/VNC Support)
|
||||
oneterm-guacd:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/oneterm-guacd:1.5.4
|
||||
container_name: oneterm-guacd-dev
|
||||
user: root
|
||||
restart: always
|
||||
volumes:
|
||||
- ./volume/replay:/replay
|
||||
- ./volume/rdp:/rdp
|
||||
healthcheck:
|
||||
test: ["CMD", "nc", "-z", "localhost", "4822"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
ports:
|
||||
- "14822:4822"
|
||||
networks:
|
||||
new:
|
||||
aliases:
|
||||
- oneterm-guacd
|
||||
|
||||
# ACL API Service
|
||||
acl-api:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/acl-api:2.2
|
||||
container_name: oneterm-acl-api-dev
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
TZ: Asia/Shanghai
|
||||
WAIT_HOSTS: mysql:3306, redis:6379
|
||||
SYSTEM_DEFAULT_LANGUAGE: # en-US, zh-CN
|
||||
volumes:
|
||||
- ./.env:/data/apps/acl/.env
|
||||
restart: always
|
||||
command:
|
||||
- /bin/sh
|
||||
- -c
|
||||
- |
|
||||
if [ ! -f /var/run/.initialized ]; then
|
||||
flask db-setup
|
||||
flask common-check-new-columns
|
||||
flask init-acl
|
||||
flask init-department
|
||||
touch /var/run/.initialized
|
||||
fi
|
||||
|
||||
nohup bash -c 'flask db-setup && flask common-check-new-columns' >/dev/null 2>&1 &
|
||||
|
||||
gunicorn --workers=3 autoapp:app -b 0.0.0.0:5000 -D --access-logfile logs/access.log --error-logfile logs/error.log
|
||||
|
||||
celery -A celery_worker.celery worker -E -Q acl_async --logfile=one_acl_async.log --autoscale=2,1
|
||||
healthcheck:
|
||||
test: ["CMD", "nc", "-z", "127.0.0.1", "5000"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
ports:
|
||||
- "15000:5000" # Expose port for local backend access
|
||||
networks:
|
||||
new:
|
||||
aliases:
|
||||
- acl-api
|
||||
|
||||
# OneTerm API Service (optional, for complete backend environment)
|
||||
oneterm-api:
|
||||
image: registry.cn-hangzhou.aliyuncs.com/veops/oneterm-api:v25.8.2
|
||||
container_name: oneterm-api-dev
|
||||
environment:
|
||||
ONETERM_RDP_DRIVE_PATH: /rdp
|
||||
volumes:
|
||||
- ./volume/replay:/replay
|
||||
- ./volume/rdp:/rdp
|
||||
- ./config.yaml:/oneterm/config.yaml
|
||||
depends_on:
|
||||
oneterm-guacd:
|
||||
condition: service_healthy
|
||||
acl-api:
|
||||
condition: service_healthy
|
||||
healthcheck:
|
||||
test: ["CMD", "nc", "-z", "localhost", "8888"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
command:
|
||||
- "./server"
|
||||
- "config.yaml"
|
||||
restart: always
|
||||
networks:
|
||||
new:
|
||||
aliases:
|
||||
- oneterm-api
|
||||
tty: true
|
||||
ports:
|
||||
- "2222:2222" # SSH Port
|
||||
- "18888:8888" # API Port
|
||||
|
||||
networks:
|
||||
new:
|
||||
driver: bridge
|
||||
name: oneterm_dev_network
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.31.0.0/24
|
Reference in New Issue
Block a user