Skip to content

Commit

Permalink
feat(kurtosis-devnet): ensure kurtosis engine is running (#13611)
Browse files Browse the repository at this point in the history
Unfortunately the logic for doing so is not present in the kurtosis
SDK, so we have to shell out to the binary.

Make sure the version we run is compatible with the client library we
use to interact with the created enclaves.
sigma authored Jan 7, 2025
1 parent f65c549 commit 83fb599
Showing 3 changed files with 90 additions and 11 deletions.
24 changes: 22 additions & 2 deletions kurtosis-devnet/cmd/main.go
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import (

"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/build"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/api/engine"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/backend"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/serve"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/tmpl"
@@ -27,6 +28,7 @@ type config struct {
dryRun bool
localHostName string
baseDir string
kurtosisBinary string
}

func newConfig(c *cli.Context) (*config, error) {
@@ -38,6 +40,7 @@ func newConfig(c *cli.Context) (*config, error) {
environment: c.String("environment"),
dryRun: c.Bool("dry-run"),
localHostName: c.String("local-hostname"),
kurtosisBinary: c.String("kurtosis-binary"),
}

// Validate required flags
@@ -54,9 +57,14 @@ type staticServer struct {
*serve.Server
}

type engineManager interface {
EnsureRunning() error
}

type Main struct {
cfg *config
newDeployer func(opts ...kurtosis.KurtosisDeployerOptions) (deployer, error)
cfg *config
newDeployer func(opts ...kurtosis.KurtosisDeployerOptions) (deployer, error)
engineManager engineManager
}

func (m *Main) launchStaticServer(ctx context.Context) (*staticServer, func(), error) {
@@ -303,6 +311,12 @@ func (m *Main) run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if !m.cfg.dryRun {
if err := m.engineManager.EnsureRunning(); err != nil {
return fmt.Errorf("error ensuring kurtosis engine is running: %w", err)
}
}

server, cleanup, err := m.launchStaticServer(ctx)
if err != nil {
return fmt.Errorf("error launching static server: %w", err)
@@ -327,6 +341,7 @@ func mainAction(c *cli.Context) error {
newDeployer: func(opts ...kurtosis.KurtosisDeployerOptions) (deployer, error) {
return kurtosis.NewKurtosisDeployer(opts...)
},
engineManager: engine.NewEngineManager(engine.WithKurtosisBinary(cfg.kurtosisBinary)),
}
return m.run()
}
@@ -365,6 +380,11 @@ func getFlags() []cli.Flag {
Usage: "DNS for localhost from Kurtosis perspective (optional)",
Value: backend.DefaultDockerHost(),
},
&cli.StringFlag{
Name: "kurtosis-binary",
Usage: "Path to kurtosis binary (optional)",
Value: "kurtosis",
},
}
}

25 changes: 16 additions & 9 deletions kurtosis-devnet/cmd/main_test.go
Original file line number Diff line number Diff line change
@@ -28,6 +28,22 @@ func newMockDeployer(...kurtosis.KurtosisDeployerOptions) (deployer, error) {
return &mockDeployer{dryRun: true}, nil
}

type mockEngineManager struct{}

func (m *mockEngineManager) EnsureRunning() error {
return nil
}

func newTestMain(cfg *config) *Main {
return &Main{
cfg: cfg,
newDeployer: func(opts ...kurtosis.KurtosisDeployerOptions) (deployer, error) {
return newMockDeployer(opts...)
},
engineManager: &mockEngineManager{},
}
}

func TestParseFlags(t *testing.T) {
tests := []struct {
name string
@@ -106,15 +122,6 @@ func TestParseFlags(t *testing.T) {
}
}

func newTestMain(cfg *config) *Main {
return &Main{
cfg: cfg,
newDeployer: func(opts ...kurtosis.KurtosisDeployerOptions) (deployer, error) {
return newMockDeployer(opts...)
},
}
}

func TestLaunchStaticServer(t *testing.T) {
cfg := &config{
localHostName: "test.local",
52 changes: 52 additions & 0 deletions kurtosis-devnet/pkg/kurtosis/api/engine/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package engine

import (
"fmt"
"os/exec"

"github.com/kurtosis-tech/kurtosis/api/golang/kurtosis_version"
)

// EngineManager handles running the Kurtosis engine
type EngineManager struct {
kurtosisBinary string
version string
}

// Option configures an EngineManager
type Option func(*EngineManager)

// WithKurtosisBinary sets the path to the kurtosis binary
func WithKurtosisBinary(binary string) Option {
return func(e *EngineManager) {
e.kurtosisBinary = binary
}
}

// WithVersion sets the engine version
func WithVersion(version string) Option {
return func(e *EngineManager) {
e.version = version
}
}

// NewEngineManager creates a new EngineManager with the given options
func NewEngineManager(opts ...Option) *EngineManager {
e := &EngineManager{
kurtosisBinary: "kurtosis", // Default to expecting kurtosis in PATH
version: kurtosis_version.KurtosisVersion, // Default to library version
}
for _, opt := range opts {
opt(e)
}
return e
}

// EnsureRunning starts the Kurtosis engine with the configured version
func (e *EngineManager) EnsureRunning() error {
cmd := exec.Command(e.kurtosisBinary, "engine", "start", "--version", e.version)
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to start kurtosis engine: %w", err)
}
return nil
}

0 comments on commit 83fb599

Please sign in to comment.