From 41ef4939b708149e3a498d00f11d4ce80dfee9b9 Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Mon, 30 Nov 2026 22:49:17 +0000 Subject: [PATCH] Add a clickhouse-client feature Installs clickhouse-client from ClickHouse's signed stable apt repository, latest by default or a pinned package version. A pinned client also pins clickhouse-common-static, which the client depends on at exactly its own version. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 2 + src/clickhouse-client/README.md | 27 ++++++++++ .../devcontainer-feature.json | 21 ++++++++ src/clickhouse-client/install.sh | 52 +++++++++++++++++++ .../install-trixie-with-settings.sh | 14 +++++ test/clickhouse-client/install-trixie.sh | 14 +++++ test/clickhouse-client/scenarios.json | 19 +++++++ test/clickhouse-client/test.sh | 14 +++++ 8 files changed, 163 insertions(+) create mode 100644 src/clickhouse-client/README.md create mode 100644 src/clickhouse-client/devcontainer-feature.json create mode 100755 src/clickhouse-client/install.sh create mode 100755 test/clickhouse-client/install-trixie-with-settings.sh create mode 100755 test/clickhouse-client/install-trixie.sh create mode 100644 test/clickhouse-client/scenarios.json create mode 100755 test/clickhouse-client/test.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6125c6a..dff5fcd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,7 @@ jobs: matrix: features: - actionlint + - clickhouse-client - elixir-project - google-cloud-cli - node @@ -37,6 +38,7 @@ jobs: matrix: features: - actionlint + - clickhouse-client - google-cloud-cli - node - postgresql-client diff --git a/src/clickhouse-client/README.md b/src/clickhouse-client/README.md new file mode 100644 index 0000000..f8a4743 --- /dev/null +++ b/src/clickhouse-client/README.md @@ -0,0 +1,27 @@ +# clickhouse-client + +Install `clickhouse-client`, the command-line client for [ClickHouse](https://clickhouse.com), from ClickHouse's signed `stable` apt repository. + +## Usage + +```json +"features": { + "ghcr.io/CargoSense/devcontainer-features/clickhouse-client:1": {} +} +``` + +## Options + +| Option ID | Description | Type | Default Value | +|:----------|:------------------------------------------|:-------|:--------------| +| `version` | The clickhouse-client version to install. | string | `latest` | + +A pinned version is a full package version such as `26.8.51.4`; `apt-cache madison clickhouse-client` lists them once the repository is added. + +## Image size + +The client ships inside `clickhouse-common-static`, the single ClickHouse binary, so the Feature adds about 600 MB to the image. ClickHouse publishes no smaller client-only package. + +## OS Support + +This Feature should work on recent versions of Debian/Ubuntu and Linux distributions using the [apt](https://wiki.debian.org/AptCLI) management tool. diff --git a/src/clickhouse-client/devcontainer-feature.json b/src/clickhouse-client/devcontainer-feature.json new file mode 100644 index 0000000..c0661ee --- /dev/null +++ b/src/clickhouse-client/devcontainer-feature.json @@ -0,0 +1,21 @@ +{ + "name": "ClickHouse Client", + "id": "clickhouse-client", + "version": "1.0.0", + "description": "Install clickhouse-client, the command-line client for ClickHouse.", + "documentationURL": "https://github.com/CargoSense/devcontainer-features/tree/main/src/clickhouse-client", + "licenseURL": "https://github.com/CargoSense/devcontainer-features/blob/main/LICENSE", + "options": { + "version": { + "type": "string", + "proposals": [ + "latest" + ], + "default": "latest", + "description": "Select or enter a clickhouse-client version (e.g. 26.8.51.4)." + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} diff --git a/src/clickhouse-client/install.sh b/src/clickhouse-client/install.sh new file mode 100755 index 0000000..5d11b90 --- /dev/null +++ b/src/clickhouse-client/install.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env sh + +set -e + +CLICKHOUSE_CLIENT_VERSION="${VERSION:-"latest"}" + +if [ "$(id -u)" -ne 0 ]; then + printf 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +curl_installed="" +gpg_installed="" + +if ! type curl >/dev/null 2>&1; then + apt-get update --yes + apt-get install --no-install-recommends --yes curl ca-certificates + + curl_installed="true" +fi + +if ! type gpg >/dev/null 2>&1; then + apt-get update --yes + apt-get install --no-install-recommends --yes gpg + + gpg_installed="true" +fi + +# ClickHouse signs its deb repository with the key it publishes beside its rpm +# repository; https://clickhouse.com/docs/install/debian_ubuntu uses the same URL. +curl -fsSL https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key | gpg --dearmor --yes -o /usr/share/keyrings/clickhouse-keyring.gpg +echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg arch=$(dpkg --print-architecture)] https://packages.clickhouse.com/deb stable main" > /etc/apt/sources.list.d/clickhouse.list + +apt-get update --yes + +if [ "${CLICKHOUSE_CLIENT_VERSION}" = "latest" ]; then + DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes clickhouse-client +else + # clickhouse-client depends on exactly its own version of clickhouse-common-static, + # so a pinned client needs the matching common package pinned beside it. + DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes \ + clickhouse-client="${CLICKHOUSE_CLIENT_VERSION}" \ + clickhouse-common-static="${CLICKHOUSE_CLIENT_VERSION}" +fi + +if [ -n "${curl_installed}" ]; then + apt purge curl --autoremove --yes +fi + +if [ -n "${gpg_installed}" ]; then + apt purge gpg --autoremove --yes +fi diff --git a/test/clickhouse-client/install-trixie-with-settings.sh b/test/clickhouse-client/install-trixie-with-settings.sh new file mode 100755 index 0000000..722453f --- /dev/null +++ b/test/clickhouse-client/install-trixie-with-settings.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# shellcheck source=/dev/null +source dev-container-features-test-lib + +# Feature-specific tests +check "version" bash -c "clickhouse-client --version | grep 26.8.51.4" +check "which clickhouse-client" bash -c "which clickhouse-client | grep /usr/bin/clickhouse-client" + +# Report result +reportResults diff --git a/test/clickhouse-client/install-trixie.sh b/test/clickhouse-client/install-trixie.sh new file mode 100755 index 0000000..3aea603 --- /dev/null +++ b/test/clickhouse-client/install-trixie.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# shellcheck source=/dev/null +source dev-container-features-test-lib + +# Feature-specific tests +check "version" clickhouse-client --version +check "which clickhouse-client" bash -c "which clickhouse-client | grep /usr/bin/clickhouse-client" + +# Report result +reportResults diff --git a/test/clickhouse-client/scenarios.json b/test/clickhouse-client/scenarios.json new file mode 100644 index 0000000..a63277f --- /dev/null +++ b/test/clickhouse-client/scenarios.json @@ -0,0 +1,19 @@ +{ + "install-trixie": { + "image": "debian:trixie", + "features": { + "clickhouse-client": { + "version": "latest" + } + } + }, + + "install-trixie-with-settings": { + "image": "debian:trixie", + "features": { + "clickhouse-client": { + "version": "26.8.51.4" + } + } + } +} diff --git a/test/clickhouse-client/test.sh b/test/clickhouse-client/test.sh new file mode 100755 index 0000000..3aea603 --- /dev/null +++ b/test/clickhouse-client/test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# shellcheck source=/dev/null +source dev-container-features-test-lib + +# Feature-specific tests +check "version" clickhouse-client --version +check "which clickhouse-client" bash -c "which clickhouse-client | grep /usr/bin/clickhouse-client" + +# Report result +reportResults