Skip to content

Commit

Permalink
Allow for calling installDockerClient() without args.
Browse files Browse the repository at this point in the history
  • Loading branch information
schnatterer committed Jun 25, 2020
1 parent 1edb0a4 commit 00c7547
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,11 @@ Example from Jenkinsfile:

This is also used by [MavenInDocker](src/com/cloudogu/ces/cesbuildlib/MavenInDocker.groovy)

* `installDockerClient(String version)`: Installs the docker client with the specified version inside the container.
* `installDockerClient(String version)`: Installs the docker client with the specified version inside the container.
If no version parameter is passed, the lib tries to query the server version by calling `docker version`.
This can be called in addition to mountDockerSocket(), when the "docker" CLI is required on the PATH.

For available versions see [here](https://download.docker.com/linux/static/stable/x86_64/).
For an exampl see [here](https://github.com/cloudogu/continuous-delivery-docs-example)

Examples:

Expand Down
5 changes: 4 additions & 1 deletion src/com/cloudogu/ces/cesbuildlib/Docker.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ class Docker implements Serializable {
*
* For available versions see here: https://download.docker.com/linux/static/stable/x86_64/
*/
Image installDockerClient(String version) {
Image installDockerClient(String version = '') {
if (!version) {
version = sh.returnStdOut "docker version --format '{{.Server.Version}}'"
}
this.dockerClientVersionToInstall = version
return this
}
Expand Down
11 changes: 11 additions & 0 deletions test/com/cloudogu/ces/cesbuildlib/DockerTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class DockerTest {
def expectedImage = 'google/cloud-sdk:164.0.0'
def expectedHome = '/home/jenkins'
def actualUser = 'jenkins'
def actualDockerServerVersion = '19.03.8'
def actualPasswd = "$actualUser:x:1000:1000:Jenkins,,,:/home/jenkins:/bin/bash"
def actualDockerGroupId = "999"
def actualDockerGroup = "docker:x:$actualDockerGroupId:jenkins"
Expand Down Expand Up @@ -383,6 +384,15 @@ class DockerTest {
assert actualShArgs[0].contains("${it}.tgz")
})
}

@Test
void "install docker clients for current server version"() {
Docker docker = createWithImage(mockedImageMethodInside())
docker.image(expectedImage)
.installDockerClient()
.inside { return 'expectedClosure' }
assert actualShArgs[0].contains("${actualDockerServerVersion}.tgz")
}

private Docker create(Map<String, Closure> mockedMethod) {
Map<String, Map<String, Closure>> mockedScript = [
Expand Down Expand Up @@ -418,6 +428,7 @@ class DockerTest {
if (script == 'cat /etc/group | grep docker') return actualDockerGroup
if (script.contains(actualDockerGroup)) return actualDockerGroupId
if (script.contains('cat /etc/passwd | grep')) return actualPasswd
if (script.contains('docker version --format \'{{.Server.Version}}\'')) return " ${actualDockerServerVersion} "
else fail("Unexpected sh call. Script: " + script)
},
pwd: { return expectedHome },
Expand Down

0 comments on commit 00c7547

Please sign in to comment.