Skip to content

Commit 96cc511

Browse files
authored
Fix shell retry generator for shells other than bash (#77422)
Closes #77414. The generated shell logic in ShellRetry doesn't work in more basic shells, so instead of using the {1..10} construct, expand the sequence.
1 parent f1a4551 commit 96cc511

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/docker/ShellRetry.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
package org.elasticsearch.gradle.internal.docker;
1010

11+
import java.util.stream.Collectors;
12+
import java.util.stream.IntStream;
13+
1114
/**
1215
* The methods in this class take a shell command and wrap it in retry logic, so that our
1316
* Docker builds can be more robust in the face of transient errors e.g. network issues.
@@ -20,7 +23,11 @@ static String loop(String name, String command) {
2023
static String loop(String name, String command, int indentSize, String exitKeyword) {
2124
String indent = " ".repeat(indentSize);
2225

23-
StringBuilder commandWithRetry = new StringBuilder("for iter in {1..10}; do \n");
26+
// bash understands the `{1..10}` syntax, but other shells don't e.g. the default in Alpine Linux.
27+
// We therefore use an explicit sequence.
28+
String retrySequence = IntStream.rangeClosed(1, 10).mapToObj(String::valueOf).collect(Collectors.joining(" "));
29+
30+
StringBuilder commandWithRetry = new StringBuilder("for iter in " + retrySequence + "; do \n");
2431
commandWithRetry.append(indent).append(" ").append(command).append(" && \n");
2532
commandWithRetry.append(indent).append(" exit_code=0 && break || \n");
2633
commandWithRetry.append(indent);

distribution/docker/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ tasks.named("composePull").configure {
221221
enabled = false
222222
}
223223

224+
tasks.named("composeUp").configure {
225+
dependsOn tasks.named("preProcessFixture")
226+
}
227+
224228
void addBuildDockerContextTask(Architecture architecture, DockerBase base) {
225229
String configDirectory = base == DockerBase.IRON_BANK ? 'scripts' : 'config'
226230
String arch = architecture == Architecture.AARCH64 ? '-aarch64' : ''

0 commit comments

Comments
 (0)