From 479dccc9d09d7a47dcdf4fa0975d769f1af07da2 Mon Sep 17 00:00:00 2001 From: Maru Newby Date: Wed, 15 Jan 2025 22:21:13 -0800 Subject: [PATCH] Update docker images to use /avalanchego/build/plugins for plugins --- Dockerfile | 7 +++++-- config/flags.go | 8 ++++++++ .../avalanchego/gencomposeconfig/main.go | 2 +- tests/antithesis/compose.go | 19 +++++++------------ tests/antithesis/xsvm/Dockerfile.node | 3 +-- .../antithesis/xsvm/gencomposeconfig/main.go | 2 +- vms/example/xsvm/Dockerfile | 5 ++--- 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5a6b58f9c194..4419c003f74b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,8 +46,11 @@ RUN . ./build_env.sh && \ ./scripts/${BUILD_SCRIPT} ${RACE_FLAG} # Create this directory in the builder to avoid requiring anything to be executed in the -# potentially emulated execution container. -RUN mkdir -p /avalanchego/build +# potentially emulated execution container. The goals are to create both +# /avalanchego/build (for the avalanchego binary) and /avalanchego/build/plugins (to +# allow consistent configuration of the plugin dir across the base image and VM images +# based on it). +RUN mkdir -p /avalanchego/build/plugins # ============= Cleanup Stage ================ # Commands executed in this stage may be emulated (i.e. very slow) if TARGETPLATFORM and diff --git a/config/flags.go b/config/flags.go index f49ca21a1cbf..f376c0d52f61 100644 --- a/config/flags.go +++ b/config/flags.go @@ -36,6 +36,14 @@ const ( defaultUnexpandedDataDir = "$" + AvalancheGoDataDirVar DefaultProcessContextFilename = "process.json" + + // The default plugin path of $HOME/.avalanchego/plugins is not + // suitable for docker images since $HOME might be writable but + // the plugin directory should not be. The value below is in the + // same hierarchy as avalanchego on the docker image + // (/avalanchego/build/avalanchego) and consistent with the + // location already used by subnet-evm. + DefaultImagePluginDir = "/avalanchego/build/plugins" ) var ( diff --git a/tests/antithesis/avalanchego/gencomposeconfig/main.go b/tests/antithesis/avalanchego/gencomposeconfig/main.go index dcdd6e8c63c2..fd1b46bffba9 100644 --- a/tests/antithesis/avalanchego/gencomposeconfig/main.go +++ b/tests/antithesis/avalanchego/gencomposeconfig/main.go @@ -18,7 +18,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, "" /* runtimePluginDir */); err != nil { + if err := antithesis.GenerateComposeConfig(network, baseImageName); err != nil { tests.NewDefaultLogger("").Fatal("failed to generate compose config", zap.Error(err), ) diff --git a/tests/antithesis/compose.go b/tests/antithesis/compose.go index b1f00fa6cbe1..ed80b2e32649 100644 --- a/tests/antithesis/compose.go +++ b/tests/antithesis/compose.go @@ -31,9 +31,8 @@ var ( // 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 { +// the subnet will be created and written to the target path. +func GenerateComposeConfig(network *tmpnet.Network, baseImageName string) error { targetPath := os.Getenv("TARGET_PATH") if len(targetPath) == 0 { return errTargetPathEnvVarNotSet @@ -70,7 +69,7 @@ func GenerateComposeConfig(network *tmpnet.Network, baseImageName string, runtim nodeImageName := fmt.Sprintf("%s-node:%s", baseImageName, imageTag) workloadImageName := fmt.Sprintf("%s-workload:%s", baseImageName, imageTag) - if err := initComposeConfig(network, nodeImageName, workloadImageName, targetPath, runtimePluginDir); err != nil { + if err := initComposeConfig(network, nodeImageName, workloadImageName, targetPath); err != nil { return fmt.Errorf("failed to generate compose config: %w", err) } @@ -84,10 +83,9 @@ 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, pluginDir) + project, err := newComposeProject(network, nodeImageName, workloadImageName) if err != nil { return fmt.Errorf("failed to create compose project: %w", err) } @@ -125,7 +123,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, pluginDir string) (*types.Project, error) { +func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadImageName string) (*types.Project, error) { networkName := "avalanche-testnet" baseNetworkAddress := "10.0.20" @@ -161,11 +159,8 @@ func newComposeProject(network *tmpnet.Network, nodeImageName string, workloadIm config.StakingTLSKeyContentKey: tlsKey, config.StakingCertContentKey: tlsCert, config.StakingSignerKeyContentKey: signerKey, - } - - // Set a non-default plugin dir if provided - if len(pluginDir) > 0 { - env[config.PluginDirKey] = pluginDir + // VM images are expected to put their plugins in the default dir + config.PluginDirKey: config.DefaultImagePluginDir, } // Apply configuration appropriate to a test network diff --git a/tests/antithesis/xsvm/Dockerfile.node b/tests/antithesis/xsvm/Dockerfile.node index 8775ac77994a..f8889f1e1a60 100644 --- a/tests/antithesis/xsvm/Dockerfile.node +++ b/tests/antithesis/xsvm/Dockerfile.node @@ -24,8 +24,7 @@ FROM $AVALANCHEGO_NODE_IMAGE AS execution ARG BUILDER_WORKDIR # Copy the executable into the container -RUN mkdir -p /root/.avalanchego/plugins COPY --from=builder $BUILDER_WORKDIR/build/xsvm \ - /root/.avalanchego/plugins/v3m4wPxaHpvGr8qfMeyK6PRW3idZrPHmYcMTt7oXdK47yurVH + /avalanchego/build/plugins/v3m4wPxaHpvGr8qfMeyK6PRW3idZrPHmYcMTt7oXdK47yurVH # The node image's entrypoint will be reused. diff --git a/tests/antithesis/xsvm/gencomposeconfig/main.go b/tests/antithesis/xsvm/gencomposeconfig/main.go index b292cf89cefb..bcf582a7c9dd 100644 --- a/tests/antithesis/xsvm/gencomposeconfig/main.go +++ b/tests/antithesis/xsvm/gencomposeconfig/main.go @@ -23,7 +23,7 @@ func main() { network.Subnets = []*tmpnet.Subnet{ subnet.NewXSVMOrPanic("xsvm", genesis.VMRQKey, network.Nodes...), } - if err := antithesis.GenerateComposeConfig(network, baseImageName, "" /* runtimePluginDir */); err != nil { + if err := antithesis.GenerateComposeConfig(network, baseImageName); err != nil { tests.NewDefaultLogger("").Fatal("failed to generate compose config", zap.Error(err), ) diff --git a/vms/example/xsvm/Dockerfile b/vms/example/xsvm/Dockerfile index 8e7c4c5bba9f..1e8078ede3ac 100644 --- a/vms/example/xsvm/Dockerfile +++ b/vms/example/xsvm/Dockerfile @@ -24,8 +24,7 @@ RUN ./scripts/build_xsvm.sh # ============= Cleanup Stage ================ FROM $AVALANCHEGO_NODE_IMAGE AS execution -# Copy the xsvm binary to the default plugin path -RUN mkdir -p /root/.avalanchego/plugins -COPY --from=builder /build/build/xsvm /root/.avalanchego/plugins/v3m4wPxaHpvGr8qfMeyK6PRW3idZrPHmYcMTt7oXdK47yurVH +# Copy the xsvm binary to the default plugin dir for images +COPY --from=builder /build/build/xsvm /avalanchego/build/plugins/v3m4wPxaHpvGr8qfMeyK6PRW3idZrPHmYcMTt7oXdK47yurVH # The node image's entrypoint will be reused.