Skip to content

Commit

Permalink
Separate State dir for cloud/e2e (#6291)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
himadrisingh authored and k-anshul committed Jan 6, 2025
1 parent 29e7827 commit f343408
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tsc-tmp/
!/runtime/drivers/duckdb/extensions/embed/**/.gitkeep
/dev-project*
/dev-cloud-state*
/e2e-cloud-state*
/playwright-report

# data files
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/devtool/data/cloud-deps.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
43 changes: 23 additions & 20 deletions cli/cmd/devtool/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
const (
minGoVersion = "1.23"
minNodeVersion = "18"
stateDirCloud = "dev-cloud-state"
stateDirLocal = "dev-project"
rillGithubURL = "https://github.com/rilldata/rill"
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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) })
}
Expand Down Expand Up @@ -384,21 +385,22 @@ 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()
if err != nil {
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
Expand Down Expand Up @@ -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 == "" {
Expand Down

0 comments on commit f343408

Please sign in to comment.