Migrate to Micronaut 4 + small improvements

Signed-off-by: Thraax Session <thraax.session@iatlas.technology>
This commit is contained in:
Thraax Session 2023-07-31 15:22:02 +02:00
parent aa7d86a702
commit 5ffbe20e1f
10 changed files with 95 additions and 82 deletions

View File

@ -1,4 +1,4 @@
FROM oracle/graalvm-ce:20.1.0-java11 as graalvm
FROM ghcr.io/graalvm/graalvm-ce:22.3.3 AS graalvm
RUN gu install native-image
COPY . /home/app/SpaceUp

View File

@ -6,7 +6,7 @@ plugins {
id "org.sonarqube" version "4.2.1.3168"
id "nebula.lint" version "18.1.0" // 18.0.0 works only with Gradle 8.x
//id "io.micronaut.aot" version "3.6.5"
id 'io.micronaut.application' version '3.7.10'
id 'io.micronaut.application' version '4.0.0'
id 'project-report'
id "application"
id 'maven-publish'
@ -44,43 +44,56 @@ configurations {
}
dependencies {
kapt(platform("io.micronaut:micronaut-bom:$micronautVersion"))
kapt 'io.micronaut:micronaut-inject-java:3.9.4'
kapt 'io.micronaut:micronaut-validation:3.9.4'
kapt(platform("io.micronaut.platform:micronaut-platform:$micronautVersion"))
kapt "io.micronaut:micronaut-inject-java:$micronautVersion"
//kapt "io.micronaut:micronaut-validation:3.9.4"
kapt "io.micronaut:micronaut-graal:$micronautVersion"
kapt 'io.micronaut.openapi:micronaut-openapi:4.9.2'
kapt 'io.micronaut.security:micronaut-security-annotations:3.11.1'
compileOnly(platform("io.micronaut:micronaut-bom:$micronautVersion"))
kapt 'io.micronaut.openapi:micronaut-openapi:5.0.1'
kapt 'io.micronaut.security:micronaut-security-annotations:4.0.1'
compileOnly(platform("io.micronaut.platform:micronaut-platform:$micronautVersion"))
compileOnly 'org.graalvm.nativeimage:svm:23.0.0'
implementation(platform("io.micronaut:micronaut-bom:$micronautVersion"))
implementation 'io.micronaut:micronaut-management:3.9.4'
implementation(platform("io.micronaut.platform:micronaut-platform:$micronautVersion"))
implementation("io.micronaut:micronaut-management:$micronautVersion")
implementation("io.micronaut:micronaut-jackson-databind")
implementation "io.swagger.core.v3:swagger-annotations"
implementation "io.micronaut:micronaut-inject:$micronautVersion"
implementation "io.micronaut:micronaut-validation:$micronautVersion"
implementation 'io.micronaut.rxjava3:micronaut-rxjava3:2.4.1'
implementation "io.reactivex.rxjava3:rxkotlin:3.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
//implementation "io.micronaut:micronaut-validation:3.9.4"
implementation 'io.micronaut.rxjava3:micronaut-rxjava3:3.0.1'
implementation 'io.micronaut.kotlin:micronaut-kotlin-runtime:3.2.2'
implementation "io.micronaut:micronaut-runtime:$micronautVersion"
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation "io.micronaut:micronaut-http-server-netty:$micronautVersion"
implementation "io.micronaut:micronaut-http-client:$micronautVersion"
implementation "io.micronaut.reactor:micronaut-reactor"
implementation 'io.micronaut:micronaut-tracing'
implementation("io.micronaut.tracing:micronaut-tracing-annotation:5.0.1")
implementation 'io.micronaut.security:micronaut-security:4.0.0'
implementation 'io.micronaut.security:micronaut-security-jwt:4.0.1'
implementation 'io.micronaut.kotlin:micronaut-kotlin-extension-functions:4.0.1'
implementation 'io.micronaut.mongodb:micronaut-mongo-reactive:5.0.1'
implementation("io.micronaut:micronaut-websocket")
developmentOnly("io.micronaut.controlpanel:micronaut-control-panel-ui")
developmentOnly("io.micronaut.controlpanel:micronaut-control-panel-management")
//runtimeOnly("io.micronaut.:micronaut-management")
annotationProcessor("io.micronaut.validation:micronaut-validation-processor")
implementation("io.micronaut.validation:micronaut-validation")
implementation "io.reactivex.rxjava3:rxkotlin:3.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
//implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation "io.opentracing.brave:brave-opentracing:1.0.0"
// https://mvnrepository.com/artifact/io.zipkin.brave/brave-context-log4j2
implementation 'io.zipkin.brave:brave-context-log4j2:5.16.0'
runtimeOnly "io.zipkin.brave:brave-instrumentation-httpclient:5.16.0"
runtimeOnly "io.zipkin.reporter:zipkin-reporter:1.1.2"
implementation 'io.micronaut.security:micronaut-security:3.11.1'
implementation 'io.micronaut.security:micronaut-security-jwt:3.11.1'
implementation 'io.micronaut.kotlin:micronaut-kotlin-extension-functions:3.2.2'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2'
implementation 'com.github.mwiede:jsch:0.2.9'
// NoSQL
implementation 'io.micronaut.mongodb:micronaut-mongo-reactive:4.6.0'
implementation 'com.github.mwiede:jsch:0.2.10'
//implementation('org.litote.kmongo:kmongo:4.7.2')
implementation 'org.litote.kmongo:kmongo-coroutine:4.9.0'
@ -97,16 +110,16 @@ dependencies {
implementation "technology.iatlas.sws:sws:1.5.1-SNAPSHOT"
implementation "org.codehaus.janino:janino:3.1.10"
implementation 'ch.qos.logback:logback-classic:1.4.8'
runtimeOnly 'ch.qos.logback:logback-classic:1.4.8'
implementation 'org.slf4j:log4j-over-slf4j:2.0.7'
//runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly 'com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2'
runtimeOnly 'io.netty:netty-tcnative:2.0.61.Final'
runtimeOnly 'io.netty:netty-tcnative-boringssl-static:2.0.61.Final'
implementation "org.reflections:reflections:0.10.2"
kaptTest(enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion"))
kaptTest(enforcedPlatform("io.micronaut.platform:micronaut-platform:$micronautVersion"))
kaptTest "io.micronaut:micronaut-inject-java:$micronautVersion"
testImplementation(enforcedPlatform("io.micronaut:micronaut-bom:$micronautVersion"))
testImplementation(enforcedPlatform("io.micronaut.platform:micronaut-platform:$micronautVersion"))
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
testImplementation "io.micronaut.test:micronaut-test-junit5:$micronautVersion"
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
@ -124,7 +137,7 @@ test {
}
kotlin {
jvmToolchain(11)
jvmToolchain(17)
}
allOpen {

View File

@ -39,7 +39,6 @@
#
# Thanks, and we hope you enjoy using SpaceUp-Server and that it's everything you ever hoped it could be.
#
micronautVersion=3.9.4
micronautVersion=4.0.2
kotlinVersion=1.9.0
kotlin.code.style=official

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2022 Thraax Session <spaceup@iatlas.technology>.
# Copyright (c) 2022-2023 Thraax Session <spaceup@iatlas.technology>.
#
# SpaceUp-Server is free software; You can redistribute it and/or modify it under the terms of:
# - the GNU Affero General Public License version 3 as published by the Free Software Foundation.
@ -42,6 +42,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -43,6 +43,7 @@
package technology.iatlas.spaceup.core.auth
import io.micronaut.context.annotation.Context
import io.micronaut.core.annotation.Nullable
import io.micronaut.core.type.Argument
import io.micronaut.http.HttpRequest
import io.micronaut.http.client.HttpClient
@ -75,21 +76,21 @@ import technology.iatlas.spaceup.services.SpaceUpService
@Installed
@Context
class AuthenticationProviderUserPassword(
class AuthenticationProviderUserPassword<T>(
private val dbService: DbService,
private val securityService: SecurityService,
private val httpClient: HttpClient,
private val spaceUpService: SpaceUpService
) : AuthenticationProvider {
) : AuthenticationProvider<T> {
private val log = LoggerFactory.getLogger(AuthenticationProviderUserPassword::class.java)
private val dispatcher: CoroutineDispatcher = Dispatchers.Default
private var ip: String = ""
override fun authenticate(
httpRequest: HttpRequest<*>?,
@Nullable httpRequest: @Nullable T,
authenticationRequest: AuthenticationRequest<*, *>?
): Publisher<AuthenticationResponse> {
): Publisher<AuthenticationResponse>? {
val authPublisher = Flowable.create({ emitter: FlowableEmitter<AuthenticationResponse> ->
runBlocking {
if (httpRequest != null) {
@ -148,9 +149,10 @@ class AuthenticationProviderUserPassword(
}, BackpressureStrategy.ERROR)
}
private fun validateIp(httpRequest: HttpRequest<*>): Mono<GeoIpRipe> {
ip = httpRequest.headers.get("X-Forwarded-For") ?: httpRequest.remoteAddress.address.hostAddress
log.debug("Possible authentication from $ip with headers ${httpRequest.headers.asMap()}")
private fun validateIp(httpRequest: T): Mono<GeoIpRipe> {
val incomingRequest = httpRequest as HttpRequest<*>
ip = incomingRequest.headers["X-Forwarded-For"] ?: incomingRequest.remoteAddress.address.hostAddress
log.debug("Possible authentication from {} with headers {}", ip, incomingRequest.headers.asMap())
// Make it work for local development / requests
return if (ip == "localhost" || ip == "127.0.0.1" || ip == "0:0:0:0:0:0:0:1" || spaceUpService.isDevMode()) {

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2022 spaceup@iatlas.technology.
* Copyright (c) 2022-2023 Thraax Session <spaceup@iatlas.technology>.
*
* SpaceUp-Server is free software; You can redistribute it and/or modify it under the terms of:
* - the GNU Affero General Public License version 3 as published by the Free Software Foundation.
* You don't have to do anything special to accept the license and you dont have to notify anyone which that you have made that decision.
@ -11,7 +12,6 @@
* You should have received a copy of both licenses along with SpaceUp-Server
* If not, see <http://www.gnu.org/licenses/>.
*
*
* There is a strong belief within us that the license we have chosen provides not only the best solution for providing you with the essential freedom necessary to use SpaceUp-Server within your projects, but also for maintaining enough copyleft strength for us to feel confident and secure with releasing our hard work to the public. For your convenience we've included our own interpretation of the license we chose, which can be seen below.
*
* Our interpretation of the GNU Affero General Public License version 3: (Quoted words are words in which there exists a definition within the license to avoid ambiguity.)
@ -55,10 +55,8 @@ class EchoParser : ParserInf<String> {
}
override fun parseSshOutput(sshResponse: SshResponse): String {
log.trace("Echo output: $sshResponse")
return if(sshResponse.stderr.isNotEmpty()) {
sshResponse.stderr
} else {
log.trace("Echo output: {}", sshResponse)
return sshResponse.stderr.ifEmpty {
sshResponse.stdout
}
}

View File

@ -66,7 +66,12 @@ import technology.iatlas.spaceup.core.helper.colored
import technology.iatlas.spaceup.dto.Command
import technology.iatlas.spaceup.dto.db.Server
import technology.iatlas.spaceup.isOk
import technology.iatlas.spaceup.services.*
import technology.iatlas.spaceup.services.DbService
import technology.iatlas.spaceup.services.InstallerService
import technology.iatlas.spaceup.services.SpaceUpService
import technology.iatlas.spaceup.services.SshService
import technology.iatlas.spaceup.services.SwsService
import technology.iatlas.spaceup.services.WsServiceInf
import technology.iatlas.spaceup.util.createNormalizedPath
import kotlin.io.path.Path
import kotlin.io.path.createDirectories
@ -150,7 +155,7 @@ open class StartupEventListener(
val dirs = listOf(spaceupRemotePathConfig.temp)
dirs.forEach {
log.info("create $it")
log.info("Create $it")
val cmd = Command(mutableListOf("mkdir", "-p", it))
val feedback = sshService.execute(cmd).toFeedback()

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Thraax Session <spaceup@iatlas.technology>.
* Copyright (c) 2022-2023 Thraax Session <spaceup@iatlas.technology>.
*
* SpaceUp-Server is free software; You can redistribute it and/or modify it under the terms of:
* - the GNU Affero General Public License version 3 as published by the Free Software Foundation.
@ -42,22 +42,21 @@
package technology.iatlas.spaceup.services
import io.micronaut.context.annotation.Context
import io.micronaut.scheduling.annotation.Scheduled
import io.micronaut.tracing.annotation.NewSpan
import jakarta.inject.Singleton
import kotlinx.coroutines.runBlocking
import org.slf4j.LoggerFactory
@Context
open class SchedulerService(
@Singleton
class SchedulerService(
private val domainService: DomainService,
private val dbService: DbService
) {
private val log = LoggerFactory.getLogger(SchedulerService::class.java)
@NewSpan("scheduler-domains-update")
//@NewSpan("scheduler-domains-update")
@Scheduled(fixedRate = "\${spaceup.scheduler.domains.update}", initialDelay = "\${spaceup.scheduler.delayed}")
open fun updateDomainList() = runBlocking {
internal fun updateDomainList() = runBlocking {
if(dbService.isAppInstalled()) {
log.debug("Update domain list")
domainService.updateDomainList()

View File

@ -1,5 +1,6 @@
#
# Copyright (c) 2022 spaceup@iatlas.technology.
# Copyright (c) 2022-2023 Thraax Session <spaceup@iatlas.technology>.
#
# SpaceUp-Server is free software; You can redistribute it and/or modify it under the terms of:
# - the GNU Affero General Public License version 3 as published by the Free Software Foundation.
# You don't have to do anything special to accept the license and you don?t have to notify anyone which that you have made that decision.
@ -11,7 +12,6 @@
# You should have received a copy of both licenses along with SpaceUp-Server
# If not, see <http://www.gnu.org/licenses/>.
#
#
# There is a strong belief within us that the license we have chosen provides not only the best solution for providing you with the essential freedom necessary to use SpaceUp-Server within your projects, but also for maintaining enough copyleft strength for us to feel confident and secure with releasing our hard work to the public. For your convenience we've included our own interpretation of the license we chose, which can be seen below.
#
# Our interpretation of the GNU Affero General Public License version 3: (Quoted words are words in which there exists a definition within the license to avoid ambiguity.)
@ -44,5 +44,4 @@ Args = -H:Name=spaceup-server \
-H:Class=technology.iatlas.spaceup.ApplicationKt \
-H:IncludeResources=logback.xml|log4j2.xml|application.properties \
-H:EnableURLProtocols=http,https \
-H:ConfigurationResourceRoots=native-config \
--allow-incomplete-classpath
-H:ConfigurationResourceRoots=native-config

View File

@ -55,23 +55,13 @@ micronaut.views.csp.policy-directives=default-src 'self'; \
base-uri 'self'; \
child-src 'self'; \
# worker-src 'self' localhost;
micronaut.control-panel.panels.*.enabled=true
# For websocket important
micronaut.heartbeat.enabled=true
# Should not time out
micronaut.server.idle-timeout=-1m
# Enable management endpoints
endpoints.all.enabled=true
endpoints.all.sensitive=false
endpoints.health.details-visible=ANONYMOUS
# Tracing / Jaeger
#tracing.jaeger.enabled=false
#tracing.jaeger.sampler.probability=1
#tracing.jaeger.sender.agent-host=your.host
#tracing.jaeger.sender.agent-port=your_port
micronaut.security.enabled=true
micronaut.security.authentication=bearer
# The secret needs to be 256bit at least
@ -81,22 +71,26 @@ micronaut.ssl.enabled=false
micronaut.server.ssl.build-self-signed=true
#micronaut.server.http-version=1.1
micronaut.server.ssl.port=9094
# Tracing
# Enable management endpoints
endpoints.all.enabled=true
endpoints.all.sensitive=false
endpoints.health.details-visible=ANONYMOUS
endpoints.env.enabled=true
endpoints.s.sensitive=false
# Tracing / Jaeger
#tracing.jaeger.enabled=false
#tracing.jaeger.sampler.probability=1
#tracing.jaeger.sender.agent-host=your.host
#tracing.jaeger.sender.agent-port=your_port
tracing.jaeger.enabled=false
tracing.jaeger.http.url=http://localhost:9411
tracing.jaeger.sampler.probability=1
#micronaut.caches.my-cache.maximumSize=100
# Hotreload for views
#micronaut.views.rocker.hot-reloading=true
micronaut.openapi.property.naming.strategy=KEBAB_CASE
#micronaut.openapi.target.file=spaceup-openapi.yml
# Defaults
spaceup.home=${user.home}/.spaceup
# Web client
# Will be used to download the client there
spaceup.ui.dir=${spaceup.home}/static/ui
spaceup.ui.enabled=false
micronaut.router.static-resources.default.mapping=/ui/**
micronaut.router.static-resources.default.enabled=${spaceup.ui.enabled}
@ -112,12 +106,16 @@ micronaut.router.static-resources.rapidoc.mapping=/rapidoc/**
micronaut.router.static-resources.swagger-ui.paths=classpath:META-INF/swagger/views/swagger-ui
micronaut.router.static-resources.swagger-ui.mapping=/swagger-ui/**
# Cache configuration
micronaut.caches.client-controller-link.maximum-size=20
#########################
# SpaceUp configuration #
#########################
# Default SpaceUp directory
spaceup.home=${user.home}/.spaceup
# Web client
# Will be used to download the client there
spaceup.ui.dir=${spaceup.home}/static/ui
spaceup.ui.enabled=false
devurl.Swagger.enabled=true
devurl.Swagger.mapping=/swagger-ui
@ -129,7 +127,7 @@ devurl.Redoc.newtab=true
# Spaceup path configuration
spaceup.remote.path.services=~/etc/services.d/
spaceup.remote.path.logs=~/logs/
spaceup.remote.path.temp=~/.spaceup/tmp
spaceup.remote.path.temp=${spaceup.home}/tmp
# For windows the local path will be transformed
spaceup.local.path.temp=${spaceup.remote.path.temp}