Just to showcase/play around with spring boot, kotlin, java 13, docker, kubernetes
- Prerequisites
- Compilation
- Running everything with docker-compose
- Running the app outside docker
- Endpoints
- Creating Key pair
- Java 13
- Docker to run the project locally
- Optional : get a free access key for the currencies exchange api. The application will still run without it
If you use IntelliJ and want to use the maven wrapper you need to install the plugin Maven Wrapper support prior to opening the project
Choice to use either maven or gradle wrapper
Two profiles are available :
- jar : will build a fat jar
- war : will build a war deployable in tomcat
./mvnw clean package -Pjar
./mvnw clean package -Pwar
./mvnw clean package -Pwar -Djenkins.buildTag=${BUILD_TAG}
This work with both profile. BUILD_TAG is one of the environment variables set by jenkins for each build
./gradlew bootJar
./gradlew bootWar
./gradlew build -DjenkinsBuildTag=${BUILD_TAG}
BUILD_TAG is one of the environment variables set by jenkins for each build
You can build and run the app and its dependencies with docker-compose
cd docker
docker-compose -f docker-compose.yml up --build -d
If you want to debug the application run
cd docker
docker-compose -f docker-compose.yml -f docker-compose-debug.yml up --build -d
Then attach the debugger to the remote JVM on port 8000
If you are using Windows you may have to run the Docker Desktop and powershell as administrator, so the processes can create the ports they need.
First you need to run the dependencies : rabbitmq, redis
cd docker
docker-compose -f docker-compose-local.yml up -d
If you have selected the profile war during the build using either maven or gradle, you need to deploy the war to tomcat.
If you have build a fat jar by using either maven or gradle
java --enable-preview -jar sandbox-0.0.1-SNAPSHOT.jar --spring.profiles.active=local-docker --sandbox.exchangesrates.api.token=theRealToken
If you have selected the profile jar during the build, you can run with the following commands:
./mvnw spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=local-docker,--sandbox.exchangesrates.api.token=theRealToken
./gradlew bootRun --args='--spring.profiles.active=local-docker --sandbox.exchangesrates.api.token=theRealToken'
Spring actuator is activated and some endpoints are available
- See application health information
- Displays info about the application. Version, Java Version
- View some metrics
- Api Documentation (Swagger)
A key is used to sign the JWT Token, in case you want to create a new key, the following commands can be used.
To create a new key pair in a keystore
keytool -genkeypair -alias sandboxJwtKey -keyalg RSA -keypass SandboxSecurityFirst -keystore sandboxJwtKeystore.jks -storepass SandboxSecurityFirst
To extract the public key
# First extract the public certificate
keytool -export -keystore sandboxJwtKeystore.jks -alias sandboxJwtKey -file sandboxJwtKey.cer
# Then extract the public key from the certificate
openssl x509 -inform der -in sandboxJwtKey.cer -pubkey -noout > sandboxJwtPublicKey.pub