Skip to content

Commit

Permalink
docker: ensure ClickHouse init script is always executed
Browse files Browse the repository at this point in the history
Recent versions of ClickHouse do not execute the provided entrypoint
script when the database exists. Workaround this by using our own
entrypoint and use it in place of the official one.

See ClickHouse/ClickHouse#50724.
  • Loading branch information
vincentbernat committed Nov 28, 2023
1 parent 1628c65 commit fa8dd62
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
4 changes: 4 additions & 0 deletions console/data/docs/99-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ identified with a specific icon:
- 🩹: bug fix
- 🌱: miscellaneous change

## 1.9.2 - 2023-11-28

- 🩹 *docker*: ensure ClickHouse init script is executed even when database already exists

## 1.9.1 - 2023-10-06

- 🌱 *console*: add filtering support for custom columns
Expand Down
3 changes: 2 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ services:
clickhouse:
image: clickhouse/clickhouse-server:23.3
volumes:
- ../orchestrator/clickhouse/data/docker-entrypoint.sh:/docker-entrypoint-initdb.d/init-db.sh:ro
- ../orchestrator/clickhouse/data/docker-entrypoint.sh:/entrypoint-override.sh:ro
- akvorado-clickhouse:/var/lib/clickhouse
entrypoint: /entrypoint-override.sh
environment:
- CLICKHOUSE_INIT_TIMEOUT=60
restart: unless-stopped
Expand Down
23 changes: 15 additions & 8 deletions orchestrator/clickhouse/data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#!/bin/sh
#!/bin/bash

set -ex
set -e

rm -f /tmp/init.sh
while [ ! -s /tmp/init.sh ]; do
sleep 1
wget --no-proxy -qO /tmp/init.sh http://akvorado-orchestrator:8080/api/v0/orchestrator/clickhouse/init.sh || continue
done
sh /tmp/init.sh
if [[ $# -lt 1 ]] || [[ "$1" = "--"* ]]; then
rm -f /tmp/init.sh
while [[ ! -s /tmp/init.sh ]]; do
sleep 1
echo "Downloading ClickHouse init script..."
wget --no-proxy -qO /tmp/init.sh \
http://akvorado-orchestrator:8080/api/v0/orchestrator/clickhouse/init.sh || continue
done
sh /tmp/init.sh
fi

# Use official entrypoint
exec /entrypoint.sh "$@"
4 changes: 4 additions & 0 deletions orchestrator/clickhouse/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ var (
initShTemplate = template.Must(template.New("initsh").Parse(`#!/bin/sh
# Install Protobuf schema
mkdir -p /var/lib/clickhouse/format_schemas
echo "Install flow schema flow-{{ .FlowSchemaHash }}.proto"
cat > /var/lib/clickhouse/format_schemas/flow-{{ .FlowSchemaHash }}.proto <<'EOPROTO'
{{ .FlowSchema }}
EOPROTO
# Alter ClickHouse configuration
mkdir -p /etc/clickhouse-server/config.d
echo "Add Akvorado-specific configuration to ClickHouse"
cat > /etc/clickhouse-server/config.d/akvorado.xml <<'EOCONFIG'
<clickhouse>
{{- if gt .SystemLogTTL 0 }}
Expand Down
3 changes: 3 additions & 0 deletions orchestrator/clickhouse/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func TestHTTPEndpoints(t *testing.T) {
`#!/bin/sh`,
``,
`# Install Protobuf schema`,
`mkdir -p /var/lib/clickhouse/format_schemas`,
fmt.Sprintf(`echo "Install flow schema flow-%s.proto"`,
c.d.Schema.ProtobufMessageHash()),
fmt.Sprintf(`cat > /var/lib/clickhouse/format_schemas/flow-%s.proto <<'EOPROTO'`,
c.d.Schema.ProtobufMessageHash()),
"",
Expand Down

0 comments on commit fa8dd62

Please sign in to comment.