forked from SPC/spc-site
Update build tools and DF
This commit is contained in:
parent
2b5af660af
commit
9e87eddcb6
@ -1,12 +1,12 @@
|
|||||||
import ru.mipt.npm.gradle.KScienceVersions
|
import space.kscience.gradle.KScienceVersions
|
||||||
import space.kscience.snark.plugin.JSch
|
import space.kscience.snark.plugin.JSch
|
||||||
import space.kscience.snark.plugin.execute
|
import space.kscience.snark.plugin.execute
|
||||||
import space.kscience.snark.plugin.uploadDirectory
|
import space.kscience.snark.plugin.uploadDirectory
|
||||||
import space.kscience.snark.plugin.useSession
|
import space.kscience.snark.plugin.useSession
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("ru.mipt.npm.gradle.project")
|
id("space.kscience.gradle.project")
|
||||||
id("ru.mipt.npm.gradle.jvm")
|
id("space.kscience.gradle.jvm")
|
||||||
id("space.kscience.snark")
|
id("space.kscience.snark")
|
||||||
application
|
application
|
||||||
}
|
}
|
||||||
@ -42,18 +42,6 @@ apiValidation{
|
|||||||
validationDisabled = true
|
validationDisabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
|
||||||
kotlinOptions {
|
|
||||||
freeCompilerArgs = freeCompilerArgs + "-Xcontext-receivers"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
resources.srcDir(project.rootDir.resolve("data"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Upload with JSch */
|
/* Upload with JSch */
|
||||||
|
|
||||||
val host = System.getenv("SPC_HOST")
|
val host = System.getenv("SPC_HOST")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
|
|
||||||
toolsVersion=0.11.7-kotlin-1.7.0
|
toolsVersion=0.12.1-kotlin-1.7.20-Beta
|
||||||
snarkVersion=0.1.0-dev-1
|
snarkVersion=0.1.0-dev-1
|
@ -15,10 +15,10 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("ru.mipt.npm.gradle.project") version toolsVersion
|
id("space.kscience.gradle.project") version toolsVersion
|
||||||
id("ru.mipt.npm.gradle.mpp") version toolsVersion
|
id("space.kscience.gradle.mpp") version toolsVersion
|
||||||
id("ru.mipt.npm.gradle.jvm") version toolsVersion
|
id("space.kscience.gradle.jvm") version toolsVersion
|
||||||
id("ru.mipt.npm.gradle.js") version toolsVersion
|
id("space.kscience.gradle.js") version toolsVersion
|
||||||
id("space.kscience.snark") version snarkVersion
|
id("space.kscience.snark") version snarkVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ dependencyResolutionManagement {
|
|||||||
|
|
||||||
versionCatalogs {
|
versionCatalogs {
|
||||||
create("npmlibs") {
|
create("npmlibs") {
|
||||||
from("ru.mipt.npm:version-catalog:$toolsVersion")
|
from("space.kscience:version-catalog:$toolsVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,47 +1,12 @@
|
|||||||
package ru.mipt.spc
|
package ru.mipt.spc
|
||||||
|
|
||||||
import io.ktor.server.application.Application
|
import io.ktor.server.application.Application
|
||||||
import io.ktor.server.application.log
|
|
||||||
import kotlinx.css.CssBuilder
|
|
||||||
import kotlinx.html.CommonAttributeGroupFacade
|
|
||||||
import kotlinx.html.style
|
|
||||||
import space.kscience.snark.SnarkEnvironment
|
import space.kscience.snark.SnarkEnvironment
|
||||||
|
import space.kscience.snark.ktor.extractResources
|
||||||
|
import space.kscience.snark.ktor.prepareSnarkDataCacheDirectory
|
||||||
import space.kscience.snark.ktor.site
|
import space.kscience.snark.ktor.site
|
||||||
import java.net.URI
|
|
||||||
import java.nio.file.FileSystems
|
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.time.LocalDateTime
|
import kotlin.io.path.div
|
||||||
import kotlin.io.path.*
|
|
||||||
|
|
||||||
fun CommonAttributeGroupFacade.css(block: CssBuilder.() -> Unit) {
|
|
||||||
style = CssBuilder().block().toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Application.resolveData(uri: URI, targetPath: Path): Path {
|
|
||||||
if (Files.isDirectory(targetPath)) {
|
|
||||||
log.info("Using existing data directory at $targetPath.")
|
|
||||||
} else {
|
|
||||||
log.info("Copying data from $uri into $targetPath.")
|
|
||||||
targetPath.createDirectories()
|
|
||||||
//Copy everything into a temporary directory
|
|
||||||
FileSystems.newFileSystem(uri, emptyMap<String, Any>()).use { fs ->
|
|
||||||
val rootPath: Path = fs.provider().getPath(uri)
|
|
||||||
Files.walk(rootPath).forEach { source: Path ->
|
|
||||||
if (source.isRegularFile()) {
|
|
||||||
val relative = source.relativeTo(rootPath).toString()
|
|
||||||
val destination: Path = targetPath.resolve(relative)
|
|
||||||
destination.parent.createDirectories()
|
|
||||||
Files.copy(source, destination)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return targetPath
|
|
||||||
}
|
|
||||||
|
|
||||||
const val DEPLOY_DATE_FILE = "deployDate"
|
|
||||||
const val BUILD_DATE_FILE = "/buildDate"
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
fun Application.spcModule() {
|
fun Application.spcModule() {
|
||||||
@ -49,54 +14,24 @@ fun Application.spcModule() {
|
|||||||
|
|
||||||
val dataPath = Path.of("data")
|
val dataPath = Path.of("data")
|
||||||
|
|
||||||
// Clear data directory if it is outdated
|
prepareSnarkDataCacheDirectory(dataPath)
|
||||||
val deployDate = dataPath.resolve(DEPLOY_DATE_FILE).takeIf { it.exists() }
|
|
||||||
?.readText()?.let { LocalDateTime.parse(it) }
|
|
||||||
val buildDate = javaClass.getResource(BUILD_DATE_FILE)?.readText()?.let { LocalDateTime.parse(it) }
|
|
||||||
|
|
||||||
val inProduction: Boolean = environment.config.propertyOrNull("ktor.environment.production") != null
|
|
||||||
|
|
||||||
if (inProduction) {
|
|
||||||
log.info("Production mode activated")
|
|
||||||
log.info("Build date: $buildDate")
|
|
||||||
log.info("Deploy date: $deployDate")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deployDate != null && buildDate != null && buildDate.isAfter(deployDate)) {
|
|
||||||
log.info("Outdated data. Resetting data directory.")
|
|
||||||
|
|
||||||
Files.walk(dataPath)
|
|
||||||
.sorted(Comparator.reverseOrder())
|
|
||||||
.forEach { it.deleteIfExists() }
|
|
||||||
|
|
||||||
//Writing deploy date file
|
|
||||||
dataPath.createDirectories()
|
|
||||||
dataPath.resolve(DEPLOY_DATE_FILE).writeText(LocalDateTime.now().toString())
|
|
||||||
|
|
||||||
} else if (inProduction && deployDate == null && buildDate != null) {
|
|
||||||
val date = LocalDateTime.now().toString()
|
|
||||||
log.info("Deploy date: $date")
|
|
||||||
//Writing deploy date in production mode if it does not exist
|
|
||||||
dataPath.createDirectories()
|
|
||||||
dataPath.resolve(DEPLOY_DATE_FILE).writeText(date)
|
|
||||||
}
|
|
||||||
|
|
||||||
SnarkEnvironment.default.site {
|
SnarkEnvironment.default.site {
|
||||||
|
|
||||||
resolveData(
|
extractResources(
|
||||||
this@spcModule.javaClass.getResource("/common")!!.toURI(),
|
"/common",
|
||||||
dataPath / "common"
|
dataPath / "common"
|
||||||
)
|
)
|
||||||
|
|
||||||
val homeDataPath = resolveData(
|
val homeDataPath = extractResources(
|
||||||
this@spcModule.javaClass.getResource("/home")!!.toURI(),
|
"/home",
|
||||||
dataPath / "home"
|
dataPath / "home"
|
||||||
)
|
)
|
||||||
|
|
||||||
spcHome(dataPath = homeDataPath)
|
spcHome(dataPath = homeDataPath)
|
||||||
|
|
||||||
val mastersDataPath = resolveData(
|
val mastersDataPath = extractResources(
|
||||||
this@spcModule.javaClass.getResource("/magprog")!!.toURI(),
|
"/magprog",
|
||||||
dataPath / "magprog"
|
dataPath / "magprog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import space.kscience.dataforge.meta.string
|
|||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
import space.kscience.dataforge.names.parseAsName
|
import space.kscience.dataforge.names.parseAsName
|
||||||
import space.kscience.dataforge.names.withIndex
|
import space.kscience.dataforge.names.withIndex
|
||||||
import space.kscience.dataforge.values.string
|
|
||||||
import space.kscience.snark.html.*
|
import space.kscience.snark.html.*
|
||||||
import kotlin.collections.component1
|
import kotlin.collections.component1
|
||||||
import kotlin.collections.component2
|
import kotlin.collections.component2
|
||||||
|
@ -9,7 +9,6 @@ import space.kscience.dataforge.meta.string
|
|||||||
import space.kscience.dataforge.names.Name
|
import space.kscience.dataforge.names.Name
|
||||||
import space.kscience.dataforge.names.asName
|
import space.kscience.dataforge.names.asName
|
||||||
import space.kscience.dataforge.names.startsWith
|
import space.kscience.dataforge.names.startsWith
|
||||||
import space.kscience.dataforge.values.string
|
|
||||||
import space.kscience.snark.html.*
|
import space.kscience.snark.html.*
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.reflect.typeOf
|
import kotlin.reflect.typeOf
|
||||||
|
Loading…
Reference in New Issue
Block a user