diff --git a/.github/workflows/docker-schedule.yml b/.github/workflows/docker-schedule.yml index 60a1081..4c3fb48 100644 --- a/.github/workflows/docker-schedule.yml +++ b/.github/workflows/docker-schedule.yml @@ -64,7 +64,7 @@ jobs: build-args: | BASE_ALGORAND_VERSION=3.25.0-stable push: true - tags: ghcr.io/voinetwork/docker-relay-node:latest + tags: ghcr.io/voinetwork/voi-node:latest labels: | ${{ steps.meta.outputs.labels }} org.opencontainers.image.version=latest diff --git a/README.md b/README.md index 67a4a6a..dbc9ee0 100644 --- a/README.md +++ b/README.md @@ -1 +1,36 @@ -# DO NOT USE - BREAKAGE EXPECTED AT ANY POINT IN TIME +# Voi Node + +This project contains a simple Docker image and associated golang tooling to +run a Voi node. + +## Node types currently supported +- Relay node +- Archiver node + +Node type will default to 'relay' if not specified. +Node configuration will use testnet defaults unless otherwise provided at image build time. + +## Running with a pre-defined network +To run a Voi node with a pre-defined network, you can use the following command: + +```bash +docker run -e VOINETWORK_NETWORK=testnet ghcr.io/voi-network/voi-node:latest +``` + +## Running with a custom network + +```bash +docker run -e VOINETWORK_NETWORK=custom_name -e VOINETWORK_GENESIS=custom_url ghcr.io/voi-network/voi-node:latest +``` + +## Running with a specific profile + +### Relay node +```bash +docker run -e VOINETWORK_NETWORK=custom_name -e VOINETWORK_GENESIS=custom_url -e VOINETWORK_PROFILE=relay ghcr.io/voi-network/voi-node:latest +``` + +### Archiver node +```bash +docker run -e VOINETWORK_NETWORK=custom_name -e VOINETWORK_GENESIS=custom_url -e VOINETWORK_PROFILE=archiver ghcr.io/voi-network/voi-node:latest +``` \ No newline at end of file diff --git a/go.mod b/go.mod index a47d9dd..66881b8 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/voinetwork/docker-relay-node +module github.com/voinetwork/voi-node go 1.22 diff --git a/tools/algodhealth/algodhealth.go b/tools/algodhealth/algodhealth.go index d855a45..e69da55 100644 --- a/tools/algodhealth/algodhealth.go +++ b/tools/algodhealth/algodhealth.go @@ -1,7 +1,7 @@ package main import ( - "github.com/voinetwork/docker-relay-node/tools/utils" + "github.com/voinetwork/voi-node/tools/utils" "log" "net/http" "os" diff --git a/tools/catch-catchpoint/catch-catchpoint.go b/tools/catch-catchpoint/catch-catchpoint.go index a6da64a..a1d59f2 100644 --- a/tools/catch-catchpoint/catch-catchpoint.go +++ b/tools/catch-catchpoint/catch-catchpoint.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "flag" - "github.com/voinetwork/docker-relay-node/tools/utils" + "github.com/voinetwork/voi-node/tools/utils" "io" "log" "math" diff --git a/tools/get-metrics/get-metrics.go b/tools/get-metrics/get-metrics.go index b416ba5..e29bf7d 100644 --- a/tools/get-metrics/get-metrics.go +++ b/tools/get-metrics/get-metrics.go @@ -2,7 +2,7 @@ package main import ( "flag" - "github.com/voinetwork/docker-relay-node/tools/utils" + "github.com/voinetwork/voi-node/tools/utils" "log" "net/http" "os" diff --git a/tools/start-metrics/start-metrics.go b/tools/start-metrics/start-metrics.go index 8c82757..6499018 100644 --- a/tools/start-metrics/start-metrics.go +++ b/tools/start-metrics/start-metrics.go @@ -1,7 +1,7 @@ package main import ( - "github.com/voinetwork/docker-relay-node/tools/utils" + "github.com/voinetwork/voi-node/tools/utils" "log" "net" "time" diff --git a/tools/start-node/start-node.go b/tools/start-node/start-node.go index e32a2b8..ee33543 100644 --- a/tools/start-node/start-node.go +++ b/tools/start-node/start-node.go @@ -3,9 +3,8 @@ package main import ( "flag" "fmt" - "github.com/voinetwork/docker-relay-node/tools/utils" + "github.com/voinetwork/voi-node/tools/utils" "log" - "net" "os" "time" ) @@ -29,6 +28,29 @@ func init() { flag.BoolVar(&overwriteConfig, "overwrite-config", true, "Specify whether to overwrite the configuration files (true, false)") } +func handleConfiguration(urlSet bool, genesisURL, network, profile string, overwriteConfig bool, genesisJSONPathFmt, configJSONPathFmt, algodDataDir string) { + fu := utils.FileUtils{} + nu := utils.NetworkUtils{} + + if urlSet { + log.Printf("Using genesis and configuration URLs from environment variables: %s", genesisURL) + if err := nu.DownloadNetworkConfiguration(genesisURL, algodDataDir); err != nil { + fmt.Printf("Failed to download network configuration: %v", err) + os.Exit(1) + } + } else { + if err := fu.CopyGenesisConfigurationFromFilesystem(network, profile, overwriteConfig, genesisJSONPathFmt, algodDataDir); err != nil { + fmt.Printf("Failed to copy network configuration: %v", err) + os.Exit(1) + } + } + + if err := fu.CopyAlgodConfigurationFromFilesystem(network, profile, overwriteConfig, configJSONPathFmt, algodDataDir); err != nil { + fmt.Printf("Failed to copy network configuration: %v", err) + os.Exit(1) + } +} + func main() { flag.Parse() @@ -40,48 +62,18 @@ func main() { network = envNetwork } - interfaces, err := net.Interfaces() - if err != nil { - fmt.Print(err) - return - } + genesisURL, urlSet := nu.GetGenesisFromEnv() - for _, i := range interfaces { - addrs, err := i.Addrs() - if err != nil { - fmt.Print(err) - continue - } - - for _, addr := range addrs { - fmt.Printf("Interface Name: %v, IP Address: %v\n", i.Name, addr.String()) - } + envProfile, profileSet := nu.GetProfileFromEnv() + if profileSet { + profile = envProfile } - // Copy configuration for the network - genesisURL, configURL, urlSet := nu.GetGenesisAndConfigurationFromEnv() - log.Printf("Network: %s", network) - if !urlSet { - log.Printf("Profile: %s", profile) - } + log.Printf("Profile: %s", profile) log.Printf("Overwrite Config: %t", overwriteConfig) - if urlSet { - log.Printf("Using genesis and configuration URLs from environment variables: %s, %s", genesisURL, configURL) - err := nu.DownloadNetworkConfiguration(genesisURL, configURL, algodDataDir) - if err != nil { - fmt.Printf("Failed to download network configuration: %v", err) - os.Exit(1) - } - } else { - fu := utils.FileUtils{} - err := fu.CopyNetworkConfigurationFromFilesystem(network, profile, overwriteConfig, genesisJSONPathFmt, configJSONPathFmt, algodDataDir) - if err != nil { - fmt.Printf("Failed to copy network configuration: %v", err) - os.Exit(1) - } - } + handleConfiguration(urlSet, genesisURL, network, profile, overwriteConfig, genesisJSONPathFmt, configJSONPathFmt, algodDataDir) pu := utils.ProcessUtils{} diff --git a/tools/utils/file_utils.go b/tools/utils/file_utils.go index b314982..7b940eb 100644 --- a/tools/utils/file_utils.go +++ b/tools/utils/file_utils.go @@ -65,15 +65,23 @@ func (fu FileUtils) WriteToFile(filePath string, data io.Reader, statusCode int) return nil } -func (fu FileUtils) CopyNetworkConfigurationFromFilesystem(network string, profile string, overWriteConfig bool, genesisJSONPathFmt string, configJSONPathFmt string, algodDataDir string) error { - err := fu.CopyFile(fmt.Sprintf(genesisJSONPathFmt, network), algodDataDir+"/genesis.json", overWriteConfig) - if err != nil { - return fmt.Errorf("failed to copy genesis.json: %v", err) +func (fu FileUtils) CopyAlgodConfigurationFromFilesystem(network string, profile string, overWriteConfig bool, configJSONPathFmt string, algodDataDir string) error { + nu := NetworkUtils{} + if !nu.CheckIfPredefinedNetwork(network) { + network = "testnet" } - err = fu.CopyFile(fmt.Sprintf(configJSONPathFmt, network, profile), algodDataDir+"/config.json", overWriteConfig) + err := fu.CopyFile(fmt.Sprintf(configJSONPathFmt, network, profile), algodDataDir+"/config.json", overWriteConfig) if err != nil { return fmt.Errorf("failed to copy config.json: %v", err) } return nil } + +func (fu FileUtils) CopyGenesisConfigurationFromFilesystem(network string, profile string, overWriteConfig bool, genesisJSONPathFmt string, algodDataDir string) error { + err := fu.CopyFile(fmt.Sprintf(genesisJSONPathFmt, network), algodDataDir+"/genesis.json", overWriteConfig) + if err != nil { + return fmt.Errorf("failed to copy genesis.json: %v", err) + } + return nil +} diff --git a/tools/utils/network_utils.go b/tools/utils/network_utils.go index da0f5d8..6b770e4 100644 --- a/tools/utils/network_utils.go +++ b/tools/utils/network_utils.go @@ -10,10 +10,10 @@ import ( ) const ( - testNet = "testnet" - envNetworkVar = "VOINETWORK_NETWORK" - envGenesisURLVar = "VOINETWORK_GENESIS" - envConfigurationURLVar = "VOINETWORK_CONFIGURATION" + testNet = "testnet" + envNetworkVar = "VOINETWORK_NETWORK" + envGenesisURLVar = "VOINETWORK_GENESIS" + envProfileVar = "VOINETWORK_PROFILE" ) type NetworkUtils struct{} @@ -27,6 +27,15 @@ func (nu NetworkUtils) GetStatusURL(network string) (string, error) { } } +func (nu NetworkUtils) CheckIfPredefinedNetwork(network string) bool { + switch network { + case testNet: + return true + default: + return false + } +} + func (nu NetworkUtils) GetEnvNetworkVar() string { return envNetworkVar } @@ -40,24 +49,32 @@ func (nu NetworkUtils) GetNetworkFromEnv() (string, bool) { return "", false } -func (nu NetworkUtils) GetGenesisAndConfigurationFromEnv() (string, string, bool) { +func (nu NetworkUtils) GetEnvProfileVar() string { + return envProfileVar +} + +func (nu NetworkUtils) GetProfileFromEnv() (string, bool) { + profile := os.Getenv(envProfileVar) + if profile != "" { + log.Printf("Using profile from environment variable: %s", profile) + return profile, true + } + return "", false +} + +func (nu NetworkUtils) GetGenesisFromEnv() (string, bool) { genesisURL := os.Getenv(envGenesisURLVar) - configurationURL := os.Getenv(envConfigurationURLVar) - if genesisURL != "" && configurationURL != "" { - return genesisURL, configurationURL, true + if genesisURL != "" { + return genesisURL, true } - return "", "", false + return "", false } -func (nu NetworkUtils) DownloadNetworkConfiguration(genesisURL, configURL string, algodDataDir string) error { +func (nu NetworkUtils) DownloadNetworkConfiguration(genesisURL, algodDataDir string) error { if err := downloadFile(genesisURL, filepath.Join(algodDataDir, "genesis.json")); err != nil { return fmt.Errorf("failed to download genesis.json: %w", err) } - if err := downloadFile(configURL, filepath.Join(algodDataDir, "config.json")); err != nil { - return fmt.Errorf("failed to download config.json: %w", err) - } - return nil }