optimize defaultTestContainer startup

This commit is contained in:
az 2022-07-06 21:26:47 +02:00
parent ee5a5301f1
commit e85be4cc20

View file

@ -12,14 +12,21 @@ val testDockerWithSudo = ("true" != System.getProperty("testdockerwithoutsudo")?
const val defaultTestContainerName = "provs_test" const val defaultTestContainerName = "provs_test"
private lateinit var prov: Prov
fun defaultTestContainer(startMode: ContainerStartMode = ContainerStartMode.USE_RUNNING_ELSE_CREATE): Prov { fun defaultTestContainer(startMode: ContainerStartMode = ContainerStartMode.USE_RUNNING_ELSE_CREATE): Prov {
val image = UbuntuPlusUser() if (!::prov.isInitialized) { prov = initDefaultTestContainer(startMode) }
val prov = testLocal() return prov
if (!prov.dockerImageExists(image.imageName(), testDockerWithSudo)) {
prov.dockerProvideImage(image, sudo = testDockerWithSudo)
} }
return Prov.newInstance( private fun initDefaultTestContainer(startMode: ContainerStartMode): Prov {
val image = UbuntuPlusUser()
val localProv = testLocal()
if (!localProv.dockerImageExists(image.imageName(), testDockerWithSudo)) {
localProv.dockerProvideImage(image, sudo = testDockerWithSudo)
}
val containerProv = Prov.newInstance(
ContainerUbuntuHostProcessor( ContainerUbuntuHostProcessor(
defaultTestContainerName, defaultTestContainerName,
startMode = startMode, startMode = startMode,
@ -28,6 +35,13 @@ fun defaultTestContainer(startMode: ContainerStartMode = ContainerStartMode.USE_
), ),
progressType = ProgressType.NONE progressType = ProgressType.NONE
) )
containerProv.sh("""
sudo apt-get update
sudo apt-get upgrade -qqq
""".trimIndent())
return containerProv
} }
fun testLocal(): Prov { fun testLocal(): Prov {