1
0
forked from SPC/spc-site
varvara_kaplenko/build.gradle.kts

100 lines
2.9 KiB
Plaintext

import space.kscience.gradle.KScienceVersions
import space.kscience.snark.plugin.JSch
import space.kscience.snark.plugin.execute
import space.kscience.snark.plugin.uploadDirectory
import space.kscience.snark.plugin.useSession
plugins {
id("space.kscience.gradle.project")
id("space.kscience.gradle.jvm")
id("space.kscience.snark")
application
}
group = "center.sciprog"
version = "0.1.0"
application {
mainClass.set("io.ktor.server.netty.EngineMain")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment", "-Xmx200M")
}
val snarkVersion: String by extra
val ktorVersion = KScienceVersions.ktorVersion
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
implementation("space.kscience:snark-ktor:$snarkVersion")
implementation("io.ktor:ktor-server-netty:$ktorVersion")
implementation("io.ktor:ktor-server-http-redirect:$ktorVersion")
implementation("io.ktor:ktor-server-forwarded-header:$ktorVersion")
implementation("ch.qos.logback:logback-classic:1.4.12")
testImplementation("io.ktor:ktor-server-tests:$ktorVersion")
}
kotlin {
explicitApi = org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Disabled
}
apiValidation{
validationDisabled = true
}
/* Upload with JSch */
val host = System.getenv("SPC_HOST")
val user = System.getenv("SPC_USER")
val password = System.getenv("SPC_PASSWORD")
val privateKey = System.getenv("SPC_ID")
//val publicKey = System.getenv("SPC_PUBKEY")
val serviceName = "sciprog-site"
if (host != null && user != null || privateKey != null) {
val uploadDistribution by tasks.creating {
group = "distribution"
dependsOn("installDist")
doLast {
JSch {
addIdentity("webmaster", privateKey.encodeToByteArray(), null, null)
}.useSession(host, user) {
//stopping service during the upload
execute("sudo systemctl stop $serviceName")
uploadDirectory(buildDir.resolve("install/spc-site"), "/opt")
//adding an executable flag to the entry point
execute("sudo chmod +x /opt/spc-site/bin/spc-site")
execute("sudo systemctl start $serviceName")
}
}
}
val reloadDistribution by tasks.creating {
group = "distribution"
doLast {
JSch {
addIdentity("webmaster", privateKey.encodeToByteArray(), null, null)
}.useSession(host, user) {
execute("sudo systemctl restart $serviceName")
}
}
}
} else {
logger.error("Host, user or ID are not defined. Skipping deployment tasks.")
}
val staticSite by tasks.creating(JavaExec::class){
doFirst {
buildDir.resolve("public").deleteRecursively()
}
group = "application"
mainClass.set("center.sciprog.StaticRenderKt")
classpath = sourceSets["main"].runtimeClasspath
}