add
This commit is contained in:
0
code/common/db/options.go
Normal file
0
code/common/db/options.go
Normal file
0
code/common/db/postgres.go
Normal file
0
code/common/db/postgres.go
Normal file
11
code/common/go.mod
Normal file
11
code/common/go.mod
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
module code/common
|
||||||
|
|
||||||
|
go 1.25.7
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gin-gonic/gin v1.9.1
|
||||||
|
github.com/jmoiron/sqlx v1.3.5
|
||||||
|
github.com/redis/go-redis/v9 v9.3.0
|
||||||
|
go.uber.org/zap v1.26.0
|
||||||
|
github.com/lib/pq v1.10.9
|
||||||
|
)
|
||||||
0
code/common/go.sum
Normal file
0
code/common/go.sum
Normal file
0
code/common/logger/logger.go
Normal file
0
code/common/logger/logger.go
Normal file
0
code/common/middleware/cors.go
Normal file
0
code/common/middleware/cors.go
Normal file
0
code/common/redis/redis.go
Normal file
0
code/common/redis/redis.go
Normal file
0
code/common/utils/common.go
Normal file
0
code/common/utils/common.go
Normal file
4
code/deploy/postgres/init.sql
Normal file
4
code/deploy/postgres/init.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
-- PostgresSQL全局初始化脚本
|
||||||
|
-- 所有业务公共建库/建表语句写在这里,单独业务表建议在各自业务中处理
|
||||||
|
CREATE DATABASE IF NOT EXISTS monorepo;
|
||||||
|
\c monorepo;
|
||||||
8
code/deploy/redis/redis.conf
Normal file
8
code/deploy/redis/redis.conf
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Redis基础配置
|
||||||
|
bind 0.0.0.0
|
||||||
|
protected-mode no
|
||||||
|
port 6379
|
||||||
|
daemonize no
|
||||||
|
requirepass 123456
|
||||||
|
appendonly yes
|
||||||
|
appendfsync everysec
|
||||||
68
code/docker-compose.yml
Normal file
68
code/docker-compose.yml
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
version: '3.8'
|
||||||
|
services:
|
||||||
|
# 公共PostgresSQL
|
||||||
|
postgres:
|
||||||
|
image: postgres:18.1-alpine
|
||||||
|
container_name: trading-assistant-postgres
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: ${PG_USER:-root}
|
||||||
|
POSTGRES_PASSWORD: ${PG_PWD:-123456}
|
||||||
|
POSTGRES_DB: ${PG_DB:-monorepo}
|
||||||
|
ports:
|
||||||
|
- "${PG_PORT:-5432}:5432"
|
||||||
|
volumes:
|
||||||
|
- ./deploy/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
|
- pg_data:/var/lib/postgresql/data
|
||||||
|
networks:
|
||||||
|
- monorepo-net
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
# 公共Redis
|
||||||
|
redis:
|
||||||
|
image: redis:8.4.-alpine
|
||||||
|
container_name: trading-assistant-redis
|
||||||
|
ports:
|
||||||
|
- "${REDIS_PORT:-6379}:6379"
|
||||||
|
volumes:
|
||||||
|
- ./deploy/redis/redis.conf:/etc/redis/redis.conf
|
||||||
|
- redis_data:/data
|
||||||
|
command: redis-server /etc/redis/redis.conf
|
||||||
|
networks:
|
||||||
|
- monorepo-net
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
# 【业务服务模板】新增业务时复制以下块修改
|
||||||
|
# user:
|
||||||
|
# build:
|
||||||
|
# context: ./services/user
|
||||||
|
# dockerfile: Dockerfile
|
||||||
|
# container_name: trading-assistant-user
|
||||||
|
# environment:
|
||||||
|
# - GIN_MODE=release
|
||||||
|
# - PG_ADDR=postgres:5432
|
||||||
|
# - REDIS_ADDR=redis:6379
|
||||||
|
# ports:
|
||||||
|
# - "8080:8080"
|
||||||
|
# volumes:
|
||||||
|
# - ./logs/user:/app/logs
|
||||||
|
# networks:
|
||||||
|
# - monorepo-net
|
||||||
|
# restart: always
|
||||||
|
# depends_on:
|
||||||
|
# - postgres
|
||||||
|
# - redis
|
||||||
|
# deploy:
|
||||||
|
# resources:
|
||||||
|
# limits:
|
||||||
|
# cpus: "0.5"
|
||||||
|
# memory: "512M"
|
||||||
|
|
||||||
|
# 全局网络
|
||||||
|
networks:
|
||||||
|
monorepo-net:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
|
# 全局数据卷
|
||||||
|
volumes:
|
||||||
|
pg_data:
|
||||||
|
redis_data:
|
||||||
@@ -5,8 +5,8 @@ import sys
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# ===================== 可自定义配置(按需修改) =====================
|
# ===================== 可自定义配置(按需修改) =====================
|
||||||
PROJECT_ROOT = "go-monorepo" # 项目根目录名
|
PROJECT_ROOT = "code" # 项目根目录名
|
||||||
GO_VERSION = "1.21" # 团队统一Go版本
|
GO_VERSION = "1.25.7" # 团队统一Go版本
|
||||||
# ====================================================================
|
# ====================================================================
|
||||||
|
|
||||||
def create_dirs(base_path: Path):
|
def create_dirs(base_path: Path):
|
||||||
@@ -108,14 +108,15 @@ appendfsync everysec
|
|||||||
"""
|
"""
|
||||||
write_file(deploy_path / "redis/redis.conf", redis_conf)
|
write_file(deploy_path / "redis/redis.conf", redis_conf)
|
||||||
|
|
||||||
def generate_docker_compose(base_path: Path):
|
# 【修复】增加project_name参数,接收外部传入的项目名
|
||||||
|
def generate_docker_compose(base_path: Path, project_name: str):
|
||||||
"""生成根目录docker-compose.yml(聚合中间件+业务模板)"""
|
"""生成根目录docker-compose.yml(聚合中间件+业务模板)"""
|
||||||
compose_content = f"""version: '3.8'
|
compose_content = f"""version: '3.8'
|
||||||
services:
|
services:
|
||||||
# 公共PostgresSQL
|
# 公共PostgresSQL
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16-alpine
|
image: postgres:16-alpine
|
||||||
container_name: {PROJECT_ROOT}-postgres
|
container_name: {project_name}-postgres
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: ${{PG_USER:-root}}
|
POSTGRES_USER: ${{PG_USER:-root}}
|
||||||
POSTGRES_PASSWORD: ${{PG_PWD:-123456}}
|
POSTGRES_PASSWORD: ${{PG_PWD:-123456}}
|
||||||
@@ -132,7 +133,7 @@ services:
|
|||||||
# 公共Redis
|
# 公共Redis
|
||||||
redis:
|
redis:
|
||||||
image: redis:7-alpine
|
image: redis:7-alpine
|
||||||
container_name: {PROJECT_ROOT}-redis
|
container_name: {project_name}-redis
|
||||||
ports:
|
ports:
|
||||||
- "${{REDIS_PORT:-6379}}:6379"
|
- "${{REDIS_PORT:-6379}}:6379"
|
||||||
volumes:
|
volumes:
|
||||||
@@ -148,7 +149,7 @@ services:
|
|||||||
# build:
|
# build:
|
||||||
# context: ./services/user
|
# context: ./services/user
|
||||||
# dockerfile: Dockerfile
|
# dockerfile: Dockerfile
|
||||||
# container_name: {PROJECT_ROOT}-user
|
# container_name: {project_name}-user
|
||||||
# environment:
|
# environment:
|
||||||
# - GIN_MODE=release
|
# - GIN_MODE=release
|
||||||
# - PG_ADDR=postgres:5432
|
# - PG_ADDR=postgres:5432
|
||||||
@@ -275,8 +276,8 @@ def main():
|
|||||||
generate_common_module(base_path)
|
generate_common_module(base_path)
|
||||||
# 4. 生成部署资源文件
|
# 4. 生成部署资源文件
|
||||||
generate_deploy_files(base_path)
|
generate_deploy_files(base_path)
|
||||||
# 5. 生成Docker Compose
|
# 【修复】调用时传入PROJECT_ROOT作为project_name参数
|
||||||
generate_docker_compose(base_path)
|
generate_docker_compose(base_path, PROJECT_ROOT)
|
||||||
# 6. 生成全局配置(.env/Makefile)
|
# 6. 生成全局配置(.env/Makefile)
|
||||||
generate_global_config(base_path)
|
generate_global_config(base_path)
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ set -euo pipefail
|
|||||||
export LANG=C.UTF-8
|
export LANG=C.UTF-8
|
||||||
|
|
||||||
# 配置项(可按需修改)
|
# 配置项(可按需修改)
|
||||||
PROJECT_NAME="go-monorepo"
|
PROJECT_NAME="code"
|
||||||
PYTHON_IMAGE="python:3.11-alpine" # 轻量Python3镜像,仅80+MB
|
PYTHON_IMAGE="python:3.11-alpine" # 轻量Python3镜像,仅80+MB
|
||||||
PYTHON_SCRIPT="init_monorepo.py"
|
PYTHON_SCRIPT="init_monorepo.py"
|
||||||
|
|
||||||
Reference in New Issue
Block a user