Skip to content

Commit

Permalink
Fix installDockerClient for versions > 18.06.3
Browse files Browse the repository at this point in the history
  • Loading branch information
schnatterer committed Jun 25, 2020
1 parent 1d0f9a3 commit 1edb0a4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/com/cloudogu/ces/cesbuildlib/Docker.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,17 @@ class Docker implements Serializable {

private void doInstallDockerClient() {
// Installs statically linked docker binary
script.sh "cd ${script.pwd()}/.jenkins && wget -qc https://download.docker.com/linux/static/stable/x86_64/docker-$dockerClientVersionToInstall-ce.tgz -O - | tar -xz"
String url = "https://download.docker.com/linux/static/stable/x86_64/docker-${dockerClientVersionToInstall}.tgz"

// Keep compatibility with old URLs
if ((dockerClientVersionToInstall.startsWith('17') ||
dockerClientVersionToInstall.startsWith('18.03') ||
dockerClientVersionToInstall.startsWith('18.06')) &&
!dockerClientVersionToInstall.endsWith('-ce')) {
url = url.replace('.tgz', '-ce.tgz')
}

script.sh "cd ${script.pwd()}/.jenkins && wget -qc ${url} -O - | tar -xz"
}
}
}
42 changes: 41 additions & 1 deletion test/com/cloudogu/ces/cesbuildlib/DockerTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,46 @@ class DockerTest {
'Unable to parse group docker from /etc/group. Docker host will not be accessible for container.')
}

@Test
void "install older docker clients"() {
Docker docker = createWithImage(mockedImageMethodInside())

def oldUrlVersions = [ '17.03.0', '17.03.1', '17.03.2', '17.06.0', '17.06.1', '17.06.2', '17.09.0', '17.09.1',
'17.12.0', '17.12.1', '18.03.0', '18.03.1', '18.06.0', '18.06.1', '18.06.2', '18.06.3']

oldUrlVersions.forEach({
actualShArgs = []
docker.image(expectedImage)
.installDockerClient(it)
.inside { return 'expectedClosure' }
assert actualShArgs[0].contains("${it}-ce.tgz")
})

// Also accept URLs ending in -ce
oldUrlVersions.forEach({
actualShArgs = []
docker.image(expectedImage)
.installDockerClient("${it}-ce")
.inside { return 'expectedClosure' }
assert actualShArgs[0].contains("${it}-ce.tgz")
})
}

@Test
void "install newer docker clients"() {
Docker docker = createWithImage(mockedImageMethodInside())

def oldUrlVersions = [ '18.09.0', '19.03.9']

oldUrlVersions.forEach({
actualShArgs = []
docker.image(expectedImage)
.installDockerClient(it)
.inside { return 'expectedClosure' }
assert actualShArgs[0].contains("${it}.tgz")
})
}

private Docker create(Map<String, Closure> mockedMethod) {
Map<String, Map<String, Closure>> mockedScript = [
docker: mockedMethod
Expand All @@ -363,7 +403,7 @@ class DockerTest {
return mockedMethod
}
],
sh: { Object args ->
sh: { args ->

if (!(args instanceof Map)) {
actualShArgs.add(args)
Expand Down

0 comments on commit 1edb0a4

Please sign in to comment.