diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 5492a7d..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,32 +0,0 @@ -version: 2.1 - -jobs: - build: - machine: - image: ubuntu-2004:202008-01 - docker_layer_caching: true - - steps: - - checkout - - - run: - name: docker login - command: | - docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD - - - run: - name: build ui service - command: | - cd ui - mvn clean install docker:build docker:push - - - run: - name: build hello-service - command: | - cd hello-service - ./gradlew build docker dockerPush - - run: - name: build message-service - command: | - cd message-service - ./gradlew build docker dockerPush \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..ba11518 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,108 @@ +name: build + +on: + push: { } + workflow_dispatch: { } + +jobs: + build-ui: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - name: install openjdk + run: | + sudo apt-get update && sudo apt-get install openjdk-17-jdk + sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java + sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac + java -version + + - name: Build + run: | + export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 + export PATH=$JAVA_HOME/bin:$PATH + cd ui + mvn clean install -q + + - name: docker push + run: | + cd ui + if [[ ${GITHUB_REF##*/} == 'master' ]] + then + DOCKER_TAG="latest" + else + DOCKER_TAG="${GITHUB_REF##*/}" + fi + echo "$DOCKER_TAG" + docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }} + docker build . -t mrflick72/ui-interface:$DOCKER_TAG + docker push mrflick72/ui-interface:$DOCKER_TAG + + build-message-service: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - name: install openjdk + run: | + sudo apt-get update && sudo apt-get install openjdk-17-jdk + sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java + sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac + java -version + + - name: Build + run: | + export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 + export PATH=$JAVA_HOME/bin:$PATH + cd message-service + ./gradlew build + + - name: docker push + run: | + cd message-service + if [[ ${GITHUB_REF##*/} == 'master' ]] + then + DOCKER_TAG="latest" + else + DOCKER_TAG="${GITHUB_REF##*/}" + fi + echo "$DOCKER_TAG" + docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }} + docker build . -t mrflick72/message-service:$DOCKER_TAG + docker push mrflick72/message-service:$DOCKER_TAG + + build-hello-service: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + + - name: install openjdk + run: | + sudo apt-get update && sudo apt-get install openjdk-17-jdk + sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java + sudo update-alternatives --set javac /usr/lib/jvm/java-17-openjdk-amd64/bin/javac + java -version + + - name: Build + run: | + export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 + export PATH=$JAVA_HOME/bin:$PATH + cd hello-service + ./gradlew build + + - name: docker push + run: | + cd hello-service + if [[ ${GITHUB_REF##*/} == 'master' ]] + then + DOCKER_TAG="latest" + else + DOCKER_TAG="${GITHUB_REF##*/}" + fi + echo "$DOCKER_TAG" + docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} -p ${{ secrets.DOCKER_HUB_PASSWORD }} + docker build . -t mrflick72/hello-service:$DOCKER_TAG + docker push mrflick72/hello-service:$DOCKER_TAG \ No newline at end of file diff --git a/README.md b/README.md index 5145bbf..edc8b7d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ In this project you can see used many technologies like: * Spring Cloud LoadBalancer * Spring Reactive Data Mongo * Spring WebFlux -* Spring Boot 2.4.x +* Spring Boot 2.7.x * Spring Session * Spring Reactive Security * Java/Kotlin @@ -74,11 +74,12 @@ benefit of the *LoadBalancerExchangeFilterFunction* injected by spring for us. T ... - @Bean - @LoadBalanced - public WebClient webClient() { - return WebClient.builder().build(); - } + @Bean + @LoadBalanced + public WebClient.Builder loadBalancedWebClientBuilder() { + return WebClient.builder(); + } + } ``` #### service integration @@ -101,8 +102,8 @@ class HelloService { } ``` -The application.yml configuration provided via config map for kubernetes profile and application-netflix.yml for netflix profile. The benefit of use configmap -with kubernetes is that configuring restart actuator endpoint with spring cloud kubernetes configuration in the bootstrap.yml, we can benefit of a hot reload configuration mechanism +The application.yml configuration provided via config map. The benefit of use configmap +with Spring Cloud Kubernetes is that configuring restart actuator endpoint with spring cloud kubernetes configuration in the application.yml, we can benefit of a hot reload configuration mechanism via Spring application context restart. The application is totally reactive and no blocking io. It involved: @@ -122,7 +123,7 @@ you can use this command: Remember to enable ingress with this command: ```minikube addons enable ingress -p spring-cloud-k8s``` In order to test on minikube you can use my docker images on docker hub and that's it install the kubernetes manifests under kubernetes folder. -Pay attention before to install all k8s descriptors is needed to apply a command like this: `kubectl create clusterrolebinding admin --clusterrole=cluster-admin --serviceaccount=default:default` +Pay attention before to install all k8s descriptors is needed to apply a command like this: `kubectl apply -f service-account.yml` The command is needed due to Spring Cloud Kubernetes interacts with Kubernetes api, without run this command you will get an error like below: ``` There was an unexpected error (type=Internal Server Error, status=500). @@ -136,26 +137,4 @@ Failure executing: GET at: https://10.96.0.1/api/v1/namespaces/default/endpoints Forbidden!Configured service account doesn't have access. Service account may have been revoked. endpoints "message-service" is forbidden: User "system:serviceaccount:default:default" cannot get resource "endpoints" in API group "" in the namespace "default". -``` -## Conclusion - -Now!, what street choose?, Spring Cloud Netflix or Spring Cloud Kubernetes? Of course the right answer is it depends! - -With Spring Cloud abstraction you can achieve many typical distributed system pattern like: service discovery, client side load balancing and configuration load in a Netflix or Kubernetes environment without -change one line of code, giving you the possibility to choose later the your way: K8S or not to K8S. Said that, the choice depends form -requirements, infrastructure already on place and many other concern. The my impression is: very cool the possibility of choose later and test in local, on premise or in the cloud with -Netflix or on K8s with the assurance that the application behaviour will be near the same, I have particularly appreciated the simple hot reload of application configuration on K8s. -But on the other hands using Spring Cloud Kubernetes for service discovery and client load balancing, that are the main features exposed by Spring Cloud Kubernetes, -it is an overkill especially considering that those features that are already built in in K8s. - -Moreover considering that the application have to talk with master for applying the api, it can be quite dangerous due to too much knowledge on your application of infrastructure -and the risk of coupling your application framework with the infrastructure it is a bad thing in my opinion. The real power is choose later not copling for ever to a platform or to a framework. - -At the end if your application run on a public cloud provider use Spring Cloud Netflix can be a very convenient choice otherwise use Kubernetes may be a real popular and farsighted choice, -especially considering the real cool project pluggable on top of Kubernetes like Istio, Knative and considering that more and more providers are adopting Kubernetes, -AWS EKS, Google Cloud GKE, Pivotal PKS and many other are an example. - -Unfortunately there not exist a correct answer, there exist only use case in wich a choice fit or not. Like in many use case the -possibility of choice later and fast adopting a new way that is more capable for embrace business changing is a winner choice. - -In this direction, in my opinion, Spring Cloud win due to give us the possibility to choose later if adopting Netflix or Kubernetes at any time and go up and forward in any time. +``` \ No newline at end of file diff --git a/hello-service/Dockerfile b/hello-service/Dockerfile new file mode 100644 index 0000000..0e89654 --- /dev/null +++ b/hello-service/Dockerfile @@ -0,0 +1,9 @@ +FROM openjdk:17 + +ADD build/libs/hello-service.jar /usr/local/hello-service/ + +WORKDIR /usr/local/hello-service/ + +EXPOSE 8080 + +CMD ["java", "-jar", "hello-service.jar"] \ No newline at end of file diff --git a/hello-service/build.gradle b/hello-service/build.gradle index e4e806d..b499c08 100644 --- a/hello-service/build.gradle +++ b/hello-service/build.gradle @@ -1,16 +1,14 @@ plugins { - id 'org.springframework.boot' version '2.4.3' - id 'java' - id 'io.spring.dependency-management' version '1.0.11.RELEASE' - - id "com.palantir.docker" version "0.21.0" + id "org.springframework.boot" version "2.7.4" + id "io.spring.dependency-management" version "1.0.14.RELEASE" + id "java" } -apply plugin: 'io.spring.dependency-management' +apply plugin: "io.spring.dependency-management" -group = 'it.valeriovaudi' -//version = '0.0.1-SNAPSHOT' -sourceCompatibility = '11' +group = "it.valeriovaudi" +//version = "0.0.1-SNAPSHOT" +sourceCompatibility = "17" jar { archiveFileName = "hello-service" @@ -21,22 +19,23 @@ repositories { } ext { - set('springCloudVersion', "2020.0.1") + set("springCloudVersion", "2021.0.4") } dependencies { - implementation 'org.springframework.cloud:spring-cloud-starter' + implementation "org.springframework.cloud:spring-cloud-starter" + + implementation "org.springframework.cloud:spring-cloud-starter-kubernetes-client-all" + implementation "org.springframework.cloud:spring-cloud-starter-kubernetes-client-loadbalancer" - implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-client-all' - implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-client-loadbalancer' + implementation "org.springframework.boot:spring-boot-starter-webflux" + implementation "org.springframework.boot:spring-boot-starter-actuator" - implementation 'org.springframework.boot:spring-boot-starter-webflux' - implementation 'org.springframework.boot:spring-boot-starter-actuator' - - compile 'org.projectlombok:lombok:1.18.6' + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'io.projectreactor:reactor-test' + testImplementation "org.springframework.boot:spring-boot-starter-test" + testImplementation "io.projectreactor:reactor-test" } dependencyManagement { @@ -46,10 +45,6 @@ dependencyManagement { } -docker { - name 'mrflick72/hello-service:latest' - dockerfile file('src/main/docker/Dockerfile') - copySpec.from("build/libs/hello-service.jar").into("hello-service.jar") - pull true - noCache true -} \ No newline at end of file +tasks.named("test") { + useJUnitPlatform() +} diff --git a/hello-service/gradle/wrapper/gradle-wrapper.jar b/hello-service/gradle/wrapper/gradle-wrapper.jar index 87b738c..249e583 100644 Binary files a/hello-service/gradle/wrapper/gradle-wrapper.jar and b/hello-service/gradle/wrapper/gradle-wrapper.jar differ diff --git a/hello-service/gradle/wrapper/gradle-wrapper.properties b/hello-service/gradle/wrapper/gradle-wrapper.properties index 12d38de..8049c68 100644 --- a/hello-service/gradle/wrapper/gradle-wrapper.properties +++ b/hello-service/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/hello-service/gradlew b/hello-service/gradlew index af6708f..ab2855b 100755 --- a/hello-service/gradlew +++ b/hello-service/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed 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 +# +# https://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. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m"' +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -89,84 +140,101 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi -exec "$JAVACMD" "$@" +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" \ No newline at end of file diff --git a/hello-service/gradlew.bat b/hello-service/gradlew.bat index 0f8d593..89d1d91 100644 --- a/hello-service/gradlew.bat +++ b/hello-service/gradlew.bat @@ -1,84 +1,91 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega \ No newline at end of file diff --git a/hello-service/settings.gradle b/hello-service/settings.gradle index f44b119..9c9dad6 100644 --- a/hello-service/settings.gradle +++ b/hello-service/settings.gradle @@ -1,6 +1 @@ -pluginManagement { - repositories { - gradlePluginPortal() - } -} -rootProject.name = 'hello-service' \ No newline at end of file +rootProject.name = "hello-service" \ No newline at end of file diff --git a/hello-service/src/main/docker/Dockerfile b/hello-service/src/main/docker/Dockerfile deleted file mode 100644 index 064c812..0000000 --- a/hello-service/src/main/docker/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM openjdk:11 - -ADD hello-service.jar /usr/local/hello-service/ - -WORKDIR /usr/local/hello-service/ - -EXPOSE 8080 - -CMD ["java", "-Xms512m", "-Xmx1g", "-jar", "hello-service.jar"] \ No newline at end of file diff --git a/hello-service/src/main/java/it/valeriovaudi/helloservice/HelloServiceApplication.java b/hello-service/src/main/java/it/valeriovaudi/helloservice/HelloServiceApplication.java index 493e62b..88088ca 100644 --- a/hello-service/src/main/java/it/valeriovaudi/helloservice/HelloServiceApplication.java +++ b/hello-service/src/main/java/it/valeriovaudi/helloservice/HelloServiceApplication.java @@ -19,7 +19,7 @@ import java.util.UUID; import static java.lang.String.format; -import static org.springframework.web.reactive.function.BodyInserters.fromObject; +import static org.springframework.web.reactive.function.BodyInserters.*; import static org.springframework.web.reactive.function.server.ServerResponse.ok; import static reactor.core.publisher.Mono.just; @@ -81,6 +81,6 @@ public RouterFunction routerFunction() { private HandlerFunction sayHelloHandler() { return request -> helloService.sayHello(request.pathVariable("name")) - .flatMap(helloMessage -> ok().body(fromObject(helloMessage))); + .flatMap(helloMessage -> ok().body(fromValue(helloMessage))); } } diff --git a/kubernetes/hello-service.yml b/kubernetes/hello-service.yml index 49951c4..e932552 100644 --- a/kubernetes/hello-service.yml +++ b/kubernetes/hello-service.yml @@ -2,6 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: hello-service + namespace: spring-cloud-kubernetes-demo labels: app: hello-service data: @@ -14,6 +15,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: hello-service + namespace: spring-cloud-kubernetes-demo labels: app: hello-service spec: @@ -33,7 +35,8 @@ spec: spec: containers: - name: hello-service - image: mrflick72/hello-service:latest + image: mrflick72/hello-service:revamp + imagePullPolicy: Always ports: - containerPort: 8080 @@ -58,9 +61,11 @@ kind: Service apiVersion: v1 metadata: name: hello-service + namespace: spring-cloud-kubernetes-demo spec: selector: app: hello-service ports: - protocol: TCP - port: 8080 \ No newline at end of file + port: 8080 + name: http \ No newline at end of file diff --git a/kubernetes/install.sh b/kubernetes/install.sh new file mode 100644 index 0000000..5ae97a4 --- /dev/null +++ b/kubernetes/install.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +kubectl apply -f namespace.yml +kubectl apply -f service-account.yml + +kubectl apply -f mongo.yml +kubectl apply -f redis.yml + +kubectl apply -f message-service.yml +kubectl apply -f hello-service.yml +kubectl apply -f ui-interface.yml diff --git a/kubernetes/message-service.yml b/kubernetes/message-service.yml index 29eebfc..ef56649 100644 --- a/kubernetes/message-service.yml +++ b/kubernetes/message-service.yml @@ -2,6 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: message-service + namespace: spring-cloud-kubernetes-demo labels: app: message-service data: @@ -19,6 +20,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: message-service + namespace: spring-cloud-kubernetes-demo labels: app: message-service spec: @@ -38,7 +40,8 @@ spec: spec: containers: - name: message-service - image: mrflick72/message-service:latest + image: mrflick72/message-service:revamp + imagePullPolicy: Always ports: - containerPort: 8080 @@ -63,9 +66,11 @@ kind: Service apiVersion: v1 metadata: name: message-service + namespace: spring-cloud-kubernetes-demo spec: selector: app: message-service ports: - protocol: TCP port: 8080 + name: http diff --git a/kubernetes/mongo.yml b/kubernetes/mongo.yml index a0cdb97..9ef3d32 100644 --- a/kubernetes/mongo.yml +++ b/kubernetes/mongo.yml @@ -2,6 +2,7 @@ kind: PersistentVolume apiVersion: v1 metadata: name: mongo-pv-volume + namespace: spring-cloud-kubernetes-demo labels: type: local app: mongo @@ -20,6 +21,7 @@ kind: PersistentVolumeClaim apiVersion: v1 metadata: name: mongo-pv-claim + namespace: spring-cloud-kubernetes-demo labels: app: mongo spec: @@ -36,6 +38,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: mongo + namespace: spring-cloud-kubernetes-demo spec: replicas: 1 selector: @@ -66,6 +69,7 @@ kind: Service apiVersion: v1 metadata: name: mongo-svc + namespace: spring-cloud-kubernetes-demo spec: selector: app: mongo diff --git a/kubernetes/namespace.yml b/kubernetes/namespace.yml new file mode 100644 index 0000000..6473f29 --- /dev/null +++ b/kubernetes/namespace.yml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: spring-cloud-kubernetes-demo \ No newline at end of file diff --git a/kubernetes/redis.yml b/kubernetes/redis.yml index 20c7cfb..39422bb 100644 --- a/kubernetes/redis.yml +++ b/kubernetes/redis.yml @@ -2,6 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: redis + namespace: spring-cloud-kubernetes-demo spec: replicas: 1 selector: @@ -25,6 +26,7 @@ kind: Service apiVersion: v1 metadata: name: redis-svc + namespace: spring-cloud-kubernetes-demo spec: selector: app: redis diff --git a/kubernetes/service-account.yml b/kubernetes/service-account.yml new file mode 100644 index 0000000..84df994 --- /dev/null +++ b/kubernetes/service-account.yml @@ -0,0 +1,26 @@ + +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + namespace: spring-cloud-kubernetes-demo + name: namespace-reader +rules: + - apiGroups: [""] + resources: ["configmaps", "pods", "services", "endpoints", "secrets"] + verbs: ["get", "list", "watch"] + +--- + +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: namespace-reader-binding + namespace: spring-cloud-kubernetes-demo +subjects: + - kind: ServiceAccount + name: default + apiGroup: "" +roleRef: + kind: Role + name: namespace-reader + apiGroup: "" \ No newline at end of file diff --git a/kubernetes/ui-interface.yml b/kubernetes/ui-interface.yml index 57e1512..5a5279e 100644 --- a/kubernetes/ui-interface.yml +++ b/kubernetes/ui-interface.yml @@ -2,10 +2,11 @@ kind: ConfigMap apiVersion: v1 metadata: name: ui-interface + namespace: spring-cloud-kubernetes-demo data: application.yaml: |- server: - use-forward-headers: true + forward-headers-strategy: framework spring: redis: @@ -33,6 +34,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: ui-interface + namespace: spring-cloud-kubernetes-demo labels: app: ui-interface spec: @@ -52,7 +54,8 @@ spec: spec: containers: - name: ui-interface - image: mrflick72/ui-interface:latest + image: mrflick72/ui-interface:revamp + imagePullPolicy: Always ports: - containerPort: 8080 livenessProbe: @@ -76,18 +79,26 @@ kind: Service apiVersion: v1 metadata: name: ui-interface + namespace: spring-cloud-kubernetes-demo spec: selector: app: ui-interface ports: - protocol: TCP port: 8080 + name: http --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ui-interface-ingress + namespace: spring-cloud-kubernetes-demo + annotations: + kubernetes.io/ingress.class: "haproxy" + kubernetes.io/tls-acme: "true" + cert-manager.io/cluster-issuer: vvaudi-lab.com-letsencrypt + spec: rules: - http: @@ -99,3 +110,8 @@ spec: name: ui-interface port: number: 8080 + host: spring-cloud-kubernetes-demo.vvaudi-lab.com + tls: + - secretName: vvaudi-lab.com-letsencrypt + hosts: + - spring-cloud-kubernetes-demo.vvaudi-lab.com \ No newline at end of file diff --git a/kubernetes/uninstall.sh b/kubernetes/uninstall.sh new file mode 100644 index 0000000..fda8b4e --- /dev/null +++ b/kubernetes/uninstall.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +kubectl delete namespace spring-cloud-kubernetes-demo \ No newline at end of file diff --git a/message-service/Dockerfile b/message-service/Dockerfile new file mode 100644 index 0000000..7990e98 --- /dev/null +++ b/message-service/Dockerfile @@ -0,0 +1,9 @@ +FROM openjdk:17 + +ADD build/libs/message-service.jar /usr/local/message-service/ + +WORKDIR /usr/local/message-service/ + +EXPOSE 8080 + +CMD ["java", "-jar", "message-service.jar"] \ No newline at end of file diff --git a/message-service/build.gradle b/message-service/build.gradle deleted file mode 100644 index 3532b89..0000000 --- a/message-service/build.gradle +++ /dev/null @@ -1,68 +0,0 @@ -plugins { - id 'org.springframework.boot' version '2.4.3' - id 'org.jetbrains.kotlin.jvm' version '1.4.30' - id 'org.jetbrains.kotlin.plugin.spring' version '1.4.30' - id 'io.spring.dependency-management' version '1.0.11.RELEASE' - - id "com.palantir.docker" version "0.21.0" -} - -apply plugin: 'io.spring.dependency-management' - -group = 'it.valeriovaudi' -java.sourceCompatibility = JavaVersion.VERSION_11 - -repositories { - mavenCentral() -} - -ext { - set('springCloudVersion', "2020.0.1") -} - -dependencies { - implementation 'org.springframework.cloud:spring-cloud-starter' - - implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-client-all' - - implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive' - implementation 'org.springframework.boot:spring-boot-starter-webflux' - implementation 'org.springframework.boot:spring-boot-starter-actuator' - - implementation 'com.fasterxml.jackson.module:jackson-module-kotlin' - implementation 'org.jetbrains.kotlin:kotlin-reflect' - implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' - - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'io.projectreactor:reactor-test' -} - - -dependencyManagement { - imports { - mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" - } -} - -compileKotlin { - kotlinOptions { - freeCompilerArgs = ['-Xjsr305=strict'] - jvmTarget = '11' - } -} - -compileTestKotlin { - kotlinOptions { - freeCompilerArgs = ['-Xjsr305=strict'] - jvmTarget = '11' - } -} - - -docker { - name 'mrflick72/message-service:latest' - dockerfile file('src/main/docker/Dockerfile') - copySpec.from("build/libs/message-service.jar").into("message-service.jar") - pull true - noCache true -} \ No newline at end of file diff --git a/message-service/build.gradle.kts b/message-service/build.gradle.kts new file mode 100644 index 0000000..c5d9051 --- /dev/null +++ b/message-service/build.gradle.kts @@ -0,0 +1,50 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.springframework.boot") version "2.7.4" + id("io.spring.dependency-management") version "1.0.14.RELEASE" + kotlin("jvm") version "1.6.21" + kotlin("plugin.spring") version "1.6.21" +} + +group = "it.valeriovaudi" +java.sourceCompatibility = JavaVersion.VERSION_17 + +repositories { + mavenCentral() +} + +extra["springCloudVersion"] = "2021.0.4" + + +dependencies { + implementation("org.springframework.cloud:spring-cloud-starter") + + implementation("org.springframework.cloud:spring-cloud-starter-kubernetes-client-all") + + implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive") + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("org.springframework.boot:spring-boot-starter-actuator") + + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") +} + + +dependencyManagement { + imports { + mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}") + } +} + +tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf("-Xjsr305=strict") + jvmTarget = "17" + } +} + +tasks.withType { + useJUnitPlatform() +} \ No newline at end of file diff --git a/message-service/gradle/wrapper/gradle-wrapper.jar b/message-service/gradle/wrapper/gradle-wrapper.jar index 87b738c..249e583 100644 Binary files a/message-service/gradle/wrapper/gradle-wrapper.jar and b/message-service/gradle/wrapper/gradle-wrapper.jar differ diff --git a/message-service/gradle/wrapper/gradle-wrapper.properties b/message-service/gradle/wrapper/gradle-wrapper.properties index 12d38de..8049c68 100644 --- a/message-service/gradle/wrapper/gradle-wrapper.properties +++ b/message-service/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/message-service/gradlew b/message-service/gradlew index af6708f..ab2855b 100755 --- a/message-service/gradlew +++ b/message-service/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed 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 +# +# https://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. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m"' +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -89,84 +140,101 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi -exec "$JAVACMD" "$@" +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" \ No newline at end of file diff --git a/message-service/gradlew.bat b/message-service/gradlew.bat index 0f8d593..a746093 100644 --- a/message-service/gradlew.bat +++ b/message-service/gradlew.bat @@ -1,4 +1,20 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -9,19 +25,22 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,40 +64,28 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal -:omega +:omega \ No newline at end of file diff --git a/message-service/settings.gradle b/message-service/settings.gradle deleted file mode 100644 index 158ae85..0000000 --- a/message-service/settings.gradle +++ /dev/null @@ -1,6 +0,0 @@ -pluginManagement { - repositories { - gradlePluginPortal() - } -} -rootProject.name = 'message-service' diff --git a/message-service/settings.gradle.kts b/message-service/settings.gradle.kts new file mode 100644 index 0000000..5f9fc02 --- /dev/null +++ b/message-service/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "message-service" \ No newline at end of file diff --git a/message-service/src/main/docker/Dockerfile b/message-service/src/main/docker/Dockerfile deleted file mode 100644 index 3a356ff..0000000 --- a/message-service/src/main/docker/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM openjdk:11 - -ADD message-service.jar /usr/local/message-service/ - -WORKDIR /usr/local/message-service/ - -EXPOSE 8080 - -CMD ["java", "-Xms512m", "-Xmx1g", "-jar", "message-service.jar"] \ No newline at end of file diff --git a/ui/Dockerfile b/ui/Dockerfile new file mode 100644 index 0000000..b6176b2 --- /dev/null +++ b/ui/Dockerfile @@ -0,0 +1,9 @@ +FROM openjdk:17 + +ADD target/ui-interface.jar /usr/local/ui-interface/ + +WORKDIR /usr/local/ui-interface/ + +EXPOSE 8080 + +CMD ["java", "-jar", "ui-interface.jar"] \ No newline at end of file diff --git a/ui/pom.xml b/ui/pom.xml index a1260f7..ec77390 100644 --- a/ui/pom.xml +++ b/ui/pom.xml @@ -5,18 +5,19 @@ org.springframework.boot spring-boot-starter-parent - 2.4.3 + 2.7.4 it.valeriovaudi ui - 0.0.1-SNAPSHOT + 1.0.0-SNAPSHOT ui Demo project for Spring Boot - 11 - 2020.0.1 + 17 + 2021.0.4 + 1.32 @@ -33,8 +34,8 @@ org.projectlombok lombok + true - org.springframework.session spring-session-core @@ -136,31 +137,6 @@ - - - com.spotify - docker-maven-plugin - 1.2.1 - - mrflick72/ui-interface:latest - src/main/docker - - - / - ${project.build.directory} - ${project.build.finalName}.jar - - - - - - - javax.activation - activation - 1.1.1 - - - diff --git a/ui/src/main/docker/Dockerfile b/ui/src/main/docker/Dockerfile deleted file mode 100644 index 1b0a8a1..0000000 --- a/ui/src/main/docker/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM openjdk:11 - -ADD ui-interface.jar /usr/local/ui-interface/ - -WORKDIR /usr/local/ui-interface/ - -EXPOSE 8080 - -CMD ["java", "-Xms512m", "-Xmx1g", "-jar", "ui-interface.jar"] \ No newline at end of file diff --git a/ui/src/main/frontend/app/site/MainSiteApp.js b/ui/src/main/frontend/app/site/MainSiteApp.js index d35142f..5dbd67a 100644 --- a/ui/src/main/frontend/app/site/MainSiteApp.js +++ b/ui/src/main/frontend/app/site/MainSiteApp.js @@ -36,7 +36,7 @@ export default class MainSiteApp extends React.Component { let bottomSection =

{this.state.message}

return - +