Skip to content

Commit

Permalink
[ISSUE #69] Integrate database credentials in auto-deploy (#70)
Browse files Browse the repository at this point in the history
* add DB_ADDRESS env var

* add env file

* skip tests & add manual

* add a hello endpoint

* exclude .env

* refine manual
  • Loading branch information
Pil0tXia authored Mar 19, 2024
1 parent e750702 commit 7aec4fe
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 14 deletions.
18 changes: 11 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
Expand Down Expand Up @@ -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*
hs_err_pid*

### Devops ###
.env
25 changes: 25 additions & 0 deletions deployment/.env.example
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions deployment/README.md
Original file line number Diff line number Diff line change
@@ -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
```
12 changes: 8 additions & 4 deletions deployment/auto-deploy-eventmesh-dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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-<current time>.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
Expand All @@ -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-<current time>.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,4 +32,8 @@ public Object druidStat() {
return DruidStatManagerFacade.getInstance().getDataSourceStatDataList();
}

@GetMapping("/hello")
public Result<String> hello() {
return Result.success("Hello, EventMesh Dashboard!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,4 @@ public Result<List<SubscriptionInfo>> listSubscriptions(
@RequestParam(name = "group", defaultValue = "") String group) {
return Result.success(subscriptionCore.retrieveConfigs(page, size, dataId, group));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down

0 comments on commit 7aec4fe

Please sign in to comment.