github.com/MetalBlockchain/metalgo@v1.11.9/tests/antithesis/xsvm/gencomposeconfig/main.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"log"
     9  	"os"
    10  
    11  	"github.com/MetalBlockchain/metalgo/genesis"
    12  	"github.com/MetalBlockchain/metalgo/tests/antithesis"
    13  	"github.com/MetalBlockchain/metalgo/tests/fixture/subnet"
    14  	"github.com/MetalBlockchain/metalgo/tests/fixture/tmpnet"
    15  )
    16  
    17  const baseImageName = "antithesis-xsvm"
    18  
    19  // Creates docker-compose.yml and its associated volumes in the target path.
    20  func main() {
    21  	avalancheGoPath := os.Getenv("AVALANCHEGO_PATH")
    22  	if len(avalancheGoPath) == 0 {
    23  		log.Fatal("AVALANCHEGO_PATH environment variable not set")
    24  	}
    25  
    26  	pluginDir := os.Getenv("AVALANCHEGO_PLUGIN_DIR")
    27  	if len(pluginDir) == 0 {
    28  		log.Fatal("AVALANCHEGO_PLUGIN_DIR environment variable not set")
    29  	}
    30  
    31  	targetPath := os.Getenv("TARGET_PATH")
    32  	if len(targetPath) == 0 {
    33  		log.Fatal("TARGET_PATH environment variable not set")
    34  	}
    35  
    36  	imageTag := os.Getenv("IMAGE_TAG")
    37  	if len(imageTag) == 0 {
    38  		log.Fatal("IMAGE_TAG environment variable not set")
    39  	}
    40  
    41  	nodeImageName := fmt.Sprintf("%s-node:%s", baseImageName, imageTag)
    42  	workloadImageName := fmt.Sprintf("%s-workload:%s", baseImageName, imageTag)
    43  
    44  	// Create a network with an xsvm subnet
    45  	network := tmpnet.LocalNetworkOrPanic()
    46  	network.Subnets = []*tmpnet.Subnet{
    47  		subnet.NewXSVMOrPanic("xsvm", genesis.VMRQKey, network.Nodes...),
    48  	}
    49  
    50  	bootstrapVolumePath, err := antithesis.GetBootstrapVolumePath(targetPath)
    51  	if err != nil {
    52  		log.Fatalf("failed to get bootstrap volume path: %v", err)
    53  	}
    54  
    55  	if err := antithesis.InitBootstrapDB(network, avalancheGoPath, pluginDir, bootstrapVolumePath); err != nil {
    56  		log.Fatalf("failed to initialize db volumes: %v", err)
    57  	}
    58  
    59  	if err := antithesis.GenerateComposeConfig(network, nodeImageName, workloadImageName, targetPath); err != nil {
    60  		log.Fatalf("failed to generate config for docker-compose: %v", err)
    61  	}
    62  }