Skip to content

Commit

Permalink
Migrate project to Micronaut
Browse files Browse the repository at this point in the history
  • Loading branch information
EliasJorgensen committed Jun 8, 2024
1 parent ba07e48 commit 7ab906e
Show file tree
Hide file tree
Showing 45 changed files with 411 additions and 357 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
HEIMDALL_URL=http://localhost:8080
HEIMDALL_SUCCESS=http://localhost:8080/success
HEIMDALL_FAILURE=http://localhost:8080/failure

GOOGLE_AID=
GOOGLE_SECRET=

MSID_AID=
MSID_SECRET=
MSID_TENANT=common

KEYSTORE_PRIVATE_KEY_PASSWORD=pk-password
KEYSTORE_PASSWORD=keystore-password
30 changes: 30 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
distribution: corretto

- name: Validate Gradle wrapper
uses: gradle/[email protected]

- name: Build with Gradle
uses: gradle/[email protected]
with:
arguments: build
42 changes: 11 additions & 31 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,40 +1,20 @@
Thumbs.db
.DS_Store
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
target/
out/
.micronaut/
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
*.iws
.project
.settings
.classpath
.factorypath

### Project ###
heimdall.jks
heimdall-storage
.env
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM amazoncorretto:21

ADD build/distributions/heimdall.tar ./
RUN chmod a+rw heimdall
WORKDIR ./heimdall
ADD build/distributions/heimdall-optimized-0.1.tar ./
RUN chmod a+rw heimdall-optimized-0.1
WORKDIR ./heimdall-optimized-0.1
EXPOSE 8080

ENV TZ="UTC"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Heimdall
User Authentication service
User Authentication service
78 changes: 56 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
plugins {
application
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.kotlin.all.open)
alias(libs.plugins.ksp)
alias(libs.plugins.johnrengelman.shadow)
alias(libs.plugins.micronaut.application)
alias(libs.plugins.micronaut.aot)
alias(libs.plugins.kotlinter)
}

version = "0.1"
group = "com.qualitive"
version = "1.0.0"

kotlin {
jvmToolchain(21)
}

application {
mainClass.set("io.ktor.server.netty.EngineMain")

val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}

repositories {
mavenCentral()
}

dependencies {
implementation(libs.bundles.ktor)
ksp(libs.micronaut.http.validation)

implementation(libs.logback)
compileOnly(libs.micronaut.http.client)
implementation(libs.micronaut.jackson.databind)
implementation(libs.micronaut.kotlin.runtime)

implementation(libs.kotlin.reflect)
implementation(libs.kotlin.stdlib)

runtimeOnly(libs.jackson.kotlin)

runtimeOnly(libs.logback)
implementation(libs.logstash.logbackEncoder)
implementation(libs.kotlinLogging)

implementation(libs.bouncycastle.bcprov)
Expand All @@ -35,20 +37,52 @@ dependencies {
implementation(libs.scribejava.apis)
implementation(libs.auth0.jwt)

implementation(libs.logstash.logbackEncoder)
testImplementation(libs.micronaut.http.client)
}

testImplementation(libs.ktor.test)
testImplementation(libs.kotlin.test)

application {
mainClass = "com.qualitive.heimdall.ApplicationKt"
}
java {
sourceCompatibility = JavaVersion.toVersion("21")
}


graalvmNative.toolchainDetection = false
micronaut {
runtime("netty")
testRuntime("kotest5")
processing {
incremental(true)
annotations("com.qualitive.*")
}
aot {
// Please review carefully the optimizations enabled below
// Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details
optimizeServiceLoading = false
convertYamlToJava = false
precomputeOperations = true
cacheEnvironment = true
optimizeClassLoading = true
deduceEnvironment = true
optimizeNetty = true
replaceLogbackXml = true
}
}

tasks.test {
ignoreFailures = false
useJUnitPlatform()
ignoreFailures = false

// Never use existing jks
doFirst { delete("${project.projectDir}/heimdall.jks")}
doLast { delete("${project.projectDir}/heimdall.jks") }
}

tasks.distTar { archiveFileName.set("heimdall.tar") }
tasks.distZip { enabled = false }

tasks.named<io.micronaut.gradle.docker.NativeImageDockerfile>("dockerfileNative") {
jdkVersion = "21"
}


31 changes: 18 additions & 13 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
services:
heimdall:
build: .
container_name: heimdall
ports:
- "8080:8080"
environment:
- HEIMDALL_SUCCESS=http://localhost:8081/heimdall-success
- HEIMDALL_FAILURE=http://localhost:8080/loginerror
- HEIMDALL_URL=http://localhost:8080
- KEYSTORE_PASS=heimdall
- PRIVATE_KEY_PASS=heimdall
volumes:
- ./heimdall-storage:/var/lib/heimdall
heimdall:
build: .
container_name: heimdall
ports:
- "8080:8080"
environment:
- HEIMDALL_URL=${HEIMDALL_URL}
- HEIMDALL_SUCCESS=${HEIMDALL_SUCCESS}
- HEIMDALL_FAILURE=${HEIMDALL_FAILURE}
- HEIMDALL_GOOGLE_AID=${GOOGLE_AID}
- HEIMDALL_GOOGLE_SECRET=${GOOGLE_SECRET}
- HEIMDALL_MSID_AID=${MSID_AID}
- HEIMDALL_MSID_SECRET=${MSID_SECRET}
- HEIMDALL_MSID_TENANT=${MSID_TENANT}
- KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD}
- KEYSTORE_PRIVATE_KEY_PASSWORD=${KEYSTORE_PRIVATE_KEY_PASSWORD}
volumes:
- ./heimdall-storage:/var/lib/heimdall
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
kotlin.code.style=official
micronautVersion=4.4.3
kotlinVersion=1.9.23
org.gradle.jvmargs=-Xmx4096M
30 changes: 16 additions & 14 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
[versions]
ktorVersion = "3.0.0-beta-1"
kotlinVersion = "1.9.22"
kotlinVersion = "2.0.0"
logbackVersion = "1.4.14"
kotlinterVersion = "4.2.0"
bouncyCastleVersion = "1.77"
scribeVersion = "8.3.3"
micronautVersion = "4.3.0"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit5", version.ref = "kotlinVersion" }
micronaut-http-validation = { module = "io.micronaut:micronaut-http-validation", version.ref = "micronautVersion" }
micronaut-jackson-databind = { module = "io.micronaut:micronaut-jackson-databind", version.ref = "micronautVersion" }
micronaut-kotlin-runtime = { module = "io.micronaut.kotlin:micronaut-kotlin-runtime", version.ref = "micronautVersion" }
micronaut-http-client = { module = "io.micronaut:micronaut-http-client", version.ref = "micronautVersion" }

ktor-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktorVersion" }
ktor-contentNegotiation = { module = "io.ktor:ktor-server-content-negotiation-jvm", version.ref = "ktorVersion" }
ktor-serialization = { module = "io.ktor:ktor-serialization-kotlinx-json-jvm", version.ref = "ktorVersion" }
ktor-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktorVersion" }
ktor-test = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktorVersion" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlinVersion" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlinVersion" }

jackson-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin" }

logback = { module = "ch.qos.logback:logback-classic", version.ref = "logbackVersion" }
logstash-logbackEncoder = { module = "net.logstash.logback:logstash-logback-encoder", version = "7.4" }
kotlinLogging = { module = "io.github.oshai:kotlin-logging-jvm", version = "5.1.0" }

bouncycastle-bcprov = { module = "org.bouncycastle:bcprov-jdk18on", version.ref = "bouncyCastleVersion" }
Expand All @@ -25,12 +28,11 @@ scribejava-core = { module = "com.github.scribejava:scribejava-core", version.re
scribejava-apis = { module = "com.github.scribejava:scribejava-apis", version.ref = "scribeVersion" }
auth0-jwt = { module = "com.auth0:java-jwt", version = "4.4.0" }

logstash-logbackEncoder = { module = "net.logstash.logback:logstash-logback-encoder", version = "7.4" }

[bundles]
ktor = ["ktor-core", "ktor-contentNegotiation", "ktor-netty", "ktor-serialization"]

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlinVersion" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinVersion" }
kotlin-all-open = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlinVersion" }
ksp = { id = "com.google.devtools.ksp", version = "2.0.0-1.0.22"}
johnrengelman-shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1"}
kotlinter = { id = "org.jmailen.kotlinter", version.ref = "kotlinterVersion" }
micronaut-application = { id = "io.micronaut.application", version.ref = "micronautVersion"}
micronaut-aot = { id = "io.micronaut.aot", version.ref = "micronautVersion"}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ 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.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ 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.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = "heimdall"
rootProject.name="heimdall"
18 changes: 0 additions & 18 deletions src/main/kotlin/com/qualitive/Application.kt

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/kotlin/com/qualitive/heimdall/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.qualitive.heimdall

import io.micronaut.runtime.Micronaut.run

fun main(args: Array<String>) {
run(*args)
}
Loading

0 comments on commit 7ab906e

Please sign in to comment.