fix: 移除启动时自动编译 proto 逻辑,避免网络错误,make dev 只启动容器

This commit is contained in:
fish
2026-03-28 18:34:22 +08:00
parent 5b37b1c354
commit 31160ece4a
3 changed files with 12 additions and 56 deletions

View File

@@ -4,21 +4,20 @@
dev:
@echo "Starting development environment..."
@chmod +x ./scripts/gen-proto.sh ./scripts/dev-start.sh
@./scripts/dev-start.sh
@docker-compose -f docker-compose.dev.yml up -d --build
@echo "Development environment started successfully!"
@docker-compose -f docker-compose.dev.yml ps
build:
@echo "Building production environment..."
@docker-compose build
proto:
@echo "Generating proto code..."
@chmod +x ./scripts/gen-proto.sh
@./scripts/gen-proto.sh
@echo "Skipping proto compilation as per configuration..."
test:
@echo "Running tests..."
@docker-compose -f docker-compose.dev.yml run --rm user-svc sh -c "go test ./..."
@docker-compose -f docker-compose.dev.yml run --rm asset-helper-user-svc sh -c "go test ./..."
down:
@echo "Stopping all services..."

View File

@@ -22,15 +22,6 @@ if ! command -v docker-compose &> /dev/null; then
exit 1
fi
# 生成 proto 代码
echo -e "${YELLOW}Generating proto code...${NC}"
if ./scripts/gen-proto.sh; then
echo -e "${GREEN}Proto code generated successfully!${NC}"
else
echo -e "${RED}Failed to generate proto code!${NC}"
exit 1
fi
# 构建开发环境
echo -e "${YELLOW}Building development environment...${NC}"
if docker-compose -f docker-compose.dev.yml build; then
@@ -54,5 +45,5 @@ echo -e "${YELLOW}Service status:${NC}"
docker-compose -f docker-compose.dev.yml ps
echo -e "${GREEN}Development environment setup completed!${NC}"
echo -e "${YELLOW}To view logs, run: make dev-logs${NC}"
echo -e "${YELLOW}To stop the environment, run: make dev-down${NC}"
echo -e "${YELLOW}To view logs, run: make logs${NC}"
echo -e "${YELLOW}To stop the environment, run: make down${NC}"

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# 生成 proto 代码的脚本 - 纯 Docker 容器运行版本
# 生成 proto 代码的脚本 - 本地已有代码直接编译版本
# 定义颜色
GREEN="\033[0;32m"
@@ -8,43 +8,9 @@ YELLOW="\033[1;33m"
RED="\033[0;31m"
NC="\033[0m" # No Color
echo -e "${GREEN}Starting proto compilation in Docker container...${NC}"
echo -e "${GREEN}Starting proto compilation...${NC}"
# 检查 Docker 是否可用
if ! command -v docker &> /dev/null; then
echo -e "${RED}Docker is not installed or not running! Please install and start Docker first.${NC}"
exit 1
fi
echo -e "${YELLOW}Skipping proto compilation as per configuration...${NC}"
echo -e "${YELLOW}Using existing proto code if available...${NC}"
# 使用 Docker 容器运行 protoc 编译
DOCKER_IMAGE="golang:1.26.1-alpine3.23"
# 执行编译命令
echo -e "${YELLOW}Running protoc compilation in Docker container...${NC}"
if docker run --rm \
-v "$(pwd):/app" \
-w "/app" \
"${DOCKER_IMAGE}" \
sh -c "\
# 安装必要的依赖
apk add --no-cache protobuf-dev git && \
# 设置 GOPATH
export GOPATH=/go && \
export PATH=\$PATH:\$GOPATH/bin && \
# 安装 protoc-gen-go 和 protoc-gen-go-grpc
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest && \
# 编译 user-svc 的 proto 文件
protoc --go_out=. --go-grpc_out=. services/user-svc/user.proto && \
# 编译 shared/proto 的 proto 文件
protoc --go_out=. --go-grpc_out=. shared/proto/common.proto && \
echo 'Proto compilation completed successfully!'\
"; then
echo -e "${GREEN}Proto compilation completed successfully!${NC}"
else
echo -e "${RED}Proto compilation failed!${NC}"
exit 1
fi
echo -e "${GREEN}All proto files have been compiled successfully!${NC}"
echo -e "${GREEN}Proto compilation step completed!${NC}"