From 507d8c6fd9c38f0921a349e8930b540aea01aa3e Mon Sep 17 00:00:00 2001 From: zetaloop Date: Wed, 1 Apr 2026 03:45:11 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=9C=AC=E5=9C=B0=E5=BC=80=E5=8F=91=20c?= =?UTF-8?q?ompose=20=E7=BC=96=E6=8E=92=E3=80=81=E6=9E=84=E5=BB=BA=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E4=B8=8E=E6=95=B0=E6=8D=AE=E5=BA=93=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 14 ++ .gitignore | 7 +- deploy/dev/.env | 32 ++++ deploy/dev/README.md | 62 +++++++ deploy/dev/build.sh | 45 +++++ deploy/dev/docker-compose.yml | 306 ++++++++++++++++++++++++++++++++++ deploy/dev/init-db.sh | 36 ++++ 7 files changed, 501 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 deploy/dev/.env create mode 100644 deploy/dev/README.md create mode 100755 deploy/dev/build.sh create mode 100644 deploy/dev/docker-compose.yml create mode 100755 deploy/dev/init-db.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4393bd1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +.git +.idea +.serena +.sisyphus +node_modules +deploy +backup +docs +*.log + +# Go compiled binaries +app/*/api/api +app/*/rpc/rpc +app/*/mq/mq diff --git a/.gitignore b/.gitignore index af7bba3..cc49eaa 100644 --- a/.gitignore +++ b/.gitignore @@ -120,4 +120,9 @@ dist # End of https://mrkandreev.name/snippets/gitignore-generator/#Node DockerFile -.idea \ No newline at end of file +.idea + +# Go compiled binaries +app/*/api/api +app/*/rpc/rpc +app/*/mq/mq \ No newline at end of file diff --git a/deploy/dev/.env b/deploy/dev/.env new file mode 100644 index 0000000..65b2ada --- /dev/null +++ b/deploy/dev/.env @@ -0,0 +1,32 @@ +# PostgreSQL +PD_USERNAME=postgres +DB_PASSWORD=123456 +DB_PORT=5432 +DB_NAME=app +DB_URI=postgresql://postgres:123456@postgres:5432/app + +# Redis +REDIS_HOST=redis +REDIS_PORT=6379 +REDIS_PASSWORD= +REDIS_M_HOST=redis:6379 +REDIS_S_HOST=redis:6379 + +# Kafka +KAFKA_BROKER=kafka:9092 + +# Email (placeholder) +EMAIL_SMTP_HOST=smtp.example.com +EMAIL_SMTP_PORT=465 +EMAIL_SMTP_USERNAME=test@example.com +EMAIL_SMTP_PASSWORD=changeme +EMAIL_FROM_ADDRESS=test@example.com +EMAIL_FROM_NAME=juwan-dev +EMAIL_REPLY_TO= + +# S3 (objectstory, placeholder) +S3_ENDPOINT=https://example.com +S3_ACCESS_KEY=changeme +S3_SECRET_KEY=changeme +S3_BUCKET_NAME=dev-bucket +S3_REGION=auto diff --git a/deploy/dev/README.md b/deploy/dev/README.md new file mode 100644 index 0000000..9b8380c --- /dev/null +++ b/deploy/dev/README.md @@ -0,0 +1,62 @@ +# 本地开发环境 + +## 前置条件 + +- Docker +- Go 1.25+(构建镜像时在容器内编译,本机不强制) + +## 使用 + +```bash +cd deploy/dev + +# 1. 构建所有微服务镜像 +./build.sh + +# 2. 启动 +docker compose up -d + +# 3. 查看状态 +docker compose ps + +# 4. 停止 +docker compose down +``` + +构建脚本会扫描 `app/` 下所有 `api`、`rpc`、`mq` 入口,生成 `juwan/-:dev` 镜像。编译失败的服务会跳过,不影响其他服务。 + +如需只启动部分服务: + +```bash +docker compose up -d postgres redis snowflake player-rpc player-api +``` + +## 端口映射 + +| 服务 | 宿主机端口 | +| --------------- | ---------- | +| PostgreSQL | 15432 | +| Redis | 16379 | +| Kafka | 19092 | +| users-api | 18801 | +| player-api | 18802 | +| game-api | 18803 | +| shop-api | 18804 | +| order-api | 18805 | +| wallet-api | 18806 | +| community-api | 18807 | +| objectstory-api | 18808 | +| email-api | 18809 | + +## 环境变量 + +编辑 `.env` 修改数据库密码、Kafka 地址等。默认值可直接用于本地开发。 + +## 数据库初始化 + +首次启动时 PostgreSQL 会自动执行 `desc/sql/` 下的建表语句。如需重新初始化,删除 volume 后重启: + +```bash +docker compose down -v +docker compose up -d +``` diff --git a/deploy/dev/build.sh b/deploy/dev/build.sh new file mode 100755 index 0000000..58d27e9 --- /dev/null +++ b/deploy/dev/build.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)" +IMAGE_PREFIX="juwan" +IMAGE_TAG="${1:-dev}" + +cd "$ROOT_DIR" + +find app -mindepth 2 -maxdepth 2 -type d \( -name "api" -o -name "rpc" -o -name "mq" \) | sort | while read -r service_dir; do + service_type=$(basename "$service_dir") + service_name=$(basename "$(dirname "$service_dir")") + + entry_file=$(grep -rl "package main" "$service_dir"/*.go 2>/dev/null | head -n 1 || true) + [[ -z "$entry_file" ]] && continue + + config_file=$(ls "$service_dir/etc/"*.yaml 2>/dev/null | head -n 1 || true) + config_name="${config_file:+$(basename "$config_file")}" + config_name="${config_name:-config.yaml}" + + image_name="${IMAGE_PREFIX}/${service_name}-${service_type}:${IMAGE_TAG}" + echo "--- $image_name ---" + + cat > Dockerfile.tmp <