Skip to content

Commit c6f1525

Browse files
committed
Fix #36025: deploy new instance when external files are modified
1 parent 624062c commit c6f1525

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

src/main/kotlin/eu/openanalytics/shinyproxyoperator/impl/docker/DockerOrchestrator.kt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class DockerOrchestrator(channel: Channel<ShinyProxyEvent>,
342342
}
343343

344344
private fun copyTemplates(shinyProxy: ShinyProxy, dir: Path) {
345-
val source = getTemplateSource(shinyProxy) ?: return
345+
val source = shinyProxy.getTemplateSource(inputDir) ?: return
346346
val destination = dir.resolve("templates")
347347
fileManager.createDirectories(destination)
348348
source.toFile().copyRecursively(destination.toFile(), true)
@@ -380,18 +380,6 @@ class DockerOrchestrator(channel: Channel<ShinyProxyEvent>,
380380
return fileNames
381381
}
382382

383-
private fun getTemplateSource(shinyProxy: ShinyProxy): Path? {
384-
val source = inputDir.resolve("templates").resolve(shinyProxy.name)
385-
if (Files.exists(source) && Files.isDirectory(source)) {
386-
return source
387-
}
388-
val source2 = inputDir.resolve("templates").resolve(shinyProxy.realmId)
389-
if (Files.exists(source2) && Files.isDirectory(source2)) {
390-
return source2
391-
}
392-
return null
393-
}
394-
395383
private fun copyCaBundle(shinyProxy: ShinyProxy, inputDir: Path, dir: Path): Boolean {
396384
var source = shinyProxy.getCaBundleFile(inputDir)
397385
if (!source.isAbsolute) {

src/main/kotlin/eu/openanalytics/shinyproxyoperator/impl/docker/ShinyProxy.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ package eu.openanalytics.shinyproxyoperator.impl.docker
2323
import com.fasterxml.jackson.module.kotlin.convertValue
2424
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
2525
import eu.openanalytics.shinyproxyoperator.model.ShinyProxy
26+
import java.nio.file.Files
2627
import java.nio.file.Path
28+
import kotlin.io.path.PathWalkOption
2729
import kotlin.io.path.absolute
2830
import kotlin.io.path.exists
2931
import kotlin.io.path.getLastModifiedTime
3032
import kotlin.io.path.isRegularFile
33+
import kotlin.io.path.walk
3134

3235
fun ShinyProxy.getCaddyTlsCertFile(): Path? {
3336
if (getSpec().get("caddyTlsCertFile")?.isTextual == true) {
@@ -70,6 +73,18 @@ fun ShinyProxy.getCaBundleFile(inputDir: Path): Path {
7073
return inputDir.resolve("ca-bundle.crt").absolute()
7174
}
7275

76+
private fun ShinyProxy.isTemplateModified(inputDir: Path, lastModified: Long): Pair<Boolean, Path?> {
77+
val source = getTemplateSource(inputDir) ?: return Pair(false, null)
78+
79+
source.walk(PathWalkOption.INCLUDE_DIRECTORIES).forEach { path ->
80+
if (path.getLastModifiedTime().toMillis() > lastModified) {
81+
return Pair(true, path)
82+
}
83+
}
84+
85+
return Pair(false, null)
86+
}
87+
7388
fun ShinyProxy.isReferencedFileMoreRecent(inputDir: Path, lastModified: Long): Pair<Boolean, Path?> {
7489
val files = listOf(getCaddyTlsCertFile(), getCaddyTlsKeyFile(), getCaBundleFile(inputDir)) + getAdditionalConfigFiles()
7590
for (file in files) {
@@ -80,7 +95,19 @@ fun ShinyProxy.isReferencedFileMoreRecent(inputDir: Path, lastModified: Long): P
8095
return Pair(true, file)
8196
}
8297
}
83-
return Pair(false, null)
98+
return isTemplateModified(inputDir, lastModified)
99+
}
100+
101+
fun ShinyProxy.getTemplateSource(inputDir: Path): Path? {
102+
val source = inputDir.resolve("templates").resolve(name)
103+
if (Files.exists(source) && Files.isDirectory(source)) {
104+
return source
105+
}
106+
val source2 = inputDir.resolve("templates").resolve(realmId)
107+
if (Files.exists(source2) && Files.isDirectory(source2)) {
108+
return source2
109+
}
110+
return null
84111
}
85112

86113
data class CaddyRedirect(val from: String, val to: String, val statusCode: Int = 302)

0 commit comments

Comments
 (0)