[skip ci] add image to docker method in Utils
This commit is contained in:
parent
85dd64c0d3
commit
dd96949ed3
1 changed files with 24 additions and 23 deletions
|
@ -52,6 +52,10 @@ fun String.escapeProcentForPrintf(): String = replace("%", "%%")
|
||||||
fun String.endingWithFileSeparator(): String = if (length > 0 && (last() != fileSeparatorChar())) this + fileSeparator() else this
|
fun String.endingWithFileSeparator(): String = if (length > 0 && (last() != fileSeparatorChar())) this + fileSeparator() else this
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put String between double quotes and escapes chars that need to be escaped (by backslash) for use in Unix Shell String
|
||||||
|
* I.e. the following chars are escaped: backslash, backtick, double quote, dollar
|
||||||
|
*/
|
||||||
fun String.escapeAndEncloseByDoubleQuoteForShell(): String {
|
fun String.escapeAndEncloseByDoubleQuoteForShell(): String {
|
||||||
return "\"" + this.escapeForShell() + "\""
|
return "\"" + this.escapeForShell() + "\""
|
||||||
}
|
}
|
||||||
|
@ -101,32 +105,29 @@ fun remote(host: String, remoteUser: String, password: Secret? = null, platform:
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Prov instance running in a local docker container with name containerName.
|
* Returns Prov instance which eexcutes its tasks in a local docker container with name containerName.
|
||||||
* A potentially existing container with the same name is reused by default resp. if
|
* If a container with the given name is running already, it'll be reused if parameter useExistingContainer is set to true.
|
||||||
* parameter useExistingContainer is set to true.
|
* If a container is reused, it is not checked if it has the correct, specified image.
|
||||||
* If a new container needs to be created, on Linux systems the image _ubuntu_ is used.
|
|
||||||
*/
|
*/
|
||||||
@Api // used by other libraries resp. KotlinScript
|
@Api // used by other libraries resp. KotlinScript
|
||||||
fun docker(containerName: String = "provs_default", useExistingContainer: Boolean = true): Prov {
|
fun docker(
|
||||||
|
containerName: String = "provs_default",
|
||||||
|
useExistingContainer: Boolean = true,
|
||||||
|
imageName: String = "ubuntu",
|
||||||
|
sudo: Boolean = true
|
||||||
|
): Prov {
|
||||||
|
|
||||||
val os = System.getProperty("os.name")
|
local().provideContainer(containerName, imageName)
|
||||||
|
|
||||||
if ("Linux".equals(os)) {
|
return Prov.newInstance(
|
||||||
val defaultDockerImage = "ubuntu"
|
ContainerUbuntuHostProcessor(
|
||||||
|
containerName,
|
||||||
local().provideContainer(containerName, defaultDockerImage)
|
imageName,
|
||||||
|
if (useExistingContainer)
|
||||||
return Prov.newInstance(
|
ContainerStartMode.USE_RUNNING_ELSE_CREATE
|
||||||
ContainerUbuntuHostProcessor(
|
else
|
||||||
containerName,
|
ContainerStartMode.CREATE_NEW_KILL_EXISTING,
|
||||||
defaultDockerImage,
|
sudo = sudo
|
||||||
if (useExistingContainer)
|
|
||||||
ContainerStartMode.USE_RUNNING_ELSE_CREATE
|
|
||||||
else
|
|
||||||
ContainerStartMode.CREATE_NEW_KILL_EXISTING
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
} else {
|
)
|
||||||
throw RuntimeException("ERROR: method docker() is currently not supported for " + os)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue