From 7aec4feed6abeb18b4e8c02b464c42fe62d770c7 Mon Sep 17 00:00:00 2001 From: Pil0tXia Date: Tue, 19 Mar 2024 16:09:54 +0800 Subject: [PATCH] [ISSUE #69] Integrate database credentials in auto-deploy (#70) * add DB_ADDRESS env var * add env file * skip tests & add manual * add a hello endpoint * exclude .env * refine manual --- .gitignore | 18 ++++++++----- deployment/.env.example | 25 +++++++++++++++++ deployment/README.md | 27 +++++++++++++++++++ deployment/auto-deploy-eventmesh-dashboard.sh | 12 ++++++--- .../console/controller/MetricsController.java | 6 +++++ .../controller/SubscriptionController.java | 1 - .../src/main/resources/application-dev.yml | 2 +- .../src/test/resources/application-test.yml | 2 +- 8 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 deployment/.env.example create mode 100644 deployment/README.md diff --git a/.gitignore b/.gitignore index 1098c796..7f22e5ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,3 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - ### STS ### .apt_generated .classpath @@ -78,8 +72,18 @@ dependency-reduced-pom.xml buildNumber.properties .mvn/timing.properties +### Gradle ### +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + ### Log Files ### *.log logs/ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* \ No newline at end of file +hs_err_pid* + +### Devops ### +.env \ No newline at end of file diff --git a/deployment/.env.example b/deployment/.env.example new file mode 100644 index 00000000..5e2799d0 --- /dev/null +++ b/deployment/.env.example @@ -0,0 +1,25 @@ +# +# Licensed to Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Apache Software Foundation (ASF) licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Copy this .env.example file to the .env file +# and edit your credentials. + +# Database credentials +DB_ADDRESS=localhost:3306 +DB_USERNAME=root +DB_PASSWORD=password \ No newline at end of file diff --git a/deployment/README.md b/deployment/README.md new file mode 100644 index 00000000..f1bd7471 --- /dev/null +++ b/deployment/README.md @@ -0,0 +1,27 @@ +## Auto Deploy EventMesh Dashboard + +### Usage + +``` +cd ~/service +git clone -b dev https://github.com/apache/eventmesh-dashboard.git +cd eventmesh-dashboard +chmod +x deployment/auto-deploy-eventmesh-dashboard.sh +``` + +Edit credentials: + +``` +cp deployment/.env.example deployment/.env +vim deployment/.env +``` + +Add task to crontab: + +``` +crontab -e +``` + +``` +0 * * * * ~/service/eventmesh-dashboard/deployment/auto-deploy-eventmesh-dashboard.sh +``` \ No newline at end of file diff --git a/deployment/auto-deploy-eventmesh-dashboard.sh b/deployment/auto-deploy-eventmesh-dashboard.sh index 01aae6c5..24ca44be 100644 --- a/deployment/auto-deploy-eventmesh-dashboard.sh +++ b/deployment/auto-deploy-eventmesh-dashboard.sh @@ -32,6 +32,10 @@ APP_LOG=~/service/eventmesh-dashboard/deployment/eventmesh-dashboard-$(date +"%Y # Jar file path JAR_FILE_PATH=~/service/eventmesh-dashboard/eventmesh-dashboard-console/target/eventmesh-dashboard-console-0.0.1-SNAPSHOT.jar +# Load environment variables from external file +ENV_FILE=~/service/eventmesh-dashboard/deployment/.env +source $ENV_FILE + # Update the git repository cd $REPO_PATH git fetch origin dev @@ -56,10 +60,10 @@ if [ $LOCAL != $REMOTE ]; then fi # Compile and package the Jar file - mvn clean package + mvn clean package -DskipTests # Start the springboot application and record the process id to pid.log file, redirect console logs to eventmesh-dashboard-.log file - nohup java -jar $JAR_FILE_PATH > $APP_LOG 2>&1 & + nohup java -DDB_ADDRESS=$DB_ADDRESS -DDB_USERNAME=$DB_USERNAME -DDB_PASSWORD=$DB_PASSWORD -jar $JAR_FILE_PATH > $APP_LOG 2>&1 & echo $! > $PID_LOG # Log the event @@ -75,10 +79,10 @@ else echo "$(date +"%Y-%m-%d %H:%M:%S") - application running, no operation performed." >> $AUTO_DEPLOY_LOG else # If the pid.log file does not exist, compile and package the Jar file - mvn clean package + mvn clean package -DskipTests # Start the springboot application and record the process id to pid.log file, redirect console logs to eventmesh-dashboard-.log file - nohup java -jar $JAR_FILE_PATH > $APP_LOG 2>&1 & + nohup java -DDB_ADDRESS=$DB_ADDRESS -DDB_USERNAME=$DB_USERNAME -DDB_PASSWORD=$DB_PASSWORD -jar $JAR_FILE_PATH > $APP_LOG 2>&1 & echo $! > $PID_LOG # Log the event diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/MetricsController.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/MetricsController.java index 689f833c..bedbbdd5 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/MetricsController.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/MetricsController.java @@ -17,6 +17,8 @@ package org.apache.eventmesh.dashboard.console.controller; +import org.apache.eventmesh.dashboard.common.dto.Result; + import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -30,4 +32,8 @@ public Object druidStat() { return DruidStatManagerFacade.getInstance().getDataSourceStatDataList(); } + @GetMapping("/hello") + public Result hello() { + return Result.success("Hello, EventMesh Dashboard!"); + } } \ No newline at end of file diff --git a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/SubscriptionController.java b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/SubscriptionController.java index 1af09aee..6d53a963 100644 --- a/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/SubscriptionController.java +++ b/eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/controller/SubscriptionController.java @@ -69,5 +69,4 @@ public Result> listSubscriptions( @RequestParam(name = "group", defaultValue = "") String group) { return Result.success(subscriptionCore.retrieveConfigs(page, size, dataId, group)); } - } diff --git a/eventmesh-dashboard-console/src/main/resources/application-dev.yml b/eventmesh-dashboard-console/src/main/resources/application-dev.yml index 3b3c83b3..73f471b0 100644 --- a/eventmesh-dashboard-console/src/main/resources/application-dev.yml +++ b/eventmesh-dashboard-console/src/main/resources/application-dev.yml @@ -30,7 +30,7 @@ spring: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/eventmesh_dashboard?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true + url: jdbc:mysql://${DB_ADDRESS:localhost:3306}/eventmesh_dashboard?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true username: ${DB_USERNAME:root} password: ${DB_PASSWORD:password} diff --git a/eventmesh-dashboard-console/src/test/resources/application-test.yml b/eventmesh-dashboard-console/src/test/resources/application-test.yml index ee44e7c2..89dbea25 100644 --- a/eventmesh-dashboard-console/src/test/resources/application-test.yml +++ b/eventmesh-dashboard-console/src/test/resources/application-test.yml @@ -21,7 +21,7 @@ spring: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/eventmesh_dashboard_test?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true + url: jdbc:mysql://${DB_ADDRESS:localhost:3306}/eventmesh_dashboard_test?useSSL=false&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&allowPublicKeyRetrieval=true username: ${DB_USERNAME:root} password: ${DB_PASSWORD:password}