spc-site/build.gradle.kts

127 lines
4.2 KiB
Plaintext
Raw Normal View History

2022-04-30 10:32:00 +03:00
import ru.mipt.npm.gradle.KScienceVersions
2022-05-24 21:39:01 +03:00
import java.time.LocalDateTime
2022-04-23 10:48:53 +03:00
plugins {
id("ru.mipt.npm.gradle.project")
id("ru.mipt.npm.gradle.jvm")
2022-04-30 10:32:00 +03:00
application
}
2022-05-22 16:52:36 +03:00
repositories {
2022-05-13 17:21:06 +03:00
mavenLocal()
}
2022-04-23 10:48:53 +03:00
group = "ru.mipt.npm"
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-04-30 10:32:00 +03:00
2022-05-21 13:38:15 +03:00
val dataforgeVersion by extra("0.6.0-dev-9")
2022-05-06 15:54:59 +03:00
val ktorVersion = KScienceVersions.ktorVersion
2022-04-30 10:32:00 +03:00
2022-04-23 10:48:53 +03:00
dependencies {
2022-04-30 10:32:00 +03:00
implementation("io.ktor:ktor-server-core:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-html:0.7.5")
implementation("io.ktor:ktor-server-html-builder:$ktorVersion")
implementation("org.jetbrains.kotlin-wrappers:kotlin-css")
implementation("io.ktor:ktor-server-host-common:$ktorVersion")
implementation("io.ktor:ktor-server-status-pages:$ktorVersion")
implementation("io.ktor:ktor-server-netty:$ktorVersion")
2022-06-23 11:02:26 +03:00
implementation("io.ktor:ktor-server-http-redirect:$ktorVersion")
2022-04-30 10:32:00 +03:00
implementation("ch.qos.logback:logback-classic:1.2.11")
implementation("space.kscience:dataforge-workspace:$dataforgeVersion")
implementation("space.kscience:dataforge-io-yaml:$dataforgeVersion")
2022-04-23 10:59:05 +03:00
implementation("org.jetbrains:markdown:0.3.1")
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-05-22 16:52:36 +03:00
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
2022-05-21 13:38:15 +03:00
freeCompilerArgs = freeCompilerArgs + "-Xcontext-receivers"
2022-05-08 22:21:01 +03:00
}
2022-05-06 15:54:59 +03:00
}
sourceSets {
main {
resources.srcDir(project.rootDir.resolve("data"))
}
2022-05-24 21:39:01 +03:00
}
2022-06-26 13:14:57 +03:00
readme {
maturity = ru.mipt.npm.gradle.Maturity.EXPERIMENTAL
feature("data") { "Data-based processing. Instead of traditional layout-based" }
feature("layouts") { "Use custom layouts to represent a data tree" }
feature("parsers") { "Add custom file formats and parsers using DataForge dependency injection" }
feature("preprocessor") { "Preprocessing text files using templates" }
feature("metadata") { "Trademark DataForge metadata layering and transformations" }
feature("dynamic") { "Generating dynamic site using KTor server" }
feature("static") { "Generating static site" }
}
/**
* This task updates the site build date in resource automatically
*/
2022-05-26 21:48:56 +03:00
val writeBuildDate: Task by tasks.creating {
2022-05-26 22:57:55 +03:00
doLast {
2022-05-24 21:39:01 +03:00
val deployDate = LocalDateTime.now()
2022-05-26 22:57:55 +03:00
val file = File(project.buildDir, "resources/main/buildDate")
file.parentFile.mkdirs()
file.writeText(deployDate.toString())
2022-05-24 21:39:01 +03:00
}
2022-05-26 21:48:56 +03:00
outputs.file("resources/main/buildDate")
2022-06-08 19:07:20 +03:00
outputs.upToDateWhen { false }
2022-05-26 21:48:56 +03:00
}
//write build time in build to check outdated external data directory
2022-06-19 14:18:44 +03:00
tasks.getByName("processResources").dependsOn(writeBuildDate)
/* Upload with JSch */
2022-06-19 19:36:48 +03:00
val host = System.getenv("SPC_HOST")
val user = System.getenv("SPC_USER")
2022-06-20 11:55:18 +03:00
val identityString = System.getenv("SPC_ID")
val serviceName = "sciprog-site"
2022-06-19 14:18:44 +03:00
2022-06-20 11:55:18 +03:00
if (host != null && user != null || identityString != 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 {
addIdentity("spc-webmaster", identityString.encodeToByteArray(), null, null)
}.useSession(host, user) {
//stopping service during the upload
execute("sudo systemctl stop $serviceName")
uploadDirectory(buildDir.resolve("install/spc-site"), "/opt")
//adding executable flag to the entry point
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 {
addIdentity("spc-webmaster", identityString.encodeToByteArray(), null, null)
}.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.")
2022-06-19 14:18:44 +03:00
}