Skip to content

Commit

Permalink
feat: update dive package path and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyasbhat0 committed Dec 12, 2023
1 parent da59c85 commit be06c12
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cli/cmd/chains/archway/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) {
return nil, common.WrapMessageToError(common.ErrDataMarshall, err.Error())
}

runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveArchwayDefaultNodeScript, runArchwayNodeWithDefaultConfigFunctionName)
runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveCosmosDefaultNodeScript, runArchwayNodeWithDefaultConfigFunctionName)

response, _, err := enclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.DiveRemotePackagePath, runConfig)

Expand All @@ -45,7 +45,7 @@ func RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) {
return nil, common.WrapMessageToError(errRemove, "Archway Run Failed.")
}

return nil, common.WrapMessageToError(err, "Archway Run Failed. Services Removed ")
return nil, common.WrapMessageToErrorf(err, "%s. %s", err, "Archway Run Failed")
}

if cli.Context().CheckSkippedInstructions(skippedInstructions) {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/chains/icon/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func RunDecentralization(cli *common.Cli, params string) error {
if err != nil {
return common.WrapMessageToError(err, "Icon Decentralization Failed")
}
starlarkConfig := common.GetStarlarkRunConfig(params, common.DiveIconDecentraliseScript, "configure_node")
starlarkConfig := common.GetStarlarkRunConfig(params, common.DiveIconDecentralizeScript, "configure_node")
data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.DiveRemotePackagePath, starlarkConfig)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/chains/neutron/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func RunNeutron(cli *common.Cli) (*common.DiveServiceResponse, error) {
return nil, common.WrapMessageToError(common.ErrDataMarshall, err.Error())
}

runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveNeutronDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName)
runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveCosmosDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName)

response, _, err := enclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.DiveRemotePackagePath, runConfig)

Expand Down
24 changes: 12 additions & 12 deletions cli/common/constants.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
package common

var DiveLogs bool
var EnclaveName string

// !!!!!!!!!!! DO NOT UPDATE! WILL BE UPDATED DURING THE RELEASE PROCESS !!!!!!!!!!!!!!!!!!!!!!
var DiveVersion = "v0.0.14-beta"
const DiveVersion = "v0.0.14-beta"

const (
DiveEnclave = "dive"
DiveRemotePackagePath = "github.com/hugobyte/dive"
DiveRemotePackagePath = "github.com/hugobyte/dive-packages"
DiveIconNodeScript = "services/jvm/icon/src/node-setup/start_icon_node.star"
DiveIconDecentraliseScript = "services/jvm/icon/src/node-setup/setup_icon_node.star"
DiveIconDecentralizeScript = "services/jvm/icon/src/node-setup/setup_icon_node.star"
DiveEthHardhatNodeScript = "services/evm/eth/src/node-setup/start-eth-node.star"
DiveArchwayNodeScript = "services/cosmvm/archway/src/node-setup/start_node.star"
DiveArchwayDefaultNodeScript = "services/cosmvm/archway/archway.star"
DiveCosmosDefaultNodeScript = "services/cosmvm/cosmos_chains.star"
DiveNeutronNodeScript = "services/cosmvm/neutron/src/node-setup/start_node.star"
RelayServiceNameIconToCosmos = "ibc-relayer"
DiveNeutronDefaultNodeScript = "services/cosmvm/neutron/neutron.star"
DiveBridgeBtpScript = "/services/bridges/btp/src/bridge.star"
DiveBridgeIbcScript = "/services/bridges/ibc/src/bridge.star"
DiveDryRun = false
DiveDefaultParallelism = 4
DiveEthNodeAlreadyRunning = "Eth Node Already Running"
DiveHardhatNodeAlreadyRuning = "Hardhat Node Already Running"
DiveIconNodeAlreadyRunning = "Icon Node Already Running"
DiveLogDirectory = "/logs/"
DiveDitLogFile = "dive.log"
DiveErrorLogFile = "error.log"
DiveOutFile = "dive_%s.json"
ServiceFilePath = "services_%s.json"
starlarkScript = `
removeServiceStarlarkScript = `
def run(plan,args):
plan.remove_service(name=args["service_name"])
`
stopServiceStarlarkScript = `
def run(plan, args):
plan.stop_service(name=args["service_name"])
plan.print(args["uuid"]) # we add this print of a random UUID to make sure the single stop_service above won't get cached
`
)

Expand Down Expand Up @@ -80,3 +77,6 @@ const (
InvalidChain
PortError
)

var DiveLogs bool
var EnclaveName string
12 changes: 0 additions & 12 deletions cli/common/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ import (
"github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context"
)

const (
removeServiceStarlarkScript = `
def run(plan,args):
plan.remove_service(name=args["service_name"])
`

stopServiceStarlarkScript = `
def run(plan, args):
plan.stop_service(name=args["service_name"])
`
)

type diveContext struct {
mu sync.Mutex
ctx context.Context
Expand Down
105 changes: 105 additions & 0 deletions cli/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,158 @@ import (
"github.com/spf13/cobra"
)

// Logger represents a generic logging interface with various log levels and formatting options.
type Logger interface {
// SetErrorToStderr configures the logger to output error messages to stderr.
SetErrorToStderr()

// SetOutputToStdout configures the logger to output messages to stdout.
SetOutputToStdout()

// Debug logs a debug message.
Debug(message string)

// Info logs an informational message.
Info(message string)

// Warn logs a warning message.
Warn(message string)

// Error logs an error with an error code and a corresponding error message.
Error(errorCode ErrorCode, errorMessage string)

// Fatal logs a fatal error with an error code and a corresponding error message,
// and then exits the program.
Fatal(errorCode ErrorCode, errorMessage string)

// Infof logs a formatted informational message.
Infof(format string, args ...interface{})

// Warnf logs a formatted warning message.
Warnf(format string, args ...interface{})

// Debugf logs a formatted debug message.
Debugf(format string, args ...interface{})

// Errorf logs a formatted error with an error code and a corresponding error message.
Errorf(errorCode ErrorCode, format string, args ...interface{})

// Fatalf logs a formatted fatal error with an error code and a corresponding error message,
// and then exits the program.
Fatalf(errorCode ErrorCode, format string, args ...interface{})
}

// Spinner is an interface for managing and controlling a terminal spinner.
type Spinner interface {
// SetSuffixMessage sets a suffix message to be displayed beside the spinner.
SetSuffixMessage(message, color string)

// SetPrefixMessage sets a prefix message to be displayed beside the spinner.
SetPrefixMessage(message string)

// SetColor sets the color of the spinner.
SetColor(color string)

// Start starts the spinner with the specified color.
Start(color string)

// StartWithMessage starts the spinner with a specified message and color.
StartWithMessage(message, color string)

// Stop stops the spinner.
Stop()

// StopWithMessage stops the spinner and displays a final message.
StopWithMessage(message string)
}

// Context represents a context for managing and interacting with enclaves and services.
type Context interface {
// GetContext returns the underlying context.Context.
GetContext() context.Context

// GetKurtosisContext returns the Kurtosis context, including configuration and utility functions.
GetKurtosisContext() (*kurtosis_context.KurtosisContext, error)

// GetEnclaves retrieves information about all enclaves currently running.
GetEnclaves() ([]EnclaveInfo, error)

// GetEnclaveContext retrieves the context of a specific enclave by its name.
GetEnclaveContext(enclaveName string) (*enclaves.EnclaveContext, error)

// CleanEnclaves stops and cleans up all running enclaves.
CleanEnclaves() ([]*EnclaveInfo, error)

// CleanEnclaveByName stops and cleans up a specific enclave by its name.
CleanEnclaveByName(enclaveName string) error

// CheckSkippedInstructions checks if specific instructions are skipped in the current kurtosis run context.
CheckSkippedInstructions(instructions map[string]bool) bool

// StopService stops a specific service within an enclave by name.
StopService(serviceName string, enclaveName string) error

// StopServices stops all services within a specific enclave.
StopServices(enclaveName string) error

// RemoveServices stops and removes all services within a specific enclave.
RemoveServices(enclaveName string) error

// RemoveService stops and removes a specific service within an enclave by name.
RemoveService(serviceName string, enclaveName string) error

// RemoveServicesByServiceNames stops and removes services within an enclave based on a map of service names.
RemoveServicesByServiceNames(services map[string]string, enclaveName string) error

// CreateEnclave creates a new enclave with the specified name and returns its context.
CreateEnclave(enclaveName string) (*enclaves.EnclaveContext, error)

// Exit terminates the execution of the context with the given status code.
Exit(statusCode int)
}

// FileHandler defines methods for handling file-related operations.
type FileHandler interface {
// ReadFile reads the contents of a file specified by the filePath.
ReadFile(filePath string) ([]byte, error)

// ReadJson reads the contents of a JSON file specified by the fileName
// and unmarshals it into the provided object (obj).
ReadJson(fileName string, obj interface{}) error

// ReadAppFile reads the contents of an application-specific file specified by the fileName.
ReadAppFile(fileName string) ([]byte, error)

// WriteFile writes the provided data to a file specified by the fileName.
WriteFile(fileName string, data []byte) error

// WriteJson writes the provided data, marshaled as JSON, to a file specified by the fileName.
WriteJson(fileName string, data interface{}) error

// WriteAppFile writes the provided data to an application-specific file specified by the fileName.
WriteAppFile(fileName string, data []byte) error

// GetPwd returns the current working directory.
GetPwd() (string, error)

// GetHomeDir returns the home directory of the user.
GetHomeDir() (string, error)

// MkdirAll creates a directory along with any necessary parents,
// and sets the specified permission.
MkdirAll(dirPath string, permission fs.FileMode) error

// OpenFile opens a file with the specified fileOpenMode and permission.
OpenFile(filePath string, fileOpenMode string, permission int) (*os.File, error)

// RemoveFile removes the file specified by the fileName.
RemoveFile(fileName string) error

// RemoveFiles removes multiple files specified by the fileNames.
RemoveFiles(fileNames []string) error

// GetAppDirPathOrAppFilePath returns the path to the application directory or a specific file within it
// based on the provided fileName.
GetAppDirPathOrAppFilePath(fileName string) (string, error)
}

Expand Down Expand Up @@ -111,10 +208,18 @@ type CommandBuilder interface {
// SetRun sets the Run field of the command.
SetRun(run func(cmd *cobra.Command, args []string)) CommandBuilder

// ToggleHelpCommand enables or disables the automatic generation of a help command.
ToggleHelpCommand(enable bool) CommandBuilder

// SetRunE sets the RunE field of the command.
SetRunE(run func(cmd *cobra.Command, args []string) error) CommandBuilder

// MarkFlagsAsRequired marks multiple flags as required for the command.
MarkFlagsAsRequired(flags []string) CommandBuilder

// MarkFlagRequired marks a flag as required for the command.
MarkFlagRequired(flag string) CommandBuilder

// AddBoolFlagP adds a boolean flag with shorthand to the command.
AddBoolFlagP(name string, shorthand string, value bool, usage string) CommandBuilder
}
Loading

0 comments on commit be06c12

Please sign in to comment.