From 1d0712dcfc8430cd346b3a51cd58f51dee691b83 Mon Sep 17 00:00:00 2001 From: Matteo Baiguini Date: Fri, 20 Dec 2019 12:30:38 +0100 Subject: [PATCH 1/4] Refactored application properties system --- buildAndRun.sh | 19 ++-- .../src/assembly/distribution/start.bat | 3 - .../src/assembly/distribution/start.sh | 24 ++--- .../{config/dev.yml => application-dev.yml} | 13 ++- .../resources/application.yml} | 88 ++++++++++++++- .../src/main/resources/config/base.yml | 100 ------------------ 6 files changed, 114 insertions(+), 133 deletions(-) rename kafka-webview-ui/src/main/resources/{config/dev.yml => application-dev.yml} (85%) rename kafka-webview-ui/src/{assembly/distribution/config.yml => main/resources/application.yml} (63%) delete mode 100644 kafka-webview-ui/src/main/resources/config/base.yml diff --git a/buildAndRun.sh b/buildAndRun.sh index 96c13622..6f249764 100755 --- a/buildAndRun.sh +++ b/buildAndRun.sh @@ -1,11 +1,14 @@ -#!/bin/bash +#!/bin/sh -## These are the required ENV variables for startup for development -## Define what configs to load on start -export SPRING_CONFIG_LOCATION=classpath:/config/base.yml,classpath:/config/dev.yml +# Define a profile to load specific configurations +# Available profiles: [null = default = prod] | dev +export SPRING_PROFILES_ACTIVE="dev" -## What port to listen on -export PORT=8080 +# Define which project should be run (comma separated list) +export PROJ_LIST="kafka-webview-ui" -## run application via maven -mvn -pl kafka-webview-ui spring-boot:run -DskipCheckStyle=true -DskipTests=true -DskipLicenseCheck=true \ No newline at end of file +# Define maven configurations +export MAVEN_CONFIG="-DskipCheckStyle=true -DskipTests=true -DskipLicenseCheck=true" + +# Run application using maven +mvn spring-boot:run -pl $PROJ_LIST $MAVEN_CONFIG diff --git a/kafka-webview-ui/src/assembly/distribution/start.bat b/kafka-webview-ui/src/assembly/distribution/start.bat index 1ffa4158..bc0b66e2 100644 --- a/kafka-webview-ui/src/assembly/distribution/start.bat +++ b/kafka-webview-ui/src/assembly/distribution/start.bat @@ -2,9 +2,6 @@ cd /D %~dp0 -:: Define configuration -set SPRING_CONFIG_LOCATION=classpath:/config/base.yml,config.yml - :: launch webapp FOR /F "tokens=* USEBACKQ" %%F IN (`dir /b kafka-webview-ui-*.jar`) DO SET "jar=%%F" java -jar %jar% diff --git a/kafka-webview-ui/src/assembly/distribution/start.sh b/kafka-webview-ui/src/assembly/distribution/start.sh index 75d98f58..faf55cd4 100755 --- a/kafka-webview-ui/src/assembly/distribution/start.sh +++ b/kafka-webview-ui/src/assembly/distribution/start.sh @@ -1,23 +1,15 @@ -#!/bin/bash +#!/bin/sh +# Temporary save current directory CWD=`pwd` -## Change to local directory +# Change to local directory cd "${0%/*}" -# Define empty options as defaults if none set -if [[ -z "$HEAP_OPTS" ]]; then - export HEAP_OPTS="" -fi -if [[ -z "$LOG_OPTS" ]]; then - export LOG_OPTS="" -fi +# Start application +export JVM_OPTS="-noverify -server -XX:TieredStopAtLevel=1" +#export MEM_OPTS="-Xms2G -Xmx2G -XX:MaxMetaspaceSize=300M" +exec java $JVM_OPTS $MEM_OPTS $JAVA_OPTS -jar kafka-webview-ui-*.jar -## Define configuration -export SPRING_CONFIG_LOCATION=classpath:/config/base.yml,config.yml - -## launch webapp -exec java -jar kafka-webview-ui-*.jar $HEAP_OPTS $LOG_OPTS - -## Change back to previous directory +# Change back to previous directory cd $CWD diff --git a/kafka-webview-ui/src/main/resources/config/dev.yml b/kafka-webview-ui/src/main/resources/application-dev.yml similarity index 85% rename from kafka-webview-ui/src/main/resources/config/dev.yml rename to kafka-webview-ui/src/main/resources/application-dev.yml index b5fe314d..aa0dcff0 100644 --- a/kafka-webview-ui/src/main/resources/config/dev.yml +++ b/kafka-webview-ui/src/main/resources/application-dev.yml @@ -1,20 +1,27 @@ + +# General server: + servlet: session: persistent: true + +# Spring spring: + jpa: show-sql: true - # H2 Datbase + h2: console: - ## Disable for release enabled: true path: /h2 + +# Kafka WebView custom app: - requireSsl: false + user: enabled: true ## Development server Ldap auth settings diff --git a/kafka-webview-ui/src/assembly/distribution/config.yml b/kafka-webview-ui/src/main/resources/application.yml similarity index 63% rename from kafka-webview-ui/src/assembly/distribution/config.yml rename to kafka-webview-ui/src/main/resources/application.yml index ae279acf..1265009d 100644 --- a/kafka-webview-ui/src/assembly/distribution/config.yml +++ b/kafka-webview-ui/src/main/resources/application.yml @@ -1,14 +1,95 @@ + +# General server: + ## What port to run the service on. port: 8080 + + tomcat: + remote_ip_header: x-forwarded-for + protocol_header: x-forwarded-proto + mbeanregistry: + enabled: true + servlet: session: + ## User sessions should not be persistent across service restarts by default. + persistent: false ## User login session timeout after 1 hour (3600 seconds) timeout: 3600 -## Various App Configs +# Spring +spring: + + application: + name: Kafka Webview + + datasource: + url: "jdbc:h2:file:./data/db" + username: sa + password: + driver-class-name: org.h2.Driver + + flyway: + locations: "classpath:schema/migration/{vendor}" + baselineOnMigrate: true + + servlet: + multipart: + max-file-size: 64MB + max-request-size: 64MB + + thymeleaf: + cache: false + enabled: true + prefix: "classpath:/templates/" + suffix: ".html" + mode: HTML + encoding: UTF-8 + check-template-location: true + + jpa: + hibernate: + ddl-auto: none + show-sql: false + open-in-view: true + + +# Spring Actuator - Global +management: + server: + port: 9090 + endpoints: + web: + exposure: + include: "*" + endpoint: + health: + show-details: when_authorized + metrics: + tags: + application: ${spring.application.name} + ## Disable LDAP by default + health: + ldap: + enabled: false + +# Spring Actuator - Info endpoint +info: + app: + name: ${spring.application.name} + + +# Kafka WebView custom app: + + ## Application name + name: Kafka WebView + + ## TODO: add a description to this configuration + uploadPath: "./data/uploads" + ## Should be unique to your installation. ## This key will be used for symmetric encryption of JKS/TrustStore secrets if you configure any SSL enabled Kafka clusters. key: "SuperSecretKey" @@ -36,13 +117,14 @@ app: ## Setting to false will disable login requirement. enabled: true + ## Ldap auth settings ## Optional: if you want to use LDAP for user authentication instead of locally defined users. ldap: ## Disabled by default. enabled: false ## URL/Hostname for your LDAP server - url: "ldap://localhost:8389/dc=example,dc=org" + url: "ldap://localhost:63182/dc=example,dc=org" ## Example values defined below, adjust as needed. ## How to find user records @@ -73,4 +155,4 @@ app: ## If LDAP does not allow anonymous access, define the user/password to connect using. ## If not required, leave both fields empty bindUser: "cn=ManagementUser" - bindUserPassword: "password-here" \ No newline at end of file + bindUserPassword: "password-here" diff --git a/kafka-webview-ui/src/main/resources/config/base.yml b/kafka-webview-ui/src/main/resources/config/base.yml deleted file mode 100644 index 5b91a6b1..00000000 --- a/kafka-webview-ui/src/main/resources/config/base.yml +++ /dev/null @@ -1,100 +0,0 @@ -server: - port: ${PORT:8080} - tomcat: - remote_ip_header: x-forwarded-for - protocol_header: x-forwarded-proto - mbeanregistry: - enabled: true - servlet: - session: - ## User sessions should not be persistent across service restarts by default. - persistent: false - ## User login session timeout after 1 hour (3600 seconds) - timeout: 3600 - -spring: - application: - name: Kafka Webview - datasource: - url: "jdbc:h2:file:./data/db" - username: sa - password: - driver-class-name: org.h2.Driver - - flyway: - locations: "classpath:schema/migration/{vendor}" - baselineOnMigrate: true - - servlet: - multipart: - max-file-size: 64MB - max-request-size: 64MB - - thymeleaf: - cache: false - enabled: true - prefix: "classpath:/templates/" - suffix: ".html" - mode: HTML - encoding: UTF-8 - check-template-location: true - - jpa: - hibernate: - ddl-auto: none - show-sql: false - open-in-view: true - -# Spring Actuator - global -management: - server: - port: 9090 - endpoints: - web: - exposure: - include: "*" - endpoint: - health: - show-details: when_authorized - metrics: - tags: - application: ${spring.application.name} - ## Disable LDAP by default - health: - ldap: - enabled: false - -# Spring Actuator - Info endpoint -info: - app: - name: ${spring.application.name} - -## Various App Configs -app: - name: Kafka Web View - uploadPath: "./data/uploads" - key: "SuperSecretKey" - multiThreadedConsumer: true - maxConcurrentWebConsumers: 32 - maxConcurrentWebSocketConsumers: 64 - consumerIdPrefix: "KafkaWebViewConsumer" - requireSsl: true - user: - enabled: true - ## Ldap auth settings - ldap: - enabled: false - userDnPattern: "uid={0},ou=people" - groupSearchBase: "ou=groups" - groupRoleAttribute: "cn" - groupSearchFilter: "(uniqueMember={0})" - passwordAttribute: "userPassword" - passwordEncoderClass: "org.springframework.security.crypto.password.LdapShaPasswordEncoder" - adminGroups: "" - userGroups: "" - url: "ldap://localhost:63182/dc=example,dc=org" - ## If LDAP does not allow anonymous access, define the user/password to connect using. - ## If not required, leave both fields empty - bindUser: - bindUserPassword: - From 28667330f5ecd8d2309d42f5b33d80b583bb7032 Mon Sep 17 00:00:00 2001 From: Matteo Baiguini Date: Fri, 20 Dec 2019 13:11:54 +0100 Subject: [PATCH 2/4] Added Makefile - Removed buildAndRun script --- Makefile | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ buildAndRun.sh | 14 -------- 2 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 Makefile delete mode 100755 buildAndRun.sh diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..099df29a --- /dev/null +++ b/Makefile @@ -0,0 +1,95 @@ + +# VARIABLES +MAVEN_PROJ_LIST := kafka-webview-ui +MAVEN_SKIP := -DskipTests=true -DskipCheckStyle=true -DskipLicenseCheck=true +RELEASE_VERSION := 2.5.0 + + +# CONFIG +.PHONY: help print-variables +.DEFAULT_GOAL := help + + +# ACTIONS + +## BUILD + +### Kafka-WebView only + +compile : ## Compile Kafka-WebView project only + mvn clean compile -pl $(MAVEN_PROJ_LIST) + +test : ## Test Kafka-WebView project only + mvn clean test -pl $(MAVEN_PROJ_LIST) + +package : ## Build Kafka-WebView jar only + mvn clean package -pl $(MAVEN_PROJ_LIST) + +package-skip : ## Build Kafka-WebView jar only, skipping tests and checks + mvn clean package -pl $(MAVEN_PROJ_LIST) $(MAVEN_SKIP) + +### All + +compile-all : ## Compile all projects + mvn clean compile + +test-all : ## Test all projects + mvn clean test + +package-all : ## Build all jars + mvn clean package + +package-all-skip : ## Build all jars, skipping tests and checks + mvn clean package $(MAVEN_SKIP) + +## RUN + +run : ## Build and run Kafka-WebView only using Maven + export SPRING_PROFILES_ACTIVE="dev"; \ + mvn spring-boot:run -pl $(MAVEN_PROJ_LIST) $(MAVEN_SKIP) + +run-jar : package-skip ## Build and run Kafka-WebView only using jar + export SPRING_PROFILES_ACTIVE="dev"; \ + java $(JVM_OPTS) $(MEM_OPTS) $(JAVA_OPTS) -jar kafka-webview-ui-*.jar + +## DOCKER + +docker-build : ## Build Docker image + docker build -t sourcelaborg/kafka-webview . + +docker-push : ## Push Docker image to Docker Hub + docker push sourcelaborg/kafka-webview:latest + +docker-tag-release : ## Tag Docker image with version $(RELEASE_VERSION) + docker tag sourcelaborg/kafka-webview sourcelaborg/kafka-webview:$(RELEASE_VERSION) + +docker-push-release : ## Push Docker image version $(RELEASE_VERSION) + docker push sourcelaborg/kafka-webview:$(RELEASE_VERSION) + +## SSL + +# TODO + +## HELPERS + +help : ## Help (default action) + @echo "" + @echo "*** \033[33mMakefile help\033[0m ***" + @echo "" + @echo "Targets list:" + @grep -E '^[a-zA-Z_-]+ :.*?## .*$$' $(MAKEFILE_LIST) | sort -k 1,1 | awk 'BEGIN {FS = ":.*?## "}; {printf "\t\033[36m%-30s\033[0m %s\n", $$1, $$2}' + @echo "" + +print-variables : ## Print variables values + @echo "" + @echo "*** \033[33mMakefile variables\033[0m ***" + @echo "" + @echo "- - - makefile - - -" + @echo "MAKE: $(MAKE)" + @echo "MAKEFILES: $(MAKEFILES)" + @echo "MAKEFILE_LIST: $(MAKEFILE_LIST)" + @echo "- - -" + @echo "MAVEN_PROJ_LIST: $(MAVEN_PROJ_LIST)" + @echo "MAVEN_SKIP: $(MAVEN_SKIP)" + @echo "RELEASE_VERSION: $(RELEASE_VERSION)" + @echo "" diff --git a/buildAndRun.sh b/buildAndRun.sh deleted file mode 100755 index 6f249764..00000000 --- a/buildAndRun.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -# Define a profile to load specific configurations -# Available profiles: [null = default = prod] | dev -export SPRING_PROFILES_ACTIVE="dev" - -# Define which project should be run (comma separated list) -export PROJ_LIST="kafka-webview-ui" - -# Define maven configurations -export MAVEN_CONFIG="-DskipCheckStyle=true -DskipTests=true -DskipLicenseCheck=true" - -# Run application using maven -mvn spring-boot:run -pl $PROJ_LIST $MAVEN_CONFIG From c9694fc7957bea02c575af04cbdfe72b47929561 Mon Sep 17 00:00:00 2001 From: Matteo Baiguini Date: Sat, 4 Jan 2020 14:04:12 +0100 Subject: [PATCH 3/4] Fixed start.sh as discussed in the PR --- .../src/assembly/distribution/start.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kafka-webview-ui/src/assembly/distribution/start.sh b/kafka-webview-ui/src/assembly/distribution/start.sh index faf55cd4..6cc490b5 100755 --- a/kafka-webview-ui/src/assembly/distribution/start.sh +++ b/kafka-webview-ui/src/assembly/distribution/start.sh @@ -6,9 +6,22 @@ CWD=`pwd` # Change to local directory cd "${0%/*}" -# Start application +# Define environment variables +## New export JVM_OPTS="-noverify -server -XX:TieredStopAtLevel=1" -#export MEM_OPTS="-Xms2G -Xmx2G -XX:MaxMetaspaceSize=300M" +export MEM_OPTS="-Xms2G -Xmx2G -XX:MaxMetaspaceSize=300M" +export JAVA_OPTS="" +## Deprecated +if [[ ! -z "$LOG_OPTS" ]]; then + echo "Usage of 'LOG_OPTS' is deprecated and will be removed in the future, please switch to 'JAVA_OPTS'" + JAVA_OPTS="$JAVA_OPTS $LOG_OPTS" +fi +if [[ ! -z "$HEAP_OPTS" ]]; then + echo "Usage of 'HEAP_OPTS' is deprecated and will be removed in the future, please switch to 'MEM_OPTS'" + export MEM_OPTS="$HEAP_OPTS" +fi + +# Start application exec java $JVM_OPTS $MEM_OPTS $JAVA_OPTS -jar kafka-webview-ui-*.jar # Change back to previous directory From a43abe8228c7493926cfbd01fc16f2191e5561b5 Mon Sep 17 00:00:00 2001 From: Matteo Baiguini SBT Date: Sun, 5 Jan 2020 13:51:48 +0100 Subject: [PATCH 4/4] Fix start script big mistake --- .../src/assembly/distribution/start.sh | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/kafka-webview-ui/src/assembly/distribution/start.sh b/kafka-webview-ui/src/assembly/distribution/start.sh index 6cc490b5..98a08f0a 100755 --- a/kafka-webview-ui/src/assembly/distribution/start.sh +++ b/kafka-webview-ui/src/assembly/distribution/start.sh @@ -1,28 +1,35 @@ #!/bin/sh -# Temporary save current directory -CWD=`pwd` - -# Change to local directory -cd "${0%/*}" +# Get the directory of this script +SCRIPT_DIR=$(dirname "$0") # Define environment variables ## New -export JVM_OPTS="-noverify -server -XX:TieredStopAtLevel=1" -export MEM_OPTS="-Xms2G -Xmx2G -XX:MaxMetaspaceSize=300M" -export JAVA_OPTS="" +if [[ -z "$JVM_OPTS" ]]; then + export JVM_OPTS="-noverify -server -XX:TieredStopAtLevel=1" +fi +if [[ -z "$MEM_OPTS" ]]; then + export MEM_OPTS="-Xms2G -Xmx2G -XX:MaxMetaspaceSize=300M" +fi +if [[ -z "$JAVA_OPTS" ]]; then + export JAVA_OPTS="" +fi ## Deprecated if [[ ! -z "$LOG_OPTS" ]]; then echo "Usage of 'LOG_OPTS' is deprecated and will be removed in the future, please switch to 'JAVA_OPTS'" - JAVA_OPTS="$JAVA_OPTS $LOG_OPTS" + export JAVA_OPTS="$JAVA_OPTS $LOG_OPTS" fi if [[ ! -z "$HEAP_OPTS" ]]; then echo "Usage of 'HEAP_OPTS' is deprecated and will be removed in the future, please switch to 'MEM_OPTS'" - export MEM_OPTS="$HEAP_OPTS" + export MEM_OPTS="$MEM_OPTS $HEAP_OPTS" fi # Start application -exec java $JVM_OPTS $MEM_OPTS $JAVA_OPTS -jar kafka-webview-ui-*.jar - -# Change back to previous directory -cd $CWD +echo "Start Kafka-WebView with following parameters:" +echo "\tJVM_OPTS: $JVM_OPTS" +echo "\tMEM_OPTS: $MEM_OPTS" +echo "\tJAVA_OPTS: $JAVA_OPTS" +echo "\tLOG_OPTS: deprecated, added to JAVA_OPTS" +echo "\tHEAP_OPTS: deprecated, added to MEM_OPTS" +echo +java $JVM_OPTS $MEM_OPTS $JAVA_OPTS -jar kafka-webview-ui-*.jar