Skip to content

Commit 3776923

Browse files
committed
Fix passing positional args to ES in Docker (#88502)
As part of #50277, we removed the `TAKE_FILE_OWNERSHIP` option from the Docker entrypoint script and the associated chroot calls, and instead just defaulted to running the image as `elasticsearch` instead of `root`. However, we didn't check that it was still possible to pass CLI options to Elasticsearch via CLI arguments, and broke this by mistake. This is probably an uncommon pattern, versus environment variables or a config file. Nevertheless, it is supposed to be possible and is mentioned in the documentation. Fix the problem by suppling the missing positional params when calling Elasticsearch, and add a test case so that we don't break it again.
1 parent 6d889f7 commit 3776923

4 files changed

Lines changed: 27 additions & 2 deletions

File tree

distribution/docker/src/docker/bin/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ fi
8181

8282
# Signal forwarding and child reaping is handled by `tini`, which is the
8383
# actual entrypoint of the container
84-
exec /usr/share/elasticsearch/bin/elasticsearch $POSITIONAL_PARAMETERS <<<"$KEYSTORE_PASSWORD"
84+
exec /usr/share/elasticsearch/bin/elasticsearch "$@" $POSITIONAL_PARAMETERS <<<"$KEYSTORE_PASSWORD"

docs/changelog/88502.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 88502
2+
summary: Fix passing positional args to ES in Docker
3+
area: Packaging
4+
type: bug
5+
issues: []

qa/os/src/test/java/org/elasticsearch/packaging/test/DockerTests.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,18 @@ public void test170DefaultShellIsBash() {
10961096
}
10971097
}
10981098

1099+
/**
1100+
* Ensure that it is possible to apply CLI options when running the image.
1101+
*/
1102+
public void test171AdditionalCliOptionsAreForwarded() throws Exception {
1103+
runContainer(distribution(), builder().runArgs("bin/elasticsearch", "-Ecluster.name=kimchy").envVar("ELASTIC_PASSWORD", PASSWORD));
1104+
waitForElasticsearch(installation, "elastic", PASSWORD);
1105+
1106+
final JsonNode node = getJson("/", "elastic", PASSWORD, ServerUtils.getCaCert(installation));
1107+
1108+
assertThat(node.get("cluster_name").textValue(), equalTo("kimchy"));
1109+
}
1110+
10991111
/**
11001112
* Check that the UBI images has the correct license information in the correct place.
11011113
*/
@@ -1193,7 +1205,7 @@ private List<String> listPlugins() {
11931205
/**
11941206
* Check that readiness listener works
11951207
*/
1196-
public void testReadiness001() throws Exception {
1208+
public void test500Readiness() throws Exception {
11971209
assertFalse(readinessProbe(9399));
11981210
// Disabling security so we wait for green
11991211
installation = runContainer(

qa/os/src/test/java/org/elasticsearch/packaging/util/docker/DockerRun.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class DockerRun {
3434
private Integer uid;
3535
private Integer gid;
3636
private final List<String> extraArgs = new ArrayList<>();
37+
private final List<String> runArgs = new ArrayList<>();
3738
private String memory = "2g"; // default to 2g memory limit
3839

3940
private DockerRun() {}
@@ -95,6 +96,11 @@ public DockerRun extraArgs(String... args) {
9596
return this;
9697
}
9798

99+
public DockerRun runArgs(String... args) {
100+
Collections.addAll(this.runArgs, args);
101+
return this;
102+
}
103+
98104
String build() {
99105
final List<String> cmd = new ArrayList<>();
100106

@@ -144,6 +150,8 @@ String build() {
144150
// Image name
145151
cmd.add(getImageName(distribution));
146152

153+
cmd.addAll(this.runArgs);
154+
147155
return String.join(" ", cmd);
148156
}
149157

0 commit comments

Comments
 (0)