fix test for pipeline

This commit is contained in:
az 2021-11-30 12:40:37 +01:00
parent 8de2f25d00
commit 2a02a0afb2
3 changed files with 18 additions and 3 deletions

View file

@ -134,15 +134,18 @@ fun remote(host: String, remoteUser: String, password: Secret? = null, platform:
* Returns Prov instance which eexcutes its tasks in a local docker container with name containerName.
* If a container with the given name is running already, it'll be reused if parameter useExistingContainer is set to true.
* If a container is reused, it is not checked if it has the correct, specified image.
* Determines automatically if sudo is required if sudo is null, otherwise the specified sudo is used
*/
@Api // used by other libraries resp. KotlinScript
fun docker(
containerName: String = "provs_default",
useExistingContainer: Boolean = true,
imageName: String = "ubuntu",
sudo: Boolean = true
sudo: Boolean? = null
): Prov {
val sudoRequired = sudo ?: checkSudoRequiredForDocker()
local().provideContainer(containerName, imageName)
return Prov.newInstance(
@ -153,7 +156,18 @@ fun docker(
ContainerStartMode.USE_RUNNING_ELSE_CREATE
else
ContainerStartMode.CREATE_NEW_KILL_EXISTING,
sudo = sudo
sudo = sudoRequired
)
)
}
fun checkSudoRequiredForDocker(): Boolean {
return if (local().chk("docker -v")) {
false
} else if (local().chk("sudo docker -v")) {
true
} else {
throw IllegalStateException("Docker could not be run.")
}
}

View file

@ -24,7 +24,7 @@ internal class K3dKtTest {
provideContainer(
containerName,
"yobasystems/alpine-docker:dind-amd64",
ContainerStartMode.CREATE_NEW_KILL_EXISTING, // for re-create a potentially existing container
// ContainerStartMode.CREATE_NEW_KILL_EXISTING, // for re-create a potentially existing container
sudo = false,
options = "--privileged"
)

View file

@ -4,6 +4,7 @@ import org.domaindrivenarchitecture.provs.core.Prov
import org.domaindrivenarchitecture.provs.core.docker
import org.domaindrivenarchitecture.provs.core.echoCommandForText
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
import org.domaindrivenarchitecture.provs.test.tags.NonCi
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test