Skip to content

Commit

Permalink
rebase and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sugh01 committed Sep 18, 2024
2 parents 1b861b4 + 000cc79 commit 6099dca
Show file tree
Hide file tree
Showing 97 changed files with 36,186 additions and 972 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
matrix:
include:
- os: ubuntu-latest
go: '1.21'
go: '1.22'
- os: macos-latest
go: '1.21'
go: '1.22'
- os: windows-latest
go: '1.21'
go: '1.22'
runs-on: ${{ matrix.os }}

steps:
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
matrix:
include:
- os: ubuntu-latest
go: '1.21'
go: '1.22'
- os: windows-latest
go: '1.21'
go: '1.22'
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -29,6 +29,11 @@ jobs:

- name: Install deps
run: make install-deps

- name: Run e2e tests

- name: Run e2e tests Windows
if: runner.os == 'Windows'
run: make e2e-test-windows

- name: Run e2e tests other
if: runner.os != 'Windows'
run: make e2e-test
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
go-version: "1.22.0"

- run: chmod +x ./scripts/build-go-darwin-binaries.sh && ./scripts/build-go-darwin-binaries.sh

Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
go-version: "1.22.0"

- run: scripts\build-go-windows-binaries.ps1

Expand All @@ -74,7 +74,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
go-version: "1.22.0"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
path: sedge
- uses: actions/setup-go@v5
with:
go-version: "1.21.0"
go-version: "1.22.0"
- name: Run publish PPA script
env:
GOPATH: /home/runner/go
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
matrix:
include:
- os: ubuntu-latest
go: '1.21'
go: '1.22'
- os: windows-latest
go: '1.21'
go: '1.22'
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -36,7 +36,7 @@ jobs:

- name: Run tests other
if: matrix.os != 'ubuntu-latest'
run: make generate && go test ./...
run: make generate && make test-no-e2e

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- New command `lido-status` to display data of Lido Node Operator.
- Monitoring stack setup with Grafana, Prometheus, and Node Exporter.

### Changed
- Update Go version from 1.21 to 1.22.

### Fixed
- Teku and Lighthouse import keys container error on Windows.
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ test: generate ## run tests
e2e-test: generate ## Run e2e tests
@go test -timeout 20m -count=1 ./e2e/...

e2e-test-windows: generate ## Run e2e tests on Windows
@go test -timeout 20m -count=1 -skip TestE2E_MonitoringStack ./e2e/...

test-no-e2e: generate ## run tests excluding e2e
@mkdir -p coverage
@go test -coverprofile=coverage/coverage.out -covermode=count ./... -skip TestE2E

codecov-test: generate ## unit tests with coverage using the courtney tool
@mkdir -p coverage
@courtney/courtney -v -o coverage/coverage.out ./...
@courtney/courtney -v -o coverage/coverage.out -t="-skip=TestE2E" ./...
@go tool cover -html=coverage/coverage.out -o coverage/coverage.html

install-gofumpt: ## install gofumpt
Expand Down
19 changes: 9 additions & 10 deletions cli/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package actions
import (
"github.com/NethermindEth/sedge/internal/pkg/commands"
"github.com/NethermindEth/sedge/internal/pkg/generate"
"github.com/NethermindEth/sedge/internal/pkg/services"
"github.com/docker/docker/client"
)

Expand All @@ -37,22 +36,22 @@ type SedgeActions interface {
}

type sedgeActions struct {
dockerClient client.APIClient
serviceManager services.ServiceManager
commandRunner commands.CommandRunner
dockerClient client.APIClient
dockerServiceManager DockerServiceManager
commandRunner commands.CommandRunner
}

type SedgeActionsOptions struct {
DockerClient client.APIClient
ServiceManager services.ServiceManager
CommandRunner commands.CommandRunner
DockerClient client.APIClient
DockerServiceManager DockerServiceManager
CommandRunner commands.CommandRunner
}

func NewSedgeActions(options SedgeActionsOptions) SedgeActions {
return &sedgeActions{
dockerClient: options.DockerClient,
serviceManager: options.ServiceManager,
commandRunner: options.CommandRunner,
dockerClient: options.DockerClient,
dockerServiceManager: options.DockerServiceManager,
commandRunner: options.CommandRunner,
}
}

Expand Down
14 changes: 14 additions & 0 deletions cli/actions/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package actions

import "github.com/docker/docker/api/types/container"

// DockerServiceManager is an interface for managing Docker containers.
type DockerServiceManager interface {
Image(service string) (string, error)
Stop(service string) error
Start(service string) error
IsRunning(service string) (bool, error)
Wait(service string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
ContainerID(service string) (string, error)
ContainerLogs(ctID, service string) (string, error)
}
6 changes: 3 additions & 3 deletions cli/actions/generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import (
func newAction(t *testing.T, ctrl *gomock.Controller) actions.SedgeActions {
t.Helper()
dockerClient := sedge_mocks.NewMockAPIClient(ctrl)
serviceManager := services.NewServiceManager(dockerClient)
dockerServiceManager := services.NewDockerServiceManager(dockerClient)
return actions.NewSedgeActions(actions.SedgeActionsOptions{
DockerClient: dockerClient,
ServiceManager: serviceManager,
DockerClient: dockerClient,
DockerServiceManager: dockerServiceManager,
})
}

Expand Down
6 changes: 3 additions & 3 deletions cli/actions/getContainers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ func getMockActions(

return actions.NewSedgeActions(
actions.SedgeActionsOptions{
DockerClient: dockerClient,
ServiceManager: nil,
CommandRunner: nil,
DockerClient: dockerClient,
DockerServiceManager: nil,
CommandRunner: nil,
},
)
}
Expand Down
47 changes: 25 additions & 22 deletions cli/actions/importKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/NethermindEth/sedge/internal/images/validator-import/teku"
"github.com/NethermindEth/sedge/internal/pkg/commands"
"github.com/NethermindEth/sedge/internal/pkg/services"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
Expand Down Expand Up @@ -72,18 +71,18 @@ func (s *sedgeActions) ImportValidatorKeys(options ImportValidatorKeysOptions) e
}
validatorCtName := services.ContainerNameWithTag(services.DefaultSedgeValidatorClient, options.ContainerTag)
// Check validator container exists
_, err := s.serviceManager.ContainerId(validatorCtName)
_, err := s.dockerServiceManager.ContainerID(validatorCtName)
if err != nil {
return err
}
previouslyRunning, err := s.serviceManager.IsRunning(validatorCtName)
previouslyRunning, err := s.dockerServiceManager.IsRunning(validatorCtName)
if err != nil {
return err
}
// Stop validator
if previouslyRunning {
log.Info("Stopping validator client")
if err := s.serviceManager.Stop(validatorCtName); err != nil {
if err := s.dockerServiceManager.Stop(validatorCtName); err != nil {
return err
}
}
Expand Down Expand Up @@ -177,16 +176,20 @@ func (s *sedgeActions) ImportValidatorKeys(options ImportValidatorKeysOptions) e
case "prysm":
prysmCtID := ""
if options.Distributed {
prysmCtID, err = setupPrysmValidatorImportContainerDV(s.dockerClient, s.commandRunner, s.serviceManager, options)
prysmCtID, err = setupPrysmValidatorImportContainerDV(s.dockerClient, s.commandRunner, s.dockerServiceManager, options)
if err != nil {
return err
}
ctID = prysmCtID
} else {
prysmCtID, err = setupPrysmValidatorImportContainer(s.dockerClient, s.serviceManager, options)
}
if err != nil {
return err
prysmCtID, err := setupPrysmValidatorImportContainer(s.dockerClient, s.dockerServiceManager, options)
if err != nil {
return err
}
ctID = prysmCtID
}
ctID = prysmCtID
case "lodestar":
lodestarCtID, err := setupLodestarValidatorImport(s.dockerClient, s.serviceManager, options)
lodestarCtID, err := setupLodestarValidatorImport(s.dockerClient, s.dockerServiceManager, options)
if err != nil {
return err
}
Expand All @@ -207,11 +210,11 @@ func (s *sedgeActions) ImportValidatorKeys(options ImportValidatorKeysOptions) e
return fmt.Errorf("%w: %s", ErrUnsupportedValidatorClient, options.ValidatorClient)
}
log.Info("Importing validator keys")
runErr := runAndWaitImportKeys(s.dockerClient, s.serviceManager, ctID)
runErr := runAndWaitImportKeys(s.dockerClient, s.dockerServiceManager, ctID)
// Run validator again
if (previouslyRunning && !options.StopValidator) || options.StartValidator {
log.Info("The validator container is being restarted")
if err := s.serviceManager.Start(validatorCtName); err != nil {
if err := s.dockerServiceManager.Start(validatorCtName); err != nil {
return err
}
}
Expand All @@ -225,12 +228,12 @@ func isDefaultKeysPath(generationPath, from string) bool {
return from == filepath.Join(generationPath, "keystore")
}

func setupPrysmValidatorImportContainer(dockerClient client.APIClient, serviceManager services.ServiceManager, options ImportValidatorKeysOptions) (string, error) {
func setupPrysmValidatorImportContainer(dockerClient client.APIClient, dockerServiceManager DockerServiceManager, options ImportValidatorKeysOptions) (string, error) {
var (
validatorCtName = services.ContainerNameWithTag(services.DefaultSedgeValidatorClient, options.ContainerTag)
validatorImportCtName = services.ContainerNameWithTag(services.ServiceCtValidatorImport, options.ContainerTag)
)
validatorImage, err := serviceManager.Image(validatorCtName)
validatorImage, err := dockerServiceManager.Image(validatorCtName)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -283,12 +286,12 @@ func setupPrysmValidatorImportContainer(dockerClient client.APIClient, serviceMa
return ct.ID, nil
}

func setupLodestarValidatorImport(dockerClient client.APIClient, serviceManager services.ServiceManager, options ImportValidatorKeysOptions) (string, error) {
func setupLodestarValidatorImport(dockerClient client.APIClient, dockerServiceManager DockerServiceManager, options ImportValidatorKeysOptions) (string, error) {
var (
validatorCtName = services.ContainerNameWithTag(services.DefaultSedgeValidatorClient, options.ContainerTag)
validatorImportCtName = services.ContainerNameWithTag(services.ServiceCtValidatorImport, options.ContainerTag)
)
validatorImage, err := serviceManager.Image(validatorCtName)
validatorImage, err := dockerServiceManager.Image(validatorCtName)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -498,19 +501,19 @@ func setupTekuValidatorImport(dockerClient client.APIClient, commandRunner comma
return ct.ID, nil
}

func runAndWaitImportKeys(dockerClient client.APIClient, serviceManager services.ServiceManager, ctID string) error {
func runAndWaitImportKeys(dockerClient client.APIClient, dockerServiceManager DockerServiceManager, ctID string) error {
log.Debugf("import keys container id: %s", ctID)
ctExit, errChan := serviceManager.Wait(ctID, container.WaitConditionNextExit)
ctExit, errChan := dockerServiceManager.Wait(ctID, container.WaitConditionNextExit)
log.Info("The keys import container is starting")
if err := dockerClient.ContainerStart(context.Background(), ctID, types.ContainerStartOptions{}); err != nil {
if err := dockerClient.ContainerStart(context.Background(), ctID, container.StartOptions{}); err != nil {
return err
}
osSignals := make(chan os.Signal, 1)
signal.Notify(osSignals, os.Interrupt)
for {
select {
case exitResult := <-ctExit:
logs, err := serviceManager.ContainerLogs(ctID, "Import keys")
logs, err := dockerServiceManager.ContainerLogs(ctID, "Import keys")
if err != nil {
return err
}
Expand All @@ -535,7 +538,7 @@ func runAndWaitImportKeys(dockerClient client.APIClient, serviceManager services
}
}

func setupPrysmValidatorImportContainerDV(dockerClient client.APIClient, commandRunner commands.CommandRunner, serviceManager services.ServiceManager, options ImportValidatorKeysOptions) (string, error) {
func setupPrysmValidatorImportContainerDV(dockerClient client.APIClient, commandRunner commands.CommandRunner, serviceManager DockerServiceManager, options ImportValidatorKeysOptions) (string, error) {
var (
validatorCtName = services.ContainerNameWithTag(services.DefaultSedgeValidatorClient, options.ContainerTag)
validatorImportCtName = services.ContainerNameWithTag(services.ServiceCtValidatorImport, options.ContainerTag)
Expand Down
Loading

0 comments on commit 6099dca

Please sign in to comment.