Commit 07c87aa7 authored by David's avatar David
Browse files

Got the kotlin working, and probably the native image

parent e49c6994
FROM adoptopenjdk/openjdk11-openj9:jdk-11.0.1.13-alpine-slim
COPY build/libs/complete-*-all.jar complete.jar
EXPOSE 8080
CMD java -Dcom.sun.management.jmxremote -noverify ${JAVA_OPTS} -jar complete.jar
\ No newline at end of file
package `is`.kow.homeedms.documents
import java.nio.file.Path
import java.util.*
data class Document(
val uuid: UUID, //Document UUID
val path: Path //Relative to media root
)
\ No newline at end of file
package `is`.kow.homeedms.documents
import `is`.kow.homeedms.ApplicationConfiguration
import io.reactivex.Observable
import io.reactivex.disposables.Disposable
import org.reactivestreams.Subscription
import org.slf4j.LoggerFactory
import java.util.*
import java.util.concurrent.TimeUnit
import javax.annotation.PostConstruct
import javax.inject.Singleton
@Singleton
class StagingWatcher(
private val config: ApplicationConfiguration
) {
val logger = LoggerFactory.getLogger(StagingWatcher::class.java)
val subscriptions: Stack<Disposable> = Stack()
@PostConstruct
fun init() {
while (subscriptions.isNotEmpty()) {
subscriptions.pop().dispose() //turn them off!
}
val watcher = Observable.interval(0, 500, TimeUnit.MILLISECONDS)
.map { count ->
logger.debug("Checking ${config.watchDirectory} at ${count}")
}
subscriptions.push(watcher.subscribe())
}
//TODO: create and start up a Observer watching for documents
}
\ No newline at end of file
micronaut:
application:
name: HomeEDMS
router:
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
---
postgres:
reactive:
client:
port: ${app.pgPort}
host: ${app.pgHost}
database: ${app.pgDatabase}
user: ${app.pgUser}
password: ${app.pgPass}
maxSize: 5
create table documents (
uuid uuid not null primary key
);
create table tags (
id serial primary key,
name varchar not null,
description varchar,
UNIQUE(name)
);
create table document_tags(
document_id uuid references documents(uuid),
tag_id serial references tags(id)
);
\ No newline at end of file
postgresql/
postgresql_data/
.kotlintest
homeedms
#FROM oracle/graalvm-ce:19.3.0-java8 as graalvm
# For JDK 11
FROM oracle/graalvm-ce:19.3.0-java11 as graalvm
COPY . /home/app/homeedms
WORKDIR /home/app/homeedms
RUN gu install native-image
RUN native-image \
--initialize-at-run-time=io.netty.buffer.AbstractReferenceCountedByteBuf,io.netty.util.AbstractReferenceCounted \
--no-server \
--static \
-cp build/libs/homeedms-*-all.jar
FROM frolvlad/alpine-glibc
EXPOSE 8080
COPY --from=graalvm /home/app/homeedms/homeedms /app/homeedms
ENTRYPOINT ["/app/homeedms", "-Djava.library.path=/app"]
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.hibernate:hibernate-gradle-plugin:5.4.3.Final"
}
}
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.50"
id "org.jetbrains.kotlin.kapt" version "1.3.50"
......@@ -7,7 +16,7 @@ plugins {
id "application"
}
apply plugin: 'org.hibernate.orm'
version "0.1"
group "example.micronaut"
......@@ -22,6 +31,14 @@ configurations {
developmentOnly
}
hibernate {
enhance {
enableLazyInitialization = true
enableDirtyTracking = true
enableAssociationManagement = true
}
}
dependencies {
implementation platform("io.micronaut:micronaut-bom:$micronautVersion")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
......@@ -30,6 +47,9 @@ dependencies {
implementation "javax.annotation:javax.annotation-api"
implementation "io.micronaut:micronaut-http-server-netty"
implementation "io.micronaut:micronaut-http-client"
kapt "io.micronaut:micronaut-graal"
compileOnly "org.graalvm.nativeimage:svm"
kapt platform("io.micronaut:micronaut-bom:$micronautVersion")
kapt "io.micronaut:micronaut-inject-java"
kapt "io.micronaut:micronaut-validation"
......@@ -52,14 +72,28 @@ dependencies {
testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
implementation 'io.micronaut.configuration:micronaut-flyway'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.9'
implementation 'io.micronaut.configuration:micronaut-postgres-reactive'
kapt 'io.micronaut.data:micronaut-data-processor:1.0.0.M5'
implementation 'io.micronaut.data:micronaut-data-hibernate-jpa:1.0.0.M5', {
exclude group:'io.micronaut.configuration', module:'micronaut-hibernate-jpa-spring'
}
runtime "io.micronaut.configuration:micronaut-jdbc-hikari"
runtime group: 'org.postgresql', name: 'postgresql', version: '42.2.9'
kapt "io.micronaut.configuration:micronaut-openapi"
compile "io.swagger.core.v3:swagger-annotations"
// https://mvnrepository.com/artifact/com.j256.simplemagic/simplemagic
implementation group: 'com.j256.simplemagic', name: 'simplemagic', version: '1.16'
api("com.github.pozo:mapstruct-kotlin:1.3.1.0")
kapt("com.github.pozo:mapstruct-kotlin-processor:1.3.1.0")
kapt "org.mapstruct:mapstruct-processor:1.3.1.Final"
implementation "org.mapstruct:mapstruct:1.3.1.Final"
// webResources(project(path = ":admin-frontend", configuration = "webResources"))
}
......@@ -113,6 +147,10 @@ shadowJar {
kapt {
useBuildCache = false
arguments {
arg("mapstruct.defaultComponentModel", "jsr330")
}
}
run.classpath += configurations.developmentOnly
......
#!/bin/sh
docker build . -t homeedms
echo
echo
echo "To run the docker container execute:"
echo " $ docker run -p 8080:8080 homeedms"
#!/bin/bash
set -euxo pipefail
export JENV_VERSION="graalvm64-11.0.5"
gu install native-image
# --initialize-at-run-time=io.netty.buffer.AbstractReferenceCountedByteBuf,io.netty.util.AbstractReferenceCounted \
native-image \
--no-server \
--initialize-at-build-time=org.jboss.logging,org.hibernate.internal.CoreMessageLogger_\$logger \
--static \
-cp build/libs/homeedms-*-all.jar \
-H:+TraceClassInitialization
package `is`.kow.homeedms
import `is`.kow.homeedms.documents.StagingWatcher
import io.micronaut.configuration.postgres.reactive.PgPoolConfiguration
import io.micronaut.core.annotation.TypeHint
import io.micronaut.runtime.Micronaut
import io.swagger.v3.oas.annotations.OpenAPIDefinition
import io.swagger.v3.oas.annotations.info.Contact
import io.swagger.v3.oas.annotations.info.Info
import io.swagger.v3.oas.annotations.info.License
import org.flywaydb.core.Flyway
import org.hibernate.dialect.PostgreSQL10Dialect
import org.slf4j.LoggerFactory
......@@ -20,6 +21,10 @@ import org.slf4j.LoggerFactory
contact = Contact(url = "https://david.kow.is", name = "David Kowis", email = "david@kow.is")
)
)
@TypeHint(typeNames = [
"org.postgresql.Driver",
"org.hibernate.dialect.PostgreSQL10Dialect"
])
object Application {
val logger = LoggerFactory.getLogger(Application::class.java)
......@@ -35,17 +40,7 @@ object Application {
val environment = context.getEnvironment()
logger.debug("Active Environments: ${environment.activeNames.joinToString(", ")}")
val options: PgPoolConfiguration = context.getBean(PgPoolConfiguration::class.java)
val flyway = Flyway.configure()
.dataSource("jdbc:postgresql://${options.pgPoolOptions.host}:${options.pgPoolOptions.port}/${options.pgPoolOptions.database}",
options.pgPoolOptions.user,
options.pgPoolOptions.password)
.load()
logger.info("Beginning Flyway migrations!")
flyway.migrate()
val stagingWatcher = context.getBean(StagingWatcher::class.java)
logger.debug("Got the staging watcher")
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment