Skip to content

Commit 73a9003

Browse files
committed
Generate test engines list dynamically
Signed-off-by: Joffrey F <[email protected]>
1 parent e9f31e1 commit 73a9003

File tree

2 files changed

+92
-8
lines changed

2 files changed

+92
-8
lines changed

Jenkinsfile

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ def imageNamePy2
55
def imageNamePy3
66
def images = [:]
77

8-
def dockerVersions = [
9-
"17.06.2-ce", // Latest EE
10-
"17.12.1-ce", // Latest CE stable
11-
"18.02.0-ce", // Latest CE edge
12-
"18.03.0-ce-rc4" // Latest CE RC
13-
]
14-
158
def buildImage = { name, buildargs, pyTag ->
169
img = docker.image(name)
1710
try {
@@ -37,9 +30,27 @@ def buildImages = { ->
3730
}
3831
}
3932

33+
def getDockerVersions = { ->
34+
def dockerVersions = ["17.06.2-ce"]
35+
wrappedNode(label: "ubuntu && !zfs") {
36+
def result = sh(script: """docker run --rm \\
37+
--entrypoint=python \\
38+
${imageNamePy3} \\
39+
/src/scripts/versions.py
40+
""", returnStdout: true
41+
)
42+
dockerVersions = dockerVersions + result.trim().tokenize(' ')
43+
}
44+
return dockerVersions
45+
}
46+
4047
def getAPIVersion = { engineVersion ->
4148
def versionMap = ['17.06': '1.30', '17.12': '1.35', '18.02': '1.36', '18.03': '1.37']
42-
return versionMap[engineVersion.substring(0, 5)]
49+
def result = versionMap[engineVersion.substring(0, 5)]
50+
if (!result) {
51+
return '1.37'
52+
}
53+
return result
4354
}
4455

4556
def runTests = { Map settings ->
@@ -94,6 +105,8 @@ def runTests = { Map settings ->
94105

95106
buildImages()
96107

108+
def dockerVersions = getDockerVersions()
109+
97110
def testMatrix = [failFast: false]
98111

99112
for (imgKey in new ArrayList(images.keySet())) {

scripts/versions.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import operator
2+
import re
3+
from collections import namedtuple
4+
5+
import requests
6+
7+
base_url = 'https://download.docker.com/linux/static/{0}/x86_64/'
8+
categories = [
9+
'edge',
10+
'stable',
11+
'test'
12+
]
13+
14+
15+
class Version(namedtuple('_Version', 'major minor patch rc edition')):
16+
17+
@classmethod
18+
def parse(cls, version):
19+
edition = None
20+
version = version.lstrip('v')
21+
version, _, rc = version.partition('-')
22+
if rc:
23+
if 'rc' not in rc:
24+
edition = rc
25+
rc = None
26+
elif '-' in rc:
27+
edition, rc = rc.split('-')
28+
29+
major, minor, patch = version.split('.', 3)
30+
return cls(major, minor, patch, rc, edition)
31+
32+
@property
33+
def major_minor(self):
34+
return self.major, self.minor
35+
36+
@property
37+
def order(self):
38+
"""Return a representation that allows this object to be sorted
39+
correctly with the default comparator.
40+
"""
41+
# rc releases should appear before official releases
42+
rc = (0, self.rc) if self.rc else (1, )
43+
return (int(self.major), int(self.minor), int(self.patch)) + rc
44+
45+
def __str__(self):
46+
rc = '-{}'.format(self.rc) if self.rc else ''
47+
edition = '-{}'.format(self.edition) if self.edition else ''
48+
return '.'.join(map(str, self[:3])) + edition + rc
49+
50+
51+
def main():
52+
results = set()
53+
for url in [base_url.format(cat) for cat in categories]:
54+
res = requests.get(url)
55+
content = res.text
56+
versions = [
57+
Version.parse(
58+
v.strip('"').lstrip('docker-').rstrip('.tgz').rstrip('-x86_64')
59+
) for v in re.findall(
60+
r'"docker-[0-9]+\.[0-9]+\.[0-9]+-.*tgz"', content
61+
)
62+
]
63+
sorted_versions = sorted(
64+
versions, reverse=True, key=operator.attrgetter('order')
65+
)
66+
latest = sorted_versions[0]
67+
results.add(str(latest))
68+
print(' '.join(results))
69+
70+
if __name__ == '__main__':
71+
main()

0 commit comments

Comments
 (0)