From fa1c716d6af669f3c33e1ade40cbcb0a54b1eedb Mon Sep 17 00:00:00 2001 From: Pil0tXia Date: Fri, 15 Mar 2024 18:35:58 +0800 Subject: [PATCH] [ISSUE #64] Support automated deployment and Fix runtime packaging errors (#65) * add back missing build label * Fix module name * add test scope * exclude log4j-to-slf4j * exclude log4j-slf4j-impl * add auto deploy script * add license * refine the script --- deployment/auto-deploy-eventmesh-dashboard.sh | 87 +++++++++++++++++++ eventmesh-dashboard-console/pom.xml | 31 +++++++ eventmesh-dashboard-service/pom.xml | 2 +- pom.xml | 7 ++ 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 deployment/auto-deploy-eventmesh-dashboard.sh diff --git a/deployment/auto-deploy-eventmesh-dashboard.sh b/deployment/auto-deploy-eventmesh-dashboard.sh new file mode 100644 index 00000000..01aae6c5 --- /dev/null +++ b/deployment/auto-deploy-eventmesh-dashboard.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# +# 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. + +# Git repository path +REPO_PATH=~/service/eventmesh-dashboard + +# SpringBoot process ID file path +PID_LOG=~/service/eventmesh-dashboard/deployment/eventmesh-dashboard-pid.log + +# Automatic deployment shell script log file path +AUTO_DEPLOY_LOG=~/service/eventmesh-dashboard/deployment/auto-deploy-eventmesh-dashboard.log + +# EventMesh Dashboard log file path +APP_LOG=~/service/eventmesh-dashboard/deployment/eventmesh-dashboard-$(date +"%Y-%m-%d-%H-%M-%S").log + +# Jar file path +JAR_FILE_PATH=~/service/eventmesh-dashboard/eventmesh-dashboard-console/target/eventmesh-dashboard-console-0.0.1-SNAPSHOT.jar + +# Update the git repository +cd $REPO_PATH +git fetch origin dev +LOCAL=$(git rev-parse @) +REMOTE=$(git rev-parse origin/dev) + +if [ $LOCAL != $REMOTE ]; then + # If the remote dev branch is newer than the local one, update the local dev branch code + git pull origin dev + + # Log the event + echo "$(date +"%Y-%m-%d %H:%M:%S") - change detected." >> $AUTO_DEPLOY_LOG + + # Terminate the old process + if [ -s $PID_LOG ]; then + PID=$(cat $PID_LOG) + if [ -n "$PID" ]; then + kill $PID + # Log the event + echo "$(date +"%Y-%m-%d %H:%M:%S") - kill running application." >> $AUTO_DEPLOY_LOG + fi + fi + + # Compile and package the Jar file + mvn clean package + + # 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 & + echo $! > $PID_LOG + + # Log the event + echo "$(date +"%Y-%m-%d %H:%M:%S") - start new application." >> $AUTO_DEPLOY_LOG +else + # If there are no new changes in the remote dev branch + + # Log the event + echo "$(date +"%Y-%m-%d %H:%M:%S") - no change detected." >> $AUTO_DEPLOY_LOG + + if [ -s $PID_LOG ]; then + # If the pid.log file exists, no action is performed + 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 + + # 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 & + echo $! > $PID_LOG + + # Log the event + echo "$(date +"%Y-%m-%d %H:%M:%S") - no pid.log file, start application." >> $AUTO_DEPLOY_LOG + fi +fi diff --git a/eventmesh-dashboard-console/pom.xml b/eventmesh-dashboard-console/pom.xml index 1fe19058..231d865c 100644 --- a/eventmesh-dashboard-console/pom.xml +++ b/eventmesh-dashboard-console/pom.xml @@ -87,6 +87,10 @@ + + + + @@ -125,6 +129,33 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + org.apache.eventmesh.dashboard.console.EventMeshDashboardApplication + + + + repackage + + repackage + + + + + org.apache.maven.plugins maven-surefire-plugin diff --git a/eventmesh-dashboard-service/pom.xml b/eventmesh-dashboard-service/pom.xml index ebcd1113..bfc88056 100644 --- a/eventmesh-dashboard-service/pom.xml +++ b/eventmesh-dashboard-service/pom.xml @@ -11,7 +11,7 @@ org.apache.eventmesh.dashboard.service eventmesh-dashboard-service 0.0.1-SNAPSHOT - eventmesh-dashboard-core + eventmesh-dashboard-service 1.8 diff --git a/pom.xml b/pom.xml index 93905dcc..e6dfb520 100644 --- a/pom.xml +++ b/pom.xml @@ -105,11 +105,18 @@ org.mybatis.spring.boot mybatis-spring-boot-starter ${mybatis-spring-boot.version} + + + org.apache.logging.log4j + log4j-to-slf4j + + org.mybatis.spring.boot mybatis-spring-boot-starter-test ${mybatis-spring-boot.version} + test