2022-09-03 11:54:56 +03:00
|
|
|
import space.kscience.gradle.KScienceVersions
|
2022-06-30 20:51:57 +03:00
|
|
|
import space.kscience.snark.plugin.JSch
|
|
|
|
import space.kscience.snark.plugin.execute
|
|
|
|
import space.kscience.snark.plugin.uploadDirectory
|
|
|
|
import space.kscience.snark.plugin.useSession
|
2022-04-23 10:48:53 +03:00
|
|
|
|
|
|
|
plugins {
|
2022-09-03 11:54:56 +03:00
|
|
|
id("space.kscience.gradle.project")
|
|
|
|
id("space.kscience.gradle.jvm")
|
2022-06-30 20:51:57 +03:00
|
|
|
id("space.kscience.snark")
|
2022-04-30 10:32:00 +03:00
|
|
|
application
|
|
|
|
}
|
|
|
|
|
2023-01-23 20:33:48 +03:00
|
|
|
group = "center.sciprog"
|
2022-06-26 13:14:57 +03:00
|
|
|
version = "0.1.0"
|
2022-04-23 10:48:53 +03:00
|
|
|
|
|
|
|
application {
|
2022-05-14 11:08:28 +03:00
|
|
|
mainClass.set("io.ktor.server.netty.EngineMain")
|
2022-04-23 10:48:53 +03:00
|
|
|
|
|
|
|
val isDevelopment: Boolean = project.ext.has("development")
|
2022-05-03 13:33:43 +03:00
|
|
|
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment", "-Xmx200M")
|
2022-04-23 10:48:53 +03:00
|
|
|
}
|
|
|
|
|
2022-07-03 16:39:38 +03:00
|
|
|
val snarkVersion: String by extra
|
2022-05-06 15:54:59 +03:00
|
|
|
val ktorVersion = KScienceVersions.ktorVersion
|
2022-04-30 10:32:00 +03:00
|
|
|
|
2023-03-13 16:25:21 +03:00
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
|
|
|
mavenLocal()
|
|
|
|
}
|
|
|
|
|
2022-04-23 10:48:53 +03:00
|
|
|
dependencies {
|
2022-06-30 20:51:57 +03:00
|
|
|
implementation("space.kscience:snark-ktor:$snarkVersion")
|
|
|
|
|
2022-04-30 10:32:00 +03:00
|
|
|
implementation("io.ktor:ktor-server-netty:$ktorVersion")
|
2022-06-23 11:02:26 +03:00
|
|
|
implementation("io.ktor:ktor-server-http-redirect:$ktorVersion")
|
2022-09-03 14:11:36 +03:00
|
|
|
implementation("io.ktor:ktor-server-forwarded-header:$ktorVersion")
|
2024-01-04 11:26:23 +03:00
|
|
|
implementation("ch.qos.logback:logback-classic:1.4.12")
|
2022-04-23 10:59:05 +03:00
|
|
|
|
2022-04-30 10:32:00 +03:00
|
|
|
testImplementation("io.ktor:ktor-server-tests:$ktorVersion")
|
2022-04-23 10:48:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
kotlin {
|
|
|
|
explicitApi = org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Disabled
|
2022-05-21 13:38:15 +03:00
|
|
|
}
|
|
|
|
|
2022-06-30 20:51:57 +03:00
|
|
|
apiValidation{
|
|
|
|
validationDisabled = true
|
|
|
|
}
|
|
|
|
|
2022-06-19 14:18:44 +03:00
|
|
|
/* Upload with JSch */
|
|
|
|
|
2022-06-19 19:36:48 +03:00
|
|
|
val host = System.getenv("SPC_HOST")
|
|
|
|
val user = System.getenv("SPC_USER")
|
2023-07-11 18:31:34 +03:00
|
|
|
val password = System.getenv("SPC_PASSWORD")
|
|
|
|
val privateKey = System.getenv("SPC_ID")
|
|
|
|
//val publicKey = System.getenv("SPC_PUBKEY")
|
2022-06-20 11:55:18 +03:00
|
|
|
val serviceName = "sciprog-site"
|
2022-06-19 14:18:44 +03:00
|
|
|
|
2023-07-11 18:31:34 +03:00
|
|
|
if (host != null && user != null || privateKey != null) {
|
2022-06-19 14:18:44 +03:00
|
|
|
val uploadDistribution by tasks.creating {
|
|
|
|
group = "distribution"
|
|
|
|
dependsOn("installDist")
|
|
|
|
doLast {
|
2022-06-20 11:55:18 +03:00
|
|
|
JSch {
|
2023-07-11 18:31:34 +03:00
|
|
|
addIdentity("webmaster", privateKey.encodeToByteArray(), null, null)
|
2022-06-20 11:55:18 +03:00
|
|
|
}.useSession(host, user) {
|
|
|
|
//stopping service during the upload
|
|
|
|
execute("sudo systemctl stop $serviceName")
|
|
|
|
uploadDirectory(buildDir.resolve("install/spc-site"), "/opt")
|
2023-07-11 18:31:34 +03:00
|
|
|
//adding an executable flag to the entry point
|
2022-06-20 11:55:18 +03:00
|
|
|
execute("sudo chmod +x /opt/spc-site/bin/spc-site")
|
|
|
|
execute("sudo systemctl start $serviceName")
|
2022-06-19 14:18:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val reloadDistribution by tasks.creating {
|
|
|
|
group = "distribution"
|
|
|
|
doLast {
|
2022-06-20 11:55:18 +03:00
|
|
|
JSch {
|
2023-07-11 18:31:34 +03:00
|
|
|
addIdentity("webmaster", privateKey.encodeToByteArray(), null, null)
|
2022-06-20 11:55:18 +03:00
|
|
|
}.useSession(host, user) {
|
|
|
|
execute("sudo systemctl restart $serviceName")
|
2022-06-19 14:18:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-19 19:36:48 +03:00
|
|
|
|
2022-06-20 11:55:18 +03:00
|
|
|
} else {
|
2022-06-20 11:05:13 +03:00
|
|
|
logger.error("Host, user or ID are not defined. Skipping deployment tasks.")
|
2023-03-27 16:24:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
val staticSite by tasks.creating(JavaExec::class){
|
2023-04-03 21:13:27 +03:00
|
|
|
doFirst {
|
|
|
|
buildDir.resolve("public").deleteRecursively()
|
|
|
|
}
|
2023-03-27 16:24:26 +03:00
|
|
|
group = "application"
|
|
|
|
mainClass.set("center.sciprog.StaticRenderKt")
|
|
|
|
classpath = sourceSets["main"].runtimeClasspath
|
2022-06-19 14:18:44 +03:00
|
|
|
}
|