diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index a8855b6e..00000000 --- a/Dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -# Set the base image -FROM openjdk:8-jre-alpine - -# Dockerfile author / maintainer -MAINTAINER SourceLab.org - -## Define what version of Kafka Webview to build the image using. -ENV WEBVIEW_VER="2.5.0" \ - WEBVIEW_SHA1="00a8db474ba2c584c5a473c8ca9acbd0259c01de" \ - WEBVIEW_HOME="/app" - -# Create app and data directories -RUN mkdir -p ${WEBVIEW_HOME} && \ - mkdir -p ${WEBVIEW_HOME}/logs && \ - mkdir -p ${WEBVIEW_HOME}/data && \ - apk add --update bash curl && \ - rm -rf /var/cache/apk/* - -WORKDIR ${WEBVIEW_HOME} - -# Download KafkaWebview Release from Github project -RUN curl -fSL -o /tmp/kafka-webview-ui-bin.zip https://oss.sonatype.org/service/local/repositories/orgsourcelab-1031/content/org/sourcelab/kafka-webview-ui/${WEBVIEW_VER}/kafka-webview-ui-${WEBVIEW_VER}-bin.zip - -# Verify SHA1 hash and extract. -RUN echo "${WEBVIEW_SHA1} /tmp/kafka-webview-ui-bin.zip" | sha1sum -c - && \ - unzip -d ${WEBVIEW_HOME} /tmp/kafka-webview-ui-bin.zip && \ - mv ${WEBVIEW_HOME}/kafka-webview-ui-${WEBVIEW_VER}/* ${WEBVIEW_HOME} && \ - rm -rf ${WEBVIEW_HOME}/kafka-webview-ui-${WEBVIEW_VER}/ && \ - rm -rf ${WEBVIEW_HOME}/src && \ - rm -f /tmp/kafka-webview-ui-bin.zip - -# Create volume to persist data -VOLUME ${WEBVIEW_HOME}/data - -# Expose port -EXPOSE 8080 - -# What to run when the container starts -ENTRYPOINT [ "/app/start.sh" ] diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..bc97f0de --- /dev/null +++ b/Makefile @@ -0,0 +1,131 @@ + +# VARIABLES +MAVEN_PROJ_LIST = kafka-webview-ui +MAVEN_SKIP = -DskipTests=true -DskipCheckStyle=true -DskipLicenseCheck=true + +# Available values: local | release +DOCKERFILE_PREFIX = local + +# If DOCKERFILE_PREFIX set as 'release', please properly specify also following variables +WEBVIEW_RELEASE_VERSION = 2.5.0 +WEBVIEW_RELEASE_SHA1 = 00a8db474ba2c584c5a473c8ca9acbd0259c01de +WEBVIEW_RELEASE_URL = https://github.com/SourceLabOrg/kafka-webview/releases/download/v$(WEBVIEW_RELEASE_VERSION)/kafka-webview-ui-$(WEBVIEW_RELEASE_VERSION)-bin.zip + + + +# CONFIG +.PHONY: help print-variables +.DEFAULT_GOAL := help + + + +# ACTIONS + +## BUILD + +### Kafka-WebView only + +clean : ## Clean Kafka-WebView project only + mvn clean -pl $(MAVEN_PROJ_LIST) + +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 + +clean-all : ## Clean all projects + mvn clean compile + +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) + +## DOCKER + +docker-build : ## Build Docker image +ifeq ($(DOCKERFILE_PREFIX), local) + docker build \ + -f $(DOCKERFILE_PREFIX).Dockerfile \ + -t sourcelaborg/kafka-webview \ + . +else + docker build \ + -f $(DOCKERFILE_PREFIX).Dockerfile \ + -t sourcelaborg/kafka-webview \ + --build-arg WEBVIEW_VER=$(WEBVIEW_RELEASE_VERSION) \ + --build-arg WEBVIEW_SHA1=$(WEBVIEW_RELEASE_SHA1) \ + --build-arg WEBVIEW_URL=$(WEBVIEW_RELEASE_URL) \ + . +endif + +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) + +## 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) + +jar-run : 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-run : docker-build ## Build Docker image and run Kafka-WebView in container + docker run -ti --rm --name kafka-webview \ + -p 8080:8080 -p 9090:9090 \ + sourcelaborg/kafka-webview + +docker-run-daemon : docker-build ## Build Docker image and run Kafka-WebView in container as daemon + docker run -d --rm --name kafka-webview \ + -p 8080:8080 -p 9090:9090 \ + sourcelaborg/kafka-webview + +## 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 "DOCKERFILE_PREFIX: $(DOCKERFILE_PREFIX)" + @echo "WEBVIEW_RELEASE_VERSION: $(WEBVIEW_RELEASE_VERSION)" + @echo "WEBVIEW_RELEASE_SHA1: $(WEBVIEW_RELEASE_SHA1)" + @echo "" diff --git a/buildAndRun.sh b/buildAndRun.sh deleted file mode 100755 index 96c13622..00000000 --- a/buildAndRun.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -## 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 - -## What port to listen on -export PORT=8080 - -## run application via maven -mvn -pl kafka-webview-ui spring-boot:run -DskipCheckStyle=true -DskipTests=true -DskipLicenseCheck=true \ No newline at end of file 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..98a08f0a 100755 --- a/kafka-webview-ui/src/assembly/distribution/start.sh +++ b/kafka-webview-ui/src/assembly/distribution/start.sh @@ -1,23 +1,35 @@ -#!/bin/bash +#!/bin/sh -CWD=`pwd` +# Get the directory of this script +SCRIPT_DIR=$(dirname "$0") -## Change to local directory -cd "${0%/*}" - -# Define empty options as defaults if none set -if [[ -z "$HEAP_OPTS" ]]; then - export HEAP_OPTS="" +# Define environment variables +## New +if [[ -z "$JVM_OPTS" ]]; then + export JVM_OPTS="-noverify -server -XX:TieredStopAtLevel=1" fi -if [[ -z "$LOG_OPTS" ]]; then - export LOG_OPTS="" +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'" + 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="$MEM_OPTS $HEAP_OPTS" fi -## 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 -cd $CWD +# Start application +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 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: - diff --git a/local.Dockerfile b/local.Dockerfile new file mode 100644 index 00000000..8d50a5fa --- /dev/null +++ b/local.Dockerfile @@ -0,0 +1,33 @@ + +# Base image +FROM openjdk:11-stretch + +# Labels +LABEL maintainer="SourceLab.org " + +# Arguments +## Ports +ARG UI_PORT=8080 +ARG MNG_PORT=9090 +## Java configs +ARG JVM_OPTS="-noverify -server -XX:TieredStopAtLevel=1" +ARG MEM_OPTS="-Xms2G -Xmx2G -XX:MaxMetaspaceSize=300M" +ARG JAVA_OPTS="" + +# Set working directory +WORKDIR "/app" + +# Get release +COPY kafka-webview-ui/target/*.jar kafka-webview.jar + +# Expose ports +EXPOSE $UI_PORT $MNG_PORT + +# Change owner of application main folder +RUN chown -hR 1001:1001 /app/ + +# Configure a user different than root +USER 1001 + +# Run application +ENTRYPOINT exec java $JVM_OPTS $MEM_OPTS $JAVA_OPTS -jar kafka-webview.jar diff --git a/release.Dockerfile b/release.Dockerfile new file mode 100644 index 00000000..a30baa5e --- /dev/null +++ b/release.Dockerfile @@ -0,0 +1,43 @@ + +# Base image +FROM openjdk:11-stretch + +# Labels +LABEL maintainer="SourceLab.org " + +# Arguments +## Ports +ARG UI_PORT=8080 +ARG MNG_PORT=9090 +## Release configs +ARG WEBVIEW_VER="2.5.0" +ARG WEBVIEW_SHA1="00a8db474ba2c584c5a473c8ca9acbd0259c01de" +ARG WEBVIEW_URL="https://oss.sonatype.org/service/local/repositories/orgsourcelab-1031/content/org/sourcelab/kafka-webview-ui/$WEBVIEW_VER/kafka-webview-ui-$WEBVIEW_VER-bin.zip" + +# Set working directory +WORKDIR "/app" + +# Get release +RUN curl -fSL -o /tmp/kafka-webview-ui-bin.zip $WEBVIEW_URL + +# Verify SHA1 hash +RUN echo "$WEBVIEW_SHA1 /tmp/kafka-webview-ui-bin.zip" | sha1sum -c - + +# Extract, move and clean +RUN unzip -d . /tmp/kafka-webview-ui-bin.zip && \ + mv ./kafka-webview-ui-$WEBVIEW_VER/* . && \ + rm -rf ./kafka-webview-ui-$WEBVIEW_VER/ && \ + rm -rf ./src && \ + rm -f /tmp/kafka-webview-ui-bin.zip + +# Expose ports +EXPOSE $UI_PORT $MNG_PORT + +# Change owner of application main folder +RUN chown -hR 1001:1001 /app/ + +# Configure a user different than root +USER 1001 + +# Run application +ENTRYPOINT [ "./start.sh" ]