Skip to content

Commit

Permalink
fixup: Explicitly pass a runtime plugin dir
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Aug 19, 2024
1 parent bb508a6 commit e490875
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tests/antithesis/avalanchego/gencomposeconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const baseImageName = "antithesis-avalanchego"
// Creates docker-compose.yml and its associated volumes in the target path.
func main() {
network := tmpnet.LocalNetworkOrPanic()
if err := antithesis.GenerateComposeConfig(network, baseImageName); err != nil {
if err := antithesis.GenerateComposeConfig(network, baseImageName, "" /* runtimePluginDir */); err != nil {
log.Fatalf("failed to generate compose config: %v", err)
}
}
40 changes: 10 additions & 30 deletions tests/antithesis/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ var (
errPluginDirEnvVarNotSet = errors.New("AVALANCHEGO_PLUGIN_DIR environment variable not set")
)

// Creates docker compose configuration for an antithesis test
// setup. Configuration is via env vars to simplify usage by main entrypoints. If
// the provided network includes a subnet, the initial DB state for the subnet
// will be created and written to the target path.
func GenerateComposeConfig(network *tmpnet.Network, baseImageName string) error {
// Creates docker compose configuration for an antithesis test setup. Configuration is via env vars to
// simplify usage by main entrypoints. If the provided network includes a subnet, the initial DB state for
// the subnet will be created and written to the target path. The runtimePluginDir should be set if the node
// image used for the test setup uses a path other than the default (~/.avalanchego/plugins).
func GenerateComposeConfig(network *tmpnet.Network, baseImageName string, runtimePluginDir string) error {
targetPath := os.Getenv("TARGET_PATH")
if len(targetPath) == 0 {
return errTargetPathEnvVarNotSet
Expand All @@ -51,6 +51,7 @@ func GenerateComposeConfig(network *tmpnet.Network, baseImageName string) error
return errAvalancheGoEvVarNotSet
}

// Plugin dir configured here is only used for initializing the bootstrap db.
pluginDir := os.Getenv(tmpnet.AvalancheGoPluginDirEnvName)
if len(pluginDir) == 0 {
return errPluginDirEnvVarNotSet
Expand All @@ -61,33 +62,15 @@ func GenerateComposeConfig(network *tmpnet.Network, baseImageName string) error
return fmt.Errorf("failed to get bootstrap volume path: %w", err)
}

// Save the plugin dir for use with compose configuration and remove it from flags so pluginDir can
// be used for the db-initialization bootstrap.
//
// TODO(marun) Separate bootstrap configuration from runtime configuration to avoid having to do this
pluginDirForCompose, err := network.GetPluginDir()
if err != nil {
return fmt.Errorf("failed to get plugin dir: %w", err)
}
delete(network.DefaultFlags, config.PluginDirKey)

if err := initBootstrapDB(network, avalancheGoPath, pluginDir, bootstrapVolumePath); err != nil {
return fmt.Errorf("failed to initialize db volumes: %w", err)
}

if len(pluginDirForCompose) > 0 {
// Restore the plugin dir
network.DefaultFlags[config.PluginDirKey] = pluginDirForCompose
} else {
// Ensure the plugin dir is not provided so that the default is used
delete(network.DefaultFlags, config.PluginDirKey)
}
}

nodeImageName := fmt.Sprintf("%s-node:%s", baseImageName, imageTag)
workloadImageName := fmt.Sprintf("%s-workload:%s", baseImageName, imageTag)

if err := initComposeConfig(network, nodeImageName, workloadImageName, targetPath); err != nil {
if err := initComposeConfig(network, nodeImageName, workloadImageName, targetPath, runtimePluginDir); err != nil {
return fmt.Errorf("failed to generate compose config: %w", err)
}

Expand All @@ -101,9 +84,10 @@ func initComposeConfig(
nodeImageName string,
workloadImageName string,
targetPath string,
pluginDir string,
) error {
// Generate a compose project for the specified network
project, err := newComposeProject(network, nodeImageName, workloadImageName)
project, err := newComposeProject(network, nodeImageName, workloadImageName, pluginDir)
if err != nil {
return fmt.Errorf("failed to create compose project: %w", err)
}
Expand Down Expand Up @@ -141,7 +125,7 @@ func initComposeConfig(

// Create a new docker compose project for an antithesis test setup
// for the provided network configuration.
func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadImageName string) (*types.Project, error) {
func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadImageName string, pluginDir string) (*types.Project, error) {
networkName := "avalanche-testnet"
baseNetworkAddress := "10.0.20"

Expand Down Expand Up @@ -179,10 +163,6 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm
}

// Set a non-default plugin dir if provided
pluginDir, err := network.GetPluginDir()
if err != nil {
return nil, err
}
if len(pluginDir) > 0 {
env[config.PluginDirKey] = pluginDir
}
Expand Down
2 changes: 1 addition & 1 deletion tests/antithesis/xsvm/gencomposeconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
network.Subnets = []*tmpnet.Subnet{
subnet.NewXSVMOrPanic("xsvm", genesis.VMRQKey, network.Nodes...),
}
if err := antithesis.GenerateComposeConfig(network, baseImageName); err != nil {
if err := antithesis.GenerateComposeConfig(network, baseImageName, "" /* runtimePluginDir */); err != nil {
log.Fatalf("failed to generate compose config: %v", err)
}
}

0 comments on commit e490875

Please sign in to comment.