Skip to content

Commit

Permalink
fixed auto genereate application.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
bakboem committed Dec 30, 2024
1 parent f2eaeae commit 37a8da9
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 6 deletions.
21 changes: 20 additions & 1 deletion backend/java-stack-microservice/spring-eureka/create-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,47 @@ CONFIG_DIR="src/main/resources"
PROPERTIES_FILE="$CONFIG_DIR/application.properties"
YAML_FILE="$CONFIG_DIR/application.yml"

# 获取 ngrok 本地地址
NGROK_API="http://127.0.0.1:4040/api/tunnels"
NGROK_URL=$(curl -s "$NGROK_API" | jq -r '.tunnels[0].public_url')

# 检查并删除 application.properties 文件
if [ -f "$PROPERTIES_FILE" ]; then
echo "Found $PROPERTIES_FILE. Deleting it."
rm -f "$PROPERTIES_FILE"
fi

if [ -z "$NGROK_URL" ] || [ "$NGROK_URL" == "null" ]; then
echo "Error: Unable to fetch ngrok URL. Make sure ngrok is running."
exit 1
fi

# 打印获取到的 ngrok 地址
echo "Using ngrok URL: $NGROK_URL"

# 创建 application.yml 文件并写入配置
echo "Creating $YAML_FILE with the required configuration."
mkdir -p "$CONFIG_DIR" # 确保目录存在
cat > "$YAML_FILE" <<EOF
spring:
application:
name: eureka-server
server:
port: 8761 # 设置 Eureka Server 监听的端口
eureka:
instance:
hostname: $NGROK_URL # 动态设置 ngrok 外网地址
client:
service-url:
defaultZone: $NGROK_URL/eureka/ # 动态设置 Eureka 注册表地址
register-with-eureka: false # 不向自己或其他 Eureka Server 注册
fetch-registry: false # 不从其他 Eureka Server 拉取注册表
server:
enable-self-preservation: false # 禁用自我保护模式(开发环境可禁用,生产建议保留)
EOF

echo "$YAML_FILE created successfully."
echo "$YAML_FILE created successfully with ngrok URL: $NGROK_URL"

# Build the project to generate JAR file
echo "Running ./gradlew clean build..."
Expand Down
2 changes: 1 addition & 1 deletion backend/nocode-standalone-instance/kafka/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://5622-61-82-161-233.ngrok-free.app:9092
KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://ce9d-61-82-161-233.ngrok-free.app:9092
KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
KAFKA_CFG_PROCESS_ROLES=broker,controller
KAFKA_CFG_NODE_ID=1
Expand Down
2 changes: 1 addition & 1 deletion backend/nocode-standalone-instance/kafka/.env.bak
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://1486-61-82-161-233.ngrok-free.app:9092
KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://0dce-61-82-161-233.ngrok-free.app:9092
KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
KAFKA_CFG_PROCESS_ROLES=broker,controller
KAFKA_CFG_NODE_ID=1
Expand Down
3 changes: 2 additions & 1 deletion build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ fi


# 运行 docker-compose build
docker-compose -f ./docker-compose-dev.yml --profile standalone build
# docker-compose -f ./docker-compose-dev.yml --profile standalone --profile java-microservices build
docker-compose -f ./docker-compose-dev.yml --profile java-microservices build
if [ $? -ne 0 ]; then
echo "构建过程中出现错误,退出脚本。"
exit 1
Expand Down
21 changes: 21 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ services:
restart: always


####### JAVA Stack ########
eureka:
# build:
# context: ./backend/java-stack-microservice/spring-eureka
image: ecm-eureka
container_name: ecm-eureka
profiles:
- java-microservices
ports:
- "8761:8761"
environment:
- EUREKA_SERVER_PORT=8761
- JAVA_OPTS=-Xms256m -Xmx512m
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8761 || exit 1"]
interval: 10s
timeout: 5s
retries: 5
restart: always


volumes:
ecm-main-db-data-dev:
ecm-redis-data-dev:
Expand Down
3 changes: 2 additions & 1 deletion init-java-stack-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ find "$JAVA_STACK_PATH" -mindepth 1 -maxdepth 1 -type d | while read -r subdir;
echo "Set executable permissions for $build_script and $create_script"


# 检查是否存在 ARTIFACT_ID 为名的文件夹
# 检查是否存在 .gradle 为名的文件夹
gradle_dir="$subdir/.gradle"
if [ -d "$gradle_dir" ]; then
echo "Directory .gradle exists in $subdir. Executing only build-jar.sh"
(cd "$subdir" && bash "./build-jar.sh") || { echo "Error: Failed to execute build-jar.sh in $subdir"; exit 1; }
else
echo "Directory .gradle does not exist in $subdir. Executing create-project.sh and build-jar.sh"
(cd "$subdir" && bash "./create-project.sh") || { echo "Error: Failed to execute create-project.sh in $subdir"; exit 1; }
fi
done

echo "All operations completed successfully."
Empty file added init.sh
Empty file.
3 changes: 2 additions & 1 deletion start.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
./extract-ngrok-ip.sh
./create-jwt-token-keypair.sh
docker-compose -f ./docker-compose-dev.yml --profile standalone up -d
# docker-compose -f ./docker-compose-dev.yml --profile standalone --profile java-microservices up -d
docker-compose -f ./docker-compose-dev.yml --profile java-microservices up -d
2 changes: 2 additions & 0 deletions stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# docker-compose -f ./docker-compose-dev.yml --profile standalone --profile java-microservices down
docker-compose -f ./docker-compose-dev.yml --profile java-microservices down

0 comments on commit 37a8da9

Please sign in to comment.