Commit 7e76fc67 authored by Yann Hodique's avatar Yann Hodique Committed by GitHub

feat(kurtosis-devnet): pass args in-memory (#13576)

Now that we don't use the kurtosis cli, there's no reason to go
through the filesystem to pass a configuration file.
parent dedf3452
...@@ -259,7 +259,7 @@ func deploy(ctx context.Context, cfg *config, r io.Reader) error { ...@@ -259,7 +259,7 @@ func deploy(ctx context.Context, cfg *config, r io.Reader) error {
} }
defer envOutput.Close() defer envOutput.Close()
} else { } else {
log.Println("Environment description:") log.Println("\nEnvironment description:")
} }
enc := json.NewEncoder(envOutput) enc := json.NewEncoder(envOutput)
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"os"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/deployer" "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/deployer"
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/spec" "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/spec"
...@@ -130,23 +129,6 @@ func NewKurtosisDeployer(opts ...KurtosisDeployerOptions) *KurtosisDeployer { ...@@ -130,23 +129,6 @@ func NewKurtosisDeployer(opts ...KurtosisDeployerOptions) *KurtosisDeployer {
return d return d
} }
// prepareArgFile creates a temporary file with the input content and returns its path
// The caller is responsible for deleting the file.
func (d *KurtosisDeployer) prepareArgFile(input io.Reader) (string, error) {
argFile, err := os.CreateTemp("", "kurtosis-args-*.yaml")
if err != nil {
return "", fmt.Errorf("failed to create temporary arg file: %w", err)
}
defer argFile.Close()
if _, err := io.Copy(argFile, input); err != nil {
os.Remove(argFile.Name())
return "", fmt.Errorf("failed to write arg file: %w", err)
}
return argFile.Name(), nil
}
func (d *KurtosisDeployer) getWallets(wallets deployer.WalletList) WalletMap { func (d *KurtosisDeployer) getWallets(wallets deployer.WalletList) WalletMap {
walletMap := make(WalletMap) walletMap := make(WalletMap)
for _, wallet := range wallets { for _, wallet := range wallets {
...@@ -219,15 +201,8 @@ func (d *KurtosisDeployer) Deploy(ctx context.Context, input io.Reader) (*Kurtos ...@@ -219,15 +201,8 @@ func (d *KurtosisDeployer) Deploy(ctx context.Context, input io.Reader) (*Kurtos
return nil, fmt.Errorf("failed to parse input spec: %w", err) return nil, fmt.Errorf("failed to parse input spec: %w", err)
} }
// Prepare argument file
argFile, err := d.prepareArgFile(inputCopy)
if err != nil {
return nil, err
}
defer os.Remove(argFile)
// Run kurtosis command // Run kurtosis command
if err := d.runKurtosis(ctx, argFile); err != nil { if err := d.runKurtosis(ctx, inputCopy); err != nil {
return nil, err return nil, err
} }
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io"
"os" "os"
"github.com/fatih/color" "github.com/fatih/color"
...@@ -374,10 +375,17 @@ func (w *instructionResultWrapper) GetSerializedInstructionResult() string { ...@@ -374,10 +375,17 @@ func (w *instructionResultWrapper) GetSerializedInstructionResult() string {
} }
// runKurtosis executes the kurtosis package using the SDK // runKurtosis executes the kurtosis package using the SDK
func (d *KurtosisDeployer) runKurtosis(ctx context.Context, argFile string) error { func (d *KurtosisDeployer) runKurtosis(ctx context.Context, args io.Reader) error {
if d.dryRun { if d.dryRun {
fmt.Printf("Dry run mode enabled, would run kurtosis package %s with args file %s in enclave %s\n", fmt.Printf("Dry run mode enabled, would run kurtosis package %s in enclave %s\n",
d.packageName, argFile, d.enclave) d.packageName, d.enclave)
if args != nil {
fmt.Println("\nWith arguments:")
if _, err := io.Copy(os.Stdout, args); err != nil {
return fmt.Errorf("failed to dump args: %w", err)
}
fmt.Println()
}
return nil return nil
} }
...@@ -405,11 +413,12 @@ func (d *KurtosisDeployer) runKurtosis(ctx context.Context, argFile string) erro ...@@ -405,11 +413,12 @@ func (d *KurtosisDeployer) runKurtosis(ctx context.Context, argFile string) erro
fmt.Printf("Using existing enclave '%s'\n\n", d.enclave) fmt.Printf("Using existing enclave '%s'\n\n", d.enclave)
} }
// Set up run config with args if provided
var serializedParams string var serializedParams string
if argFile != "" { if args != nil {
argsBytes, err := os.ReadFile(argFile) argsBytes, err := io.ReadAll(args)
if err != nil { if err != nil {
return fmt.Errorf("failed to read args file: %w", err) return fmt.Errorf("failed to read args: %w", err)
} }
serializedParams = string(argsBytes) serializedParams = string(argsBytes)
} }
......
...@@ -261,7 +261,7 @@ func TestRunKurtosis(t *testing.T) { ...@@ -261,7 +261,7 @@ func TestRunKurtosis(t *testing.T) {
d := NewKurtosisDeployer() d := NewKurtosisDeployer()
d.kurtosisCtx = fakeCtx d.kurtosisCtx = fakeCtx
err := d.runKurtosis(ctx, "") err := d.runKurtosis(ctx, nil)
if tt.wantErr { if tt.wantErr {
assert.Error(t, err) assert.Error(t, err)
} else { } else {
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"os"
"strings" "strings"
"testing" "testing"
...@@ -58,22 +57,6 @@ func TestKurtosisDeployer(t *testing.T) { ...@@ -58,22 +57,6 @@ func TestKurtosisDeployer(t *testing.T) {
} }
} }
func TestPrepareArgFile(t *testing.T) {
d := NewKurtosisDeployer()
input := strings.NewReader("test content")
path, err := d.prepareArgFile(input)
require.NoError(t, err)
defer func() {
err := os.Remove(path)
require.NoError(t, err)
}()
content, err := os.ReadFile(path)
require.NoError(t, err)
assert.Equal(t, "test content", string(content))
}
// fakeEnclaveInspecter implements EnclaveInspecter for testing // fakeEnclaveInspecter implements EnclaveInspecter for testing
type fakeEnclaveInspecter struct { type fakeEnclaveInspecter struct {
result *inspect.InspectData result *inspect.InspectData
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment