Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

package org.elasticsearch.gradle.internal.docker;

import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
* The methods in this class take a shell command and wrap it in retry logic, so that our
* Docker builds can be more robust in the face of transient errors e.g. network issues.
Expand All @@ -20,7 +23,11 @@ static String loop(String name, String command) {
static String loop(String name, String command, int indentSize, String exitKeyword) {
String indent = " ".repeat(indentSize);

StringBuilder commandWithRetry = new StringBuilder("for iter in {1..10}; do \n");
// bash understands the `{1..10}` syntax, but other shells don't e.g. the default in Alpine Linux.
// We therefore use an explicit sequence.
String retrySequence = IntStream.rangeClosed(1, 10).mapToObj(String::valueOf).collect(Collectors.joining(" "));

StringBuilder commandWithRetry = new StringBuilder("for iter in " + retrySequence + "; do \n");
commandWithRetry.append(indent).append(" ").append(command).append(" && \n");
commandWithRetry.append(indent).append(" exit_code=0 && break || \n");
commandWithRetry.append(indent);
Expand Down
4 changes: 4 additions & 0 deletions distribution/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ tasks.named("composePull").configure {
enabled = false
}

tasks.named("composeUp").configure {
dependsOn tasks.named("preProcessFixture")
}

void addBuildDockerContextTask(Architecture architecture, DockerBase base) {
String configDirectory = base == DockerBase.IRON_BANK ? 'scripts' : 'config'
String arch = architecture == Architecture.AARCH64 ? '-aarch64' : ''
Expand Down