Skip to content

Commit

Permalink
cleaned up startup and added documentation in anticipation of adding …
Browse files Browse the repository at this point in the history
…docker deployment next
  • Loading branch information
markiantorno committed Oct 26, 2020
1 parent 849ca9e commit 75001bd
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 173 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Added gradle task to provide release version to pipelines
41 changes: 26 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
plugins {
kotlin("multiplatform") version "1.4.0"
kotlin("plugin.serialization") version "1.4.0"
id("org.hidetake.ssh") version "2.10.1"
id ("org.openjfx.javafxplugin") version "0.0.8"
application
}
group = "org.hl7.fhir"
version = "1.0-SNAPSHOT"
version = "0.0.1"

repositories {
google()
Expand Down Expand Up @@ -133,7 +134,7 @@ kotlin {
}
}
javafx {
version = "14"//"11.0.2"
version = "14"
modules("javafx.controls", "javafx.graphics", "javafx.web")
}
application {
Expand All @@ -154,20 +155,30 @@ tasks.getByName<JavaExec>("run") {
dependsOn(tasks.getByName<Jar>("jvmJar"))
classpath(tasks.getByName<Jar>("jvmJar"))
}
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "ServerKt"
}

// To add all of the dependencies otherwise a "NoClassDefFoundError" error
from(sourceSets.main.get().output)

dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
})
}
//
//tasks.withType<Jar> {
// manifest {
// attributes["Main-Class"] = "ServerKt"
// }
//
// // To add all of the dependencies otherwise a "NoClassDefFoundError" error
// from(sourceSets.main.get().output)
//
// dependsOn(configurations.runtimeClasspath)
// from({
// configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
// })
//}

tasks.withType<JavaCompile>().configureEach {
options.compilerArgs = listOf("-Xmx2g", "-XX:MaxMetaspaceSize=512m")
}

/**
* Utility function to retrieve the current version number.
*/
task("printVersion") {
doLast {
println(project.version)
}
}
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/constants/MIMETypes.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package constants

enum class MIMEType(val code: String, val image: String, val fhirType: String) {
JSON("text/xml", "images/xml_icon.svg", "xml"),
XML("application/json", "images/json_icon.svg", "json");
JSON("text/xml", "static/images/xml_icon.svg", "xml"),
XML("application/json", "static/images/json_icon.svg", "json");

companion object {
// Reverse-lookup map for getting a day from an abbreviation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import css.text.TextStyle
import css.widget.CheckboxStyle
import kotlinx.coroutines.launch
import kotlinx.css.*
import kotlinx.html.id
import kotlinx.html.js.onClickFunction
import mainScope
import model.CliContext
Expand Down
2 changes: 0 additions & 2 deletions src/jsMain/kotlin/ui/components/FileUpload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package ui.components
import css.component.FileUploadStyle
import css.widget.FABStyle
import kotlinx.browser.document
import kotlinx.coroutines.launch
import kotlinx.html.js.onClickFunction
import mainScope
import org.w3c.dom.HTMLInputElement
import react.*
import reactredux.containers.uploadFilesButton
Expand Down
8 changes: 0 additions & 8 deletions src/jsMain/kotlin/ui/components/generic/OptionEntryField.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package ui.components.generic

import css.component.OptionEntryFieldStyle
import css.const.GRAY_100
import css.const.ICON_SMALL_DIM
import css.const.SHADOW
import css.text.TextStyle
import css.widget.Spinner
import kotlinx.browser.document
import kotlinx.css.*
import kotlinx.css.properties.boxShadow
import kotlinx.html.id
import kotlinx.html.js.onClickFunction
import org.w3c.dom.HTMLTextAreaElement
import react.*
import react.dom.textArea
import styled.*

external interface OptionEntryFieldProps : RProps {
Expand Down
28 changes: 28 additions & 0 deletions src/jvmMain/kotlin/HtmlIndex.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import kotlinx.html.*

/**
* We use kotlinx to create this HTML index file which contains the reference to `/static/output.js`, the location
* of our generated JS code from KotlinJS. This is also where we load in our external fonts and set the main 'root' div.
*/
fun HTML.index() {
head {
meta {
charset = "UTF-8"
}
title("Validator GUI")
link(
href = "https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap",
rel = "stylesheet"
)
link(
href = "https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,900;1,200;1,300;1,400;1,500;1,600;1,700;1,900&display=swap",
rel = "stylesheet"
)
}
body {
div {
id = "root"
}
script(src = "/static/output.js") {}
}
}
100 changes: 100 additions & 0 deletions src/jvmMain/kotlin/Module.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.SerializationFeature
import desktop.launchLocalApp
import io.ktor.application.*
import io.ktor.features.*
import io.ktor.html.*
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.jackson.*
import io.ktor.routing.*
import kotlinx.html.*
import org.slf4j.event.Level
import routes.debugRoutes
import routes.igRoutes
import routes.validationRoutes
import routes.versionRoutes

/**
* Entry point of the application. This function is referenced in the resources/application.conf file (see the line
* that says `modules = [ ModuleKt.module ]`, pointing to this method.
*/
fun Application.module() {
// Any DB initialization will go here.
val starting: (Application) -> Unit = { log.info("Application starting: $it") }
val started: (Application) -> Unit = {
log.info("Application started: $it")
if (runningAsDesktopStandalone) {
launchLocalApp()
}
}
val stopping: (Application) -> Unit = { log.info("Application stopping: $it") }
var stopped: (Application) -> Unit = {}

stopped = {
log.info("Application stopped: $it")
environment.monitor.unsubscribe(ApplicationStarting, starting)
environment.monitor.unsubscribe(ApplicationStarted, started)
environment.monitor.unsubscribe(ApplicationStopping, stopping)
environment.monitor.unsubscribe(ApplicationStopped, stopped)
}

environment.monitor.subscribe(ApplicationStarted, starting)
environment.monitor.subscribe(ApplicationStarted, started)
environment.monitor.subscribe(ApplicationStopping, stopping)
environment.monitor.subscribe(ApplicationStopped, stopped)

// Now we call to a main with the dependencies as arguments.
// Separating this function with its dependencies allows us to provide several modules with
// the same code and different data-sources living in the same application,
// and to provide mocked instances for doing integration tests.
start()
}

/**
* Application extension function where we configure Ktor application with features, interceptors and routing.
*/
fun Application.start() {

install(CallLogging) {
level = Level.DEBUG
}

install(CORS) {
method(HttpMethod.Get)
method(HttpMethod.Post)
method(HttpMethod.Delete)
anyHost()
}

install(Compression) {
gzip()
}

install(ContentNegotiation) {
jackson {
enable(SerializationFeature.INDENT_OUTPUT)
/*
* Right now we need to ignore unknown fields because we take a very simplified version of many of the fhir
* model classes, and map them to classes across JVM/Common/JS.
*/
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
}
}

install(Routing) {
get("/") {
call.respondHtml(HttpStatusCode.OK, HTML::index)
}

static("/static") {
resources()
}
resources()
validationRoutes()
versionRoutes()
igRoutes()
// Only enable if things have gone horribly, and you need to add a debug logging endpoint.
//debugRoutes()
}
}
Loading

0 comments on commit 75001bd

Please sign in to comment.