From 3db6148d6e6db6ed91a3e0a199ba6f455167b7bd Mon Sep 17 00:00:00 2001 From: Polyglot AI <293096396+polyglotAI-bot@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:38:27 +0000 Subject: [PATCH] [tests] Start the test containers without a shell From ClickHouse 26.12 (ClickHouse/ClickHouse#129069), the default clickhouse/clickhouse-server image is built FROM scratch: it has no /bin/sh, coreutils or /entrypoint.sh, and its entrypoint is `clickhouse docker-init`. The test harness set the entrypoint to /bin/sh to run the bash script containers/clickhouse-server/patch, and started Keeper with `sh -c "mkdir ... && exec clickhouse-keeper"`, so no container started with the `head` image. - Copy the server configuration straight into /etc/clickhouse-server and keep the entrypoint of the image. A copy merges with the files of the image, as the `cp` of the script did. Remove the script. - Start Keeper as `/usr/bin/clickhouse keeper`. Keeper creates its log and snapshot directories itself. - CONTRIBUTING.md: TEST_CLICKHOUSE_ADDITIONAL_PACKAGES needs an image with apt-get (a `-ubuntu` tag from 26.12). Fixes: https://github.com/ClickHouse/clickhouse-java/issues/3441 Co-Authored-By: Claude Opus 5.5 --- CONTRIBUTING.md | 2 +- .../client/ClickHouseContainerStarter.java | 19 +++++++++++-------- .../ClusterClickHouseContainerStarter.java | 6 ++---- .../containers/clickhouse-server/patch | 15 --------------- 4 files changed, 14 insertions(+), 28 deletions(-) delete mode 100644 clickhouse-client/src/test/resources/containers/clickhouse-server/patch diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 80ab28bdca..968bcb5507 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -151,7 +151,7 @@ Integration tests usually require [Docker](https://docs.docker.com/engine/instal | `TEST_CLICKHOUSE_PASSWORD` | `test_default_password` | Password | | `TEST_CLICKHOUSE_SECURE` | `false` | `true` uses HTTPS on port 8443 (ClickHouse Cloud) | | `TEST_CLICKHOUSE_TIMEZONE` | `UTC` | Timezone inside a started container | -| `TEST_CLICKHOUSE_ADDITIONAL_PACKAGES` | | Extra apt packages installed into the image | +| `TEST_CLICKHOUSE_ADDITIONAL_PACKAGES` | | Extra apt packages installed into the image. Needs an image with `apt-get`: from ClickHouse 26.12, use a tag with the suffix `-ubuntu` (the default image has no shell) | | `TEST_DB_NAME` | generated | Database name. An external name must start with `clickhouse_java_test_` | | `TEST_PROXY_ADDRESS` | | External proxy as `host:port` | | `TEST_PROXY_IMAGE` | `ghcr.io/shopify/toxiproxy:2.5.0` | Toxiproxy image | diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java index b26710ce90..75ef288200 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java @@ -8,6 +8,7 @@ import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.images.builder.ImageFromDockerfile; +import org.testcontainers.utility.MountableFile; import java.time.Duration; import java.util.List; @@ -27,7 +28,7 @@ public abstract class ClickHouseContainerStarter { static final String FRONTEND_ALIAS = "clickhouse"; static final String CONTAINER_TMP_DIR = "/tmp"; - private static final String CUSTOM_DIRECTORY = "/custom"; + private static final String SERVER_CONFIG_DIRECTORY = "/etc/clickhouse-server"; private static final String CONFIG_RESOURCE = "containers/clickhouse-server"; protected final ClickHouseTestEnvironment environment; @@ -124,12 +125,10 @@ protected final GenericContainer newClickHouseServer(String networkAlias, Str .from(environment.getImageRef()) .run("apt-get update && apt-get install -y " + additionalPackages)))) .withCreateContainerCmdModifier(command -> { - command.withEntrypoint("/bin/sh"); if (containerName != null) { command.withName(containerName); } }) - .withCommand("-c", String.format("chmod +x %1$s/patch && %1$s/patch", CUSTOM_DIRECTORY)) .withEnv("TZ", environment.getTimezone()) .withExposedPorts( ClickHouseProtocol.GRPC.getDefaultPort(), @@ -139,7 +138,9 @@ protected final GenericContainer newClickHouseServer(String networkAlias, Str ClickHouseProtocol.TCP.getDefaultPort(), ClickHouseProtocol.TCP.getDefaultSecurePort(), ClickHouseProtocol.POSTGRESQL.getDefaultPort()) - .withClasspathResourceMapping(CONFIG_RESOURCE, CUSTOM_DIRECTORY, BindMode.READ_ONLY) + // The default image has no shell: copy the files into the configuration directory of the + // image (a copy merges with the files of the image), and keep the entrypoint of the image. + .withCopyFileToContainer(MountableFile.forClasspathResource(CONFIG_RESOURCE), SERVER_CONFIG_DIRECTORY) .withClasspathResourceMapping("empty.csv", "/var/lib/clickhouse/user_files/empty.csv", BindMode.READ_ONLY) .withFileSystemBind(System.getProperty("java.io.tmpdir"), CONTAINER_TMP_DIR, BindMode.READ_WRITE) @@ -149,10 +150,12 @@ protected final GenericContainer newClickHouseServer(String networkAlias, Str container = container .withEnv("CLICKHOUSE_REPLICA", replicaName) .withEnv("CLICKHOUSE_INTERSERVER_HOST", networkAlias) - .withClasspathResourceMapping("containers/clickhouse-cluster/config.d/custom_config.xml", - CUSTOM_DIRECTORY + "/config.d/custom_config.xml", BindMode.READ_ONLY) - .withClasspathResourceMapping("containers/clickhouse-cluster/users.d/cluster_quorum.xml", - CUSTOM_DIRECTORY + "/users.d/cluster_quorum.xml", BindMode.READ_ONLY); + .withCopyFileToContainer(MountableFile.forClasspathResource( + "containers/clickhouse-cluster/config.d/custom_config.xml"), + SERVER_CONFIG_DIRECTORY + "/config.d/custom_config.xml") + .withCopyFileToContainer(MountableFile.forClasspathResource( + "containers/clickhouse-cluster/users.d/cluster_quorum.xml"), + SERVER_CONFIG_DIRECTORY + "/users.d/cluster_quorum.xml"); } return container.waitingFor(Wait.forHttp("/ping").forPort(HTTP_PORT) .forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS))); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java index 7d255fc18d..bb9cb75177 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java @@ -36,16 +36,14 @@ final class ClusterClickHouseContainerStarter extends ClickHouseContainerStarter String baseName = environment.getContainerName(); this.keeper = new GenericContainer<>(environment.getImageRef()) .withCreateContainerCmdModifier(command -> { - command.withEntrypoint("/bin/sh"); + command.withEntrypoint("/usr/bin/clickhouse"); if (baseName != null) { command.withName(baseName + "-keeper"); } }) .withNetwork(network) .withNetworkAliases("clickhouse-keeper") - .withCommand("-c", "mkdir -p /var/lib/clickhouse/coordination/log" - + " /var/lib/clickhouse/coordination/snapshots" - + " && exec clickhouse-keeper --config-file=/etc/clickhouse-keeper/keeper_config.xml") + .withCommand("keeper", "--config-file=/etc/clickhouse-keeper/keeper_config.xml") .withClasspathResourceMapping(KEEPER_CONFIG, "/etc/clickhouse-keeper/keeper_config.xml", BindMode.READ_ONLY) .withExposedPorts(KEEPER_PORT) diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-server/patch b/clickhouse-client/src/test/resources/containers/clickhouse-server/patch deleted file mode 100644 index 1ebee8d084..0000000000 --- a/clickhouse-client/src/test/resources/containers/clickhouse-server/patch +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -e - -SERVER_CONF_DIR="/etc/clickhouse-server" - -\cp -rfv "$(dirname $0)/." $SERVER_CONF_DIR - -if chown clickhouse:clickhouse -R /etc/clickhouse-server/certs; then - echo "Ownership of /etc/clickhouse-server/certs changed successfully." -else - echo "Failed to change ownership of /etc/clickhouse-server/certs." -fi - -/entrypoint.sh