92 lines
2.3 KiB
Kotlin
92 lines
2.3 KiB
Kotlin
#!/usr/bin/env kotlin
|
|
|
|
plugins {
|
|
kotlin("jvm") version "1.9.22"
|
|
kotlin("plugin.serialization") version "1.9.22"
|
|
application
|
|
}
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
implementation("io.ktor:ktor-server-core:2.3.7")
|
|
implementation("io.ktor:ktor-server-netty:2.3.7")
|
|
implementation("io.ktor:ktor-server-content-negotiation:2.3.7")
|
|
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.7")
|
|
implementation("io.ktor:ktor-server-websockets:2.3.7")
|
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
|
|
implementation("ch.qos.logback:logback-classic:1.4.14")
|
|
implementation("org.mariadb.jdbc:mariadb-java-client:3.3.3")
|
|
implementation("com.zaxxer:HikariCP:5.1.0")
|
|
implementation("io.ktor:ktor-server-compression:2.3.7")
|
|
testImplementation(kotlin("test"))
|
|
}
|
|
|
|
application {
|
|
mainClass.set("org.pavloveugene.iot.backend.ApplicationKt")
|
|
}
|
|
|
|
tasks.jar {
|
|
manifest {
|
|
attributes["Main-Class"] = "org.pavloveugene.iot.backend.ApplicationKt"
|
|
}
|
|
|
|
from({
|
|
configurations.runtimeClasspath.get().map { zipTree(it) }
|
|
})
|
|
|
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
}
|
|
|
|
tasks.processResources {
|
|
from("../db/migrations") {
|
|
into("db/migration")
|
|
}
|
|
}
|
|
|
|
tasks.register("deploy") {
|
|
dependsOn("jar")
|
|
|
|
doLast {
|
|
val jarFile = file("build/libs/backend.jar")
|
|
|
|
if (!jarFile.exists()) {
|
|
throw GradleException("Jar not found: ${jarFile.absolutePath}")
|
|
}
|
|
|
|
fun runCommand(vararg cmd: String) {
|
|
println("Running: ${cmd.joinToString(" ")}")
|
|
|
|
val process = ProcessBuilder(*cmd)
|
|
.inheritIO()
|
|
.start()
|
|
|
|
val exitCode = process.waitFor()
|
|
if (exitCode != 0) {
|
|
throw GradleException("Command failed: ${cmd.joinToString(" ")}")
|
|
}
|
|
}
|
|
|
|
// upload
|
|
runCommand(
|
|
"scp",
|
|
jarFile.absolutePath,
|
|
"home-iot:/tmp/backend.jar"
|
|
)
|
|
|
|
// deploy
|
|
runCommand(
|
|
"ssh",
|
|
"home-iot",
|
|
"sudo mv /tmp/backend.jar /opt/iot-backend/app.jar && sudo systemctl restart iot-backend"
|
|
)
|
|
|
|
runCommand("ssh",
|
|
"home-iot",
|
|
"systemctl status iot-backend --no-pager")
|
|
|
|
println("Deploy completed")
|
|
}
|
|
} |