Skip to content

Commit

Permalink
Update docker images to use /avalanchego/build/plugins for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Jan 16, 2025
1 parent e973af8 commit 479dccc
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion tests/antithesis/avalanchego/gencomposeconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
19 changes: 7 additions & 12 deletions tests/antithesis/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/antithesis/xsvm/Dockerfile.node
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion tests/antithesis/xsvm/gencomposeconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
5 changes: 2 additions & 3 deletions vms/example/xsvm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 479dccc

Please sign in to comment.