From 31160ece4ac95669f080a690eb714230bd0340f9 Mon Sep 17 00:00:00 2001 From: fish Date: Sat, 28 Mar 2026 18:34:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E8=87=AA=E5=8A=A8=E7=BC=96=E8=AF=91=20proto=20?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E9=81=BF=E5=85=8D=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=8Cmake=20dev=20=E5=8F=AA=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=AE=B9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/Makefile | 11 ++++----- backend/scripts/dev-start.sh | 13 ++--------- backend/scripts/gen-proto.sh | 44 ++++-------------------------------- 3 files changed, 12 insertions(+), 56 deletions(-) diff --git a/backend/Makefile b/backend/Makefile index a8e4a05..7f6e973 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -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..." diff --git a/backend/scripts/dev-start.sh b/backend/scripts/dev-start.sh index 1c655d4..ae714cd 100755 --- a/backend/scripts/dev-start.sh +++ b/backend/scripts/dev-start.sh @@ -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}" diff --git a/backend/scripts/gen-proto.sh b/backend/scripts/gen-proto.sh index eff20f5..3710384 100755 --- a/backend/scripts/gen-proto.sh +++ b/backend/scripts/gen-proto.sh @@ -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}"