From f343408246c7479a80dd65e769d64130db3d8da9 Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Fri, 3 Jan 2025 03:32:36 +0530 Subject: [PATCH] Separate State dir for cloud/e2e (#6291) * Separate State dir for cloud/e2e * rename * Apply suggestions from code review * Update cli/cmd/devtool/start.go * Update cli/cmd/devtool/start.go * Update cli/cmd/devtool/start.go * fix the order of tasks --- .gitignore | 1 + .../data/cloud-deps.docker-compose.yml | 4 +- cli/cmd/devtool/start.go | 43 ++++++++++--------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index adb8493282c..c2911aa847b 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ tsc-tmp/ !/runtime/drivers/duckdb/extensions/embed/**/.gitkeep /dev-project* /dev-cloud-state* +/e2e-cloud-state* /playwright-report # data files diff --git a/cli/cmd/devtool/data/cloud-deps.docker-compose.yml b/cli/cmd/devtool/data/cloud-deps.docker-compose.yml index b4d8f348fc9..b8ef86ebc30 100644 --- a/cli/cmd/devtool/data/cloud-deps.docker-compose.yml +++ b/cli/cmd/devtool/data/cloud-deps.docker-compose.yml @@ -8,7 +8,7 @@ services: ports: - '5432:5432' volumes: - - ../../../../dev-cloud-state/postgres:/var/lib/postgresql/data + - ../../../../${RILL_DEVTOOL_STATE_DIRECTORY}/postgres:/var/lib/postgresql/data e2e-postgres: image: postgres:17 restart: always @@ -63,4 +63,4 @@ services: image: stripe/stripe-cli:v1.21.11 command: listen --forward-to http://host.docker.internal:8080/payment/webhook --config /etc/stripe-config.toml volumes: - - ../../../../dev-cloud-state/stripe-config.toml:/etc/stripe-config.toml + - ../../../../${RILL_DEVTOOL_STATE_DIRECTORY}/stripe-config.toml:/etc/stripe-config.toml diff --git a/cli/cmd/devtool/start.go b/cli/cmd/devtool/start.go index 4f24ed37f70..d23e9164df4 100644 --- a/cli/cmd/devtool/start.go +++ b/cli/cmd/devtool/start.go @@ -30,7 +30,6 @@ import ( const ( minGoVersion = "1.23" minNodeVersion = "18" - stateDirCloud = "dev-cloud-state" stateDirLocal = "dev-project" rillGithubURL = "https://github.com/rilldata/rill" ) @@ -225,19 +224,6 @@ func (s *servicesCfg) parse() error { type cloud struct{} func (s cloud) start(ctx context.Context, ch *cmdutil.Helper, verbose, reset, refreshDotenv bool, preset string, services *servicesCfg) error { - if reset { - err := s.resetState(ctx) - if err != nil { - return fmt.Errorf("reset cloud deps: %w", err) - } - logInfo.Printf("Reset cloud dependencies\n") - } - - err := os.MkdirAll(stateDirCloud, os.ModePerm) - if err != nil { - return fmt.Errorf("failed to create state dir %q: %w", stateDirCloud, err) - } - if refreshDotenv { err := downloadDotenv(ctx, preset) if err != nil { @@ -247,7 +233,7 @@ func (s cloud) start(ctx context.Context, ch *cmdutil.Helper, verbose, reset, re } // Validate the .env file is well-formed. - err = checkDotenv() + err := checkDotenv() if err != nil { return err } @@ -256,8 +242,23 @@ func (s cloud) start(ctx context.Context, ch *cmdutil.Helper, verbose, reset, re return fmt.Errorf("error parsing .env: %w", err) } + if reset { + err := s.resetState(ctx) + if err != nil { + return fmt.Errorf("reset cloud deps: %w", err) + } + logInfo.Printf("Reset cloud dependencies\n") + } + g, ctx := errgroup.WithContext(ctx) + stateDir := lookupDotenv("RILL_DEVTOOL_STATE_DIRECTORY") + err = os.MkdirAll(stateDir, os.ModePerm) + if err != nil { + return fmt.Errorf("failed to create state dir %q: %w", stateDir, err) + } + logInfo.Printf("State dir set to %s\n", stateDir) + if services.deps { g.Go(func() error { return s.runDeps(ctx, verbose) }) } @@ -384,13 +385,14 @@ func (s cloud) resetState(ctx context.Context) (err error) { } }() - _ = os.RemoveAll(stateDirCloud) - return newCmd(ctx, "docker", "compose", "-f", "cli/cmd/devtool/data/cloud-deps.docker-compose.yml", "down", "--volumes").Run() + stateDir := lookupDotenv("RILL_DEVTOOL_STATE_DIRECTORY") + _ = os.RemoveAll(stateDir) + return newCmd(ctx, "docker", "compose", "--env-file", ".env", "-f", "cli/cmd/devtool/data/cloud-deps.docker-compose.yml", "down", "--volumes").Run() } func (s cloud) runDeps(ctx context.Context, verbose bool) error { composeFile := "cli/cmd/devtool/data/cloud-deps.docker-compose.yml" - logInfo.Printf("Starting dependencies: docker compose -f %s up\n", composeFile) + logInfo.Printf("Starting dependencies: docker compose --env-file .env -f %s up\n", composeFile) defer logInfo.Printf("Stopped dependencies\n") err := prepareStripeConfig() @@ -398,7 +400,7 @@ func (s cloud) runDeps(ctx context.Context, verbose bool) error { return fmt.Errorf("failed to prepare stripe config: %w", err) } - cmd := newCmd(ctx, "docker", "compose", "-f", composeFile, "up") + cmd := newCmd(ctx, "docker", "compose", "--env-file", ".env", "-f", composeFile, "up") if verbose { cmd.Stdout = os.Stdout cmd.Stderr = os.Stdout @@ -722,7 +724,8 @@ func (s local) awaitUI(ctx context.Context) error { func prepareStripeConfig() error { templateFile := "cli/cmd/devtool/data/stripe-config.template" - outputFile := filepath.Join(stateDirCloud, "stripe-config.toml") + stateDir := lookupDotenv("RILL_DEVTOOL_STATE_DIRECTORY") + outputFile := filepath.Join(stateDir, "stripe-config.toml") apiKey := lookupDotenv("RILL_DEVTOOL_STRIPE_CLI_API_KEY") if apiKey == "" {