From 735a63bf2e93ed47e6416b832919aa8d991bddef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Egelund-M=C3=BCller?= Date: Fri, 3 Jan 2025 14:35:48 +0100 Subject: [PATCH] Add ClickHouse server and provisioner in `rill devtool` --- cli/cmd/devtool/data/clickhouse-config.xml | 13 +++++++ cli/cmd/devtool/data/clickhouse-users.xml | 37 +++++++++++++++++++ .../data/cloud-deps.docker-compose.yml | 9 +++++ cli/cmd/devtool/start.go | 24 ++++++++---- runtime/testruntime/connectors.go | 2 - 5 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 cli/cmd/devtool/data/clickhouse-config.xml create mode 100644 cli/cmd/devtool/data/clickhouse-users.xml diff --git a/cli/cmd/devtool/data/clickhouse-config.xml b/cli/cmd/devtool/data/clickhouse-config.xml new file mode 100644 index 00000000000..9b6cd0c4175 --- /dev/null +++ b/cli/cmd/devtool/data/clickhouse-config.xml @@ -0,0 +1,13 @@ + + + information + true + + rill devtool clickhouse + 9000 + 8123 + UTC + + true + + \ No newline at end of file diff --git a/cli/cmd/devtool/data/clickhouse-users.xml b/cli/cmd/devtool/data/clickhouse-users.xml new file mode 100644 index 00000000000..9727475733a --- /dev/null +++ b/cli/cmd/devtool/data/clickhouse-users.xml @@ -0,0 +1,37 @@ + + + + 10000000000 + 0 + in_order + 1 + best_effort + + + + + + 3600 + 0 + 0 + 0 + 0 + 0 + + + + + + default + default + default + + ::/0 + + 1 + 1 + 1 + 1 + + + \ No newline at end of file diff --git a/cli/cmd/devtool/data/cloud-deps.docker-compose.yml b/cli/cmd/devtool/data/cloud-deps.docker-compose.yml index b8ef86ebc30..0e80216ad87 100644 --- a/cli/cmd/devtool/data/cloud-deps.docker-compose.yml +++ b/cli/cmd/devtool/data/cloud-deps.docker-compose.yml @@ -64,3 +64,12 @@ services: command: listen --forward-to http://host.docker.internal:8080/payment/webhook --config /etc/stripe-config.toml volumes: - ../../../../${RILL_DEVTOOL_STATE_DIRECTORY}/stripe-config.toml:/etc/stripe-config.toml + clickhouse: + image: 'clickhouse/clickhouse-server:24.11.1.2557' + volumes: + - ./clickhouse-config.xml:/etc/clickhouse-server/config.d/config.xml + - ./clickhouse-users.xml:/etc/clickhouse-server/users.d/users.xml + - ../../../../${RILL_DEVTOOL_STATE_DIRECTORY}/clickhouse:/var/lib/clickhouse + ports: + - '9000:9000' # Native port + - '8123:8123' # HTTP port diff --git a/cli/cmd/devtool/start.go b/cli/cmd/devtool/start.go index d23e9164df4..e0c31d0eeed 100644 --- a/cli/cmd/devtool/start.go +++ b/cli/cmd/devtool/start.go @@ -252,12 +252,11 @@ func (s cloud) start(ctx context.Context, ch *cmdutil.Helper, verbose, reset, re g, ctx := errgroup.WithContext(ctx) - stateDir := lookupDotenv("RILL_DEVTOOL_STATE_DIRECTORY") - err = os.MkdirAll(stateDir, os.ModePerm) + err = os.MkdirAll(stateDirectory(), os.ModePerm) if err != nil { - return fmt.Errorf("failed to create state dir %q: %w", stateDir, err) + return fmt.Errorf("failed to create state dir %q: %w", stateDirectory(), err) } - logInfo.Printf("State dir set to %s\n", stateDir) + logInfo.Printf("State directory is %q\n", stateDirectory()) if services.deps { g.Go(func() error { return s.runDeps(ctx, verbose) }) @@ -385,8 +384,8 @@ func (s cloud) resetState(ctx context.Context) (err error) { } }() - stateDir := lookupDotenv("RILL_DEVTOOL_STATE_DIRECTORY") - _ = os.RemoveAll(stateDir) + _ = os.RemoveAll(stateDirectory()) + return newCmd(ctx, "docker", "compose", "--env-file", ".env", "-f", "cli/cmd/devtool/data/cloud-deps.docker-compose.yml", "down", "--volumes").Run() } @@ -724,8 +723,7 @@ func (s local) awaitUI(ctx context.Context) error { func prepareStripeConfig() error { templateFile := "cli/cmd/devtool/data/stripe-config.template" - stateDir := lookupDotenv("RILL_DEVTOOL_STATE_DIRECTORY") - outputFile := filepath.Join(stateDir, "stripe-config.toml") + outputFile := filepath.Join(stateDirectory(), "stripe-config.toml") apiKey := lookupDotenv("RILL_DEVTOOL_STRIPE_CLI_API_KEY") if apiKey == "" { @@ -785,3 +783,13 @@ func lookupDotenv(key string) string { } return env[key] } + +// stateDirectory returns the directory where the devtool's state is stored. +// Deleting this directory will reset the state of the local development environment. +func stateDirectory() string { + dir := lookupDotenv("RILL_DEVTOOL_STATE_DIRECTORY") + if dir == "" { + dir = "dev-cloud-state" + } + return dir +} diff --git a/runtime/testruntime/connectors.go b/runtime/testruntime/connectors.go index b8b8d4179a5..8d907ada28d 100644 --- a/runtime/testruntime/connectors.go +++ b/runtime/testruntime/connectors.go @@ -3,7 +3,6 @@ package testruntime import ( "context" "fmt" - "log" "os" "path/filepath" goruntime "runtime" @@ -65,7 +64,6 @@ var Connectors = map[string]ConnectorAcquireFunc{ require.NoError(t, err) t.Cleanup(func() { - log.Printf("TERMINATING") err := clickHouseContainer.Terminate(ctx) require.NoError(t, err) })