Skip to content

Commit

Permalink
feat: implement reth and op-node checks
Browse files Browse the repository at this point in the history
..also:  refactor a bit
  • Loading branch information
0x416e746f6e committed Sep 16, 2024
1 parent 484ff13 commit c67b732
Show file tree
Hide file tree
Showing 37 changed files with 1,460 additions and 575 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ jobs:
- name: setup go dependencies
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"

- name: setup quemu
uses: docker/setup-qemu-action@v3

- name: setup docker buildx
uses: docker/setup-buildx-action@v3

- name: login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: build and publish backend release
uses: goreleaser/goreleaser-action@v5
Expand Down
17 changes: 10 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Built binaries
# builds

bin/*
!bin/.gitkeep
/bin/*
!/bin/.gitkeep
dist

# Goreleaser artifacts
# ide

dist/*
.idea
.vscode
*.code-workspace

# VS Code
# temporary files

.vscode
.temp
35 changes: 28 additions & 7 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ env:
builds:
- main: ./cmd
ldflags:
- -X main.version={{.Version}}
- -s
- -w
- -X main.version={{ .Version }}
targets:
- darwin_amd64
- darwin_arm64
- linux_386
- linux_amd64
- linux_arm
- linux_arm64
- windows_386
- windows_amd64

archives:
- id: zip
Expand All @@ -27,3 +23,28 @@ checksum:

release:
prerelease: auto

dockers:
- dockerfile: Dockerfile.goreleaser
goarch: amd64
goos: linux
use: buildx
build_flag_templates:
- --platform=linux/amd64
image_templates:
- "ghcr.io/flashbots/node-healthchecker:{{ .Tag }}-amd64"

- dockerfile: Dockerfile.goreleaser
goarch: arm64
goos: linux
use: buildx
build_flag_templates:
- --platform=linux/arm64
image_templates:
- "ghcr.io/flashbots/node-healthchecker:{{ .Tag }}-arm64"

docker_manifests:
- name_template: "ghcr.io/flashbots/node-healthchecker:{{ .Tag }}"
image_templates:
- "ghcr.io/flashbots/node-healthchecker:{{ .Tag }}-amd64"
- "ghcr.io/flashbots/node-healthchecker:{{ .Tag }}-arm64"
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# stage: build ---------------------------------------------------------

FROM golang:1.22-alpine as build

RUN apk add --no-cache gcc musl-dev linux-headers

WORKDIR /go/src/github.com/flashbots/node-healthchecker

COPY go.* ./
RUN go mod download

COPY . .

RUN go build -o bin/node-healthchecker -ldflags "-s -w" github.com/flashbots/node-healthchecker/cmd

# stage: run -----------------------------------------------------------

FROM alpine

RUN apk add --no-cache ca-certificates

WORKDIR /app

COPY --from=build /go/src/github.com/flashbots/node-healthchecker/bin/node-healthchecker ./node-healthchecker

ENTRYPOINT ["/app/node-healthchecker"]
9 changes: 9 additions & 0 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# stage: run

FROM gcr.io/distroless/static-debian12 as runner

WORKDIR /app

COPY node-healthchecker ./

ENTRYPOINT [ "./node-healthchecker" ]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Flashbots
Copyright (c) 2023-2024 Flashbots

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 17 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
VERSION := $(shell git describe --tags --always --dirty="-dev")

default: build
VERSION := $(shell git describe --tags --always --dirty="-dev" --match "v*.*.*" || echo "development" )
VERSION := $(VERSION:v%=%)

.PHONY: build
build:
CGO_ENABLED=0 go build -ldflags "-X main.version=${VERSION}" -o ./bin/node-healthchecker github.com/flashbots/node-healthchecker/cmd
@CGO_ENABLED=0 go build \
-ldflags "-X main.version=${VERSION}" \
-o ./bin/node-healthchecker \
github.com/flashbots/node-healthchecker/cmd

.PHONY: snapshot
snapshot:
goreleaser release --snapshot --rm-dist
@goreleaser release --snapshot --clean

.PHONY: help
help:
@printf "\n=====\n\n"
@go run github.com/flashbots/node-healthchecker/cmd help
@printf "\n=====\n\n"
@go run github.com/flashbots/node-healthchecker/cmd serve --help

.PHONY: release
release:
@rm -rf ./dist
GITHUB_TOKEN=$$( gh auth token ) goreleaser release
.PHONY: serve
serve:
@go run github.com/flashbots/node-healthchecker/cmd serve
18 changes: 18 additions & 0 deletions cmd/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"github.com/urfave/cli/v2"

"github.com/flashbots/node-healthchecker/config"
)

func CommandHelp(_ *config.Config) *cli.Command {
return &cli.Command{
Usage: "show the list of commands or help for one command",
Name: "help",

Action: func(clictx *cli.Context) error {
return cli.ShowAppHelp(clictx)
},
}
}
107 changes: 47 additions & 60 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,78 @@ package main
import (
"fmt"
"os"
"strings"

"github.com/urfave/cli/v2"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/flashbots/node-healthchecker/config"
"github.com/flashbots/node-healthchecker/logutils"
)

var (
version = "development"
)

const (
envPrefix = "NH_"
)

func main() {
var logFormat, logLevel string
cfg := &config.Config{}

app := &cli.App{
Name: "node-healthchecker",
Usage: "Aggregates complex health-checks of a blockchain node into a simple http endpoint",
Version: version,
flags := []cli.Flag{
&cli.StringFlag{
Destination: &cfg.Log.Level,
EnvVars: []string{envPrefix + "LOG_LEVEL"},
Name: "log-level",
Usage: "logging level",
Value: "info",
},

Action: func(c *cli.Context) error {
return cli.ShowAppHelp(c)
&cli.StringFlag{
Destination: &cfg.Log.Mode,
EnvVars: []string{envPrefix + "LOG_MODE"},
Name: "log-mode",
Usage: "logging mode",
Value: "prod",
},
}

Flags: []cli.Flag{
&cli.StringFlag{
Destination: &logLevel,
EnvVars: []string{"LOG_LEVEL"},
Name: "log-level",
Usage: "logging level",
Value: "info",
},
commands := []*cli.Command{
CommandServe(cfg),
CommandHelp(cfg),
}

&cli.StringFlag{
Destination: &logFormat,
EnvVars: []string{"LOG_MODE"},
Name: "log-mode",
Usage: "logging mode",
Value: "prod",
},
},
app := &cli.App{
Name: "node-healthchecker",
Usage: "Report the sync-status of a blockchain node as HTTP status",
Version: version,

Flags: flags,
Commands: commands,
DefaultCommand: commands[0].Name,

Before: func(ctx *cli.Context) error {
err := setupLogger(logLevel, logFormat)
Before: func(_ *cli.Context) error {
// setup logger
l, err := logutils.NewLogger(&cfg.Log)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to configure the logging: %s\n", err)
return err
}
return err
zap.ReplaceGlobals(l)

return nil
},

Commands: []*cli.Command{
CommandServe(),
Action: func(clictx *cli.Context) error {
return cli.ShowAppHelp(clictx)
},
}

defer func() {
zap.L().Sync()
zap.L().Sync() //nolint:errcheck
}()
if err := app.Run(os.Args); err != nil {
zap.L().Error("Failed with error", zap.Error(err))
}
}

func setupLogger(level, mode string) error {
var config zap.Config
switch strings.ToLower(mode) {
case "dev":
config = zap.NewDevelopmentConfig()
case "prod":
config = zap.NewProductionConfig()
default:
return fmt.Errorf("invalid log-mode '%s'", mode)
fmt.Fprintf(os.Stderr, "\nFailed with error:\n\n%s\n\n", err.Error())
os.Exit(1)
}
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder

logLevel, err := zap.ParseAtomicLevel(level)
if err != nil {
return fmt.Errorf("invalid log-level '%s': %w", level, err)
}
config.Level = logLevel

l, err := config.Build()
if err != nil {
return fmt.Errorf("failed to build the logger: %w", err)
}
zap.ReplaceGlobals(l)

return nil
}
Loading

0 comments on commit c67b732

Please sign in to comment.