Skip to content

Commit

Permalink
Merge pull request #74 from ava-labs/hostexample
Browse files Browse the repository at this point in the history
AWS example
  • Loading branch information
arturrez authored Jun 26, 2024
2 parents 0f88235 + ea669cc commit 57466d2
Show file tree
Hide file tree
Showing 51 changed files with 20,619 additions and 42 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
Copyright (C) 2024, Ava Labs, Inc. All rights reserved.

Ecosystem License
Version: 1.1
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.header
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
See the file LICENSE for licensing terms.
Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
See the file LICENSE for licensing terms.
2 changes: 1 addition & 1 deletion cloud/aws/aws.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package aws
Expand Down
4 changes: 2 additions & 2 deletions cloud/gcp/gcp.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package gcp
Expand Down Expand Up @@ -319,7 +319,7 @@ func (c *GcpCloud) SetupInstances(
return instances, nil
}

// // Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// // Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
// // See the file LICENSE for licensing terms.

func (c *GcpCloud) GetUbuntuimageID() (string, error) {
Expand Down
20 changes: 19 additions & 1 deletion constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package constants

Expand Down Expand Up @@ -34,6 +34,7 @@ const (
AvalanchegoLokiPort = 23101
AvalanchegoMonitoringPort = 9090
AvalanchegoMachineMetricsPort = 9100
AvalanchegoLoadTestPort = 8082

// ssh
SSHSleepBetweenChecks = 1 * time.Second
Expand All @@ -49,6 +50,16 @@ const (
CloudNodeSubnetEvmBinaryPath = "/home/ubuntu/.avalanchego/plugins/%s"
CloudNodeStakingPath = "/home/ubuntu/.avalanchego/staking/"
CloudNodeConfigPath = "/home/ubuntu/.avalanchego/configs/"
ServicesDir = "services"
DashboardsDir = "dashboards"

// services
ServiceAvalanchego = "avalanchego"
ServicePromtail = "promtail"
ServiceGrafana = "grafana"
ServicePrometheus = "prometheus"
ServiceLoki = "loki"
ServiceAWMRelayer = "awm-relayer"

// misc
DefaultPerms755 = 0o755
Expand All @@ -61,4 +72,11 @@ const (
AvalancheGoDockerImage = "avaplatform/avalanchego"
AvalancheGoGitRepo = "https://github.com/ava-labs/avalanchego"
SubnetEVMRepoName = "subnet-evm"

AWMRelayerInstallDir = "awm-relayer"
AWMRelayerConfigFilename = "awm-relayer-config.json"

StakerCertFileName = "staker.crt"
StakerKeyFileName = "staker.key"
BLSKeyFileName = "signer.key"
)
87 changes: 87 additions & 0 deletions examples/aws.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package examples

import (
"context"
"fmt"
"time"

"github.com/ava-labs/avalanche-tooling-sdk-go/avalanche"
"github.com/ava-labs/avalanche-tooling-sdk-go/node"
)

func main() {
ctx := context.Background()
// Get the default cloud parameters for AWS
cp, err := node.GetDefaultCloudParams(ctx, node.AWSCloud)
// Set the cloud parameters for AWS non provided by the default
// Please set your own values for the following fields
cp.AWSConfig.AWSProfile = "default"
cp.AWSConfig.AWSSecurityGroupID = "sg-0e198c427f8f0616b"
cp.AWSConfig.AWSKeyPair = "artur-us-east-1-avalanche-cli"
if err != nil {
panic(err)
}
// Create a new host instance. Count is 1 so only one host will be created
const (
avalanchegoVersion = "v1.11.8"
avalancheCliVersion = "v1.6.2"
)
hosts, err := node.CreateNodes(ctx,
&node.NodeParams{
CloudParams: cp,
Count: 2,
Roles: []node.SupportedRole{node.Validator},
Network: avalanche.FujiNetwork(),
AvalancheGoVersion: avalanchegoVersion,
AvalancheCliVersion: avalancheCliVersion,
UseStaticIP: false,
})
if err != nil {
panic(err)
}

const (
sshTimeout = 120 * time.Second
sshCommandTimeout = 10 * time.Second
)
for _, h := range hosts {
// Wait for the host to be ready
fmt.Println("Waiting for SSH shell")
if err := h.WaitForSSHShell(sshTimeout); err != nil {
panic(err)
}
fmt.Println("SSH shell ready to execute commands")
// Run a command on the host
if output, err := h.Commandf(nil, sshCommandTimeout, "echo 'Hello, %s!'", "World"); err != nil {
panic(err)
} else {
fmt.Println(string(output))
}
// sleep for 10 seconds allowing AvalancheGo container to start
time.Sleep(10 * time.Second)
// check if avalanchego is running
if output, err := h.Commandf(nil, sshCommandTimeout, "docker ps"); err != nil {
panic(err)
} else {
fmt.Println(string(output))
}
}
// Create a monitoring node
monitoringHosts, err := node.CreateNodes(ctx,
&node.NodeParams{
CloudParams: cp,
Count: 1,
Roles: []node.SupportedRole{node.Monitor},
UseStaticIP: false,
})
if err != nil {
panic(err)
}
// Register nodes with monitoring host
if err := monitoringHosts[0].MonitorNodes(hosts, ""); err != nil {
panic(err)
}
}
2 changes: 1 addition & 1 deletion node/config/avalanche.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package services

import (
"bytes"
"html/template"
"path/filepath"
"text/template"

"github.com/ava-labs/avalanche-tooling-sdk-go/constants"
)
Expand Down
13 changes: 8 additions & 5 deletions node/config/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

package services

import "github.com/ava-labs/avalanche-tooling-sdk-go/utils"
import (
"github.com/ava-labs/avalanche-tooling-sdk-go/constants"
"github.com/ava-labs/avalanche-tooling-sdk-go/utils"
)

func RenderGrafanaLokiDataSourceConfig() ([]byte, error) {
return templates.ReadFile("templates/grafana-loki-datasource.yaml")
Expand All @@ -23,9 +26,9 @@ func RenderGrafanaDashboardConfig() ([]byte, error) {

func GrafanaFoldersToCreate() []string {
return []string{
utils.GetRemoteComposeServicePath("grafana", "data"),
utils.GetRemoteComposeServicePath("grafana", "dashboards"),
utils.GetRemoteComposeServicePath("grafana", "provisioning", "datasources"),
utils.GetRemoteComposeServicePath("grafana", "provisioning", "dashboards"),
utils.GetRemoteComposeServicePath(constants.ServiceGrafana, "data"),
utils.GetRemoteComposeServicePath(constants.ServiceGrafana, "dashboards"),
utils.GetRemoteComposeServicePath(constants.ServiceGrafana, "provisioning", "datasources"),
utils.GetRemoteComposeServicePath(constants.ServiceGrafana, "provisioning", "dashboards"),
}
}
3 changes: 2 additions & 1 deletion node/config/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
package services

import (
"github.com/ava-labs/avalanche-tooling-sdk-go/constants"
"github.com/ava-labs/avalanche-tooling-sdk-go/utils"
)

func LokiFoldersToCreate() []string {
return []string{utils.GetRemoteComposeServicePath("loki", "data")}
return []string{utils.GetRemoteComposeServicePath(constants.ServiceLoki, "data")}
}
5 changes: 3 additions & 2 deletions node/config/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
package services

import (
"github.com/ava-labs/avalanche-tooling-sdk-go/constants"
"github.com/ava-labs/avalanche-tooling-sdk-go/utils"
)

func PrometheusFoldersToCreate() []string {
return []string{
utils.GetRemoteComposeServicePath("prometheus"),
utils.GetRemoteComposeServicePath("prometheus", "data"),
utils.GetRemoteComposeServicePath(constants.ServicePrometheus),
utils.GetRemoteComposeServicePath(constants.ServicePrometheus, "data"),
}
}
7 changes: 5 additions & 2 deletions node/config/promtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

package services

import "github.com/ava-labs/avalanche-tooling-sdk-go/utils"
import (
"github.com/ava-labs/avalanche-tooling-sdk-go/constants"
"github.com/ava-labs/avalanche-tooling-sdk-go/utils"
)

func PromtailFoldersToCreate() []string {
return []string{
utils.GetRemoteComposeServicePath("promtail"),
utils.GetRemoteComposeServicePath(constants.ServicePromtail),
"/home/ubuntu/.avalanchego/logs",
}
}
Loading

0 comments on commit 57466d2

Please sign in to comment.