Skip to content

Commit 9f75b6e

Browse files
alpar-tdroberts195
authored andcommitted
Fix build on sles with new docker version (#36707)
The build hash for some Docker versions is longer than 7 characters. Closes #36414
1 parent 9c2980a commit 9f75b6e

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

+16-12
Original file line numberDiff line numberDiff line change
@@ -293,18 +293,7 @@ class BuildPlugin implements Plugin<Project> {
293293
it.standardOutput = dockerVersionOutput
294294
})
295295
final String dockerVersion = dockerVersionOutput.toString().trim()
296-
final Matcher matcher = dockerVersion =~ /Docker version (\d+\.\d+)\.\d+(?:-ce)?, build [0-9a-f]{7}/
297-
assert matcher.matches() : dockerVersion
298-
final dockerMajorMinorVersion = matcher.group(1)
299-
final String[] majorMinor = dockerMajorMinorVersion.split("\\.")
300-
if (Integer.parseInt(majorMinor[0]) < 17
301-
|| (Integer.parseInt(majorMinor[0]) == 17 && Integer.parseInt(majorMinor[1]) < 5)) {
302-
final String message = String.format(
303-
Locale.ROOT,
304-
"building Docker images requires Docker version 17.05+ due to use of multi-stage builds yet was [%s]",
305-
dockerVersion)
306-
throwDockerRequiredException(message)
307-
}
296+
checkDockerVersionRecent(dockerVersion)
308297

309298
final ByteArrayOutputStream dockerImagesErrorOutput = new ByteArrayOutputStream()
310299
// the Docker binary executes, check that we can execute a privileged command
@@ -339,6 +328,21 @@ class BuildPlugin implements Plugin<Project> {
339328
}
340329
}
341330

331+
protected static void checkDockerVersionRecent(String dockerVersion) {
332+
final Matcher matcher = dockerVersion =~ /Docker version (\d+\.\d+)\.\d+(?:-ce)?, build [0-9a-f]{7,40}/
333+
assert matcher.matches(): dockerVersion
334+
final dockerMajorMinorVersion = matcher.group(1)
335+
final String[] majorMinor = dockerMajorMinorVersion.split("\\.")
336+
if (Integer.parseInt(majorMinor[0]) < 17
337+
|| (Integer.parseInt(majorMinor[0]) == 17 && Integer.parseInt(majorMinor[1]) < 5)) {
338+
final String message = String.format(
339+
Locale.ROOT,
340+
"building Docker images requires Docker version 17.05+ due to use of multi-stage builds yet was [%s]",
341+
dockerVersion)
342+
throwDockerRequiredException(message)
343+
}
344+
}
345+
342346
private static void throwDockerRequiredException(final String message) {
343347
throw new GradleException(
344348
message + "\nyou can address this by attending to the reported issue, "
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.gradle;
20+
21+
import org.elasticsearch.gradle.test.GradleUnitTestCase;
22+
import org.gradle.api.GradleException;
23+
import org.junit.Test;
24+
25+
26+
public class BuildPluginTests extends GradleUnitTestCase {
27+
28+
public void testPassingDockerVersions() {
29+
BuildPlugin.checkDockerVersionRecent("Docker version 18.06.1-ce, build e68fc7a215d7");
30+
BuildPlugin.checkDockerVersionRecent("Docker version 17.05.0, build e68fc7a");
31+
BuildPlugin.checkDockerVersionRecent("Docker version 17.05.1, build e68fc7a");
32+
}
33+
34+
@Test(expected = GradleException.class)
35+
public void testFailingDockerVersions() {
36+
BuildPlugin.checkDockerVersionRecent("Docker version 17.04.0, build e68fc7a");
37+
}
38+
39+
}

0 commit comments

Comments
 (0)