Skip to content

Commit

Permalink
Initial commit after move to voi-node
Browse files Browse the repository at this point in the history
  • Loading branch information
hsoerensen committed Jul 23, 2024
1 parent d694b7a commit 4fa611b
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/voinetwork/docker-relay-node
module github.com/voinetwork/voi-node

go 1.22
2 changes: 1 addition & 1 deletion tools/algodhealth/algodhealth.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tools/catch-catchpoint/catch-catchpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tools/get-metrics/get-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tools/start-metrics/start-metrics.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
68 changes: 30 additions & 38 deletions tools/start-node/start-node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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()

Expand All @@ -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{}

Expand Down
18 changes: 13 additions & 5 deletions tools/utils/file_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
45 changes: 31 additions & 14 deletions tools/utils/network_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
}
Expand All @@ -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
}

Expand Down

0 comments on commit 4fa611b

Please sign in to comment.