Install a nightly Docker cleanup timer with init --systemd (v0.9.7)
Port of the legacy host's docker-prune.timer: 02:00 host time, Persistent=true, docker system prune -af — but without --volumes, so the per-repository Gradle cache volumes survive. The units are host-global; several GitTally instances share one timer. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
74bc4c2d73
commit
e1f3f5f384
@@ -104,6 +104,26 @@ class InitCommandTest : FunSpec() {
|
||||
tempDir.resolve(".git/gittally/gittally.env").toFile().shouldExist()
|
||||
}
|
||||
|
||||
test("--systemd also generates the nightly Docker cleanup timer") {
|
||||
val tempDir = Files.createTempDirectory("gittally-init-test")
|
||||
initCommand.workingDir = tempDir
|
||||
initCommand.systemd = true
|
||||
initCommand.jarPathResolver = { Paths.get("/home/ci/bin/gittally.jar") }
|
||||
initCommand.javaExecutableResolver = { Paths.get("/usr/bin/java") }
|
||||
|
||||
every { gitService.getTopLevel(tempDir) } returns tempDir
|
||||
every { gitService.getOriginUrl(tempDir) } returns "https://git.example.org/my-org/my-repo.git"
|
||||
|
||||
initCommand.run()
|
||||
|
||||
val pruneService = tempDir.resolve(".git/gittally/gittally-docker-prune.service")
|
||||
pruneService.toFile().shouldExist()
|
||||
pruneService.toFile().readText() shouldContain "docker system prune -af"
|
||||
val pruneTimer = tempDir.resolve(".git/gittally/gittally-docker-prune.timer")
|
||||
pruneTimer.toFile().shouldExist()
|
||||
pruneTimer.toFile().readText() shouldContain "OnCalendar=*-*-* 02:00:00"
|
||||
}
|
||||
|
||||
test("--systemd keeps an existing environment file") {
|
||||
val tempDir = Files.createTempDirectory("gittally-init-test")
|
||||
initCommand.workingDir = tempDir
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.hoennig.gittally.commands
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import io.kotest.matchers.string.shouldNotContain
|
||||
import java.nio.file.Paths
|
||||
|
||||
class SystemdServiceFilesTest : FunSpec() {
|
||||
@@ -46,6 +47,24 @@ class SystemdServiceFilesTest : FunSpec() {
|
||||
content shouldContain """-jar "/srv/100%%-repo/gittally.jar" server"""
|
||||
}
|
||||
|
||||
test("prune service cleans containers and images but never volumes") {
|
||||
val content = SystemdServiceFiles.pruneServiceContent()
|
||||
|
||||
content shouldContain "Type=oneshot"
|
||||
content shouldContain "ExecStart=docker system prune -af"
|
||||
// the per-repository Gradle cache volumes must survive the cleanup
|
||||
content shouldNotContain "--volumes"
|
||||
content shouldContain "ExecCondition=sh -c 'command -v docker'"
|
||||
}
|
||||
|
||||
test("prune timer fires nightly at 02:00 and catches up after downtime") {
|
||||
val content = SystemdServiceFiles.pruneTimerContent()
|
||||
|
||||
content shouldContain "OnCalendar=*-*-* 02:00:00"
|
||||
content shouldContain "Persistent=true"
|
||||
content shouldContain "WantedBy=timers.target"
|
||||
}
|
||||
|
||||
test("environment file template only tunes the JVM") {
|
||||
val content = SystemdServiceFiles.envFileContent()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user