diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a8fed61 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Release + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..fa6a928 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,33 @@ +project_name: contributoor-test + +before: + hooks: + - go mod tidy + +builds: + - main: ./cmd/sentry + binary: sentry + env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + +archives: + - format: tar.gz + name_template: >- + {{ .ProjectName }}_ + {{- .Version }}_ + {{- .Os }}_ + {{- .Arch }} + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^ci:' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6433ec8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.23-alpine AS builder + +WORKDIR /app +COPY . . +RUN go build -o sentry ./cmd/sentry + +FROM alpine:latest + +COPY --from=builder /app/sentry /usr/local/bin/ +RUN mkdir -p /config +ENTRYPOINT ["sentry"] \ No newline at end of file diff --git a/cmd/sentry/main.go b/cmd/sentry/main.go new file mode 100644 index 0000000..807274f --- /dev/null +++ b/cmd/sentry/main.go @@ -0,0 +1,84 @@ +package main + +import ( + "os" + "os/signal" + "syscall" + + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "gopkg.in/yaml.v3" +) + +var ( + version = "0.0.1" + cfgFile string + log = logrus.New() +) + +type ContributoorConfig struct { + ContributoorDirectory string `yaml:"contributoorDirectory"` + Network *NetworkConfig `yaml:"network"` +} + +type NetworkConfig struct { + Name Parameter `yaml:"name"` + BeaconNodeAddress Parameter `yaml:"beaconNodeAddress"` +} + +// A parameter that can be configured by the user +type Parameter struct { + Value interface{} `yaml:"value,omitempty"` +} + +var rootCmd = &cobra.Command{ + Use: "sentry", + Short: "Contributoor sentry node", + Run: func(cmd *cobra.Command, args []string) { + config, err := loadConfig(cfgFile) + if err != nil { + log.Fatal(err) + } + + logCtx := log.WithFields(logrus.Fields{ + "config_path": config.ContributoorDirectory, + "network_name": config.Network.Name.Value, + "beacon_address": config.Network.BeaconNodeAddress.Value, + "version": version, + }) + + logCtx.Info("Starting sentry...") + + // Wait for interrupt signal + sigChan := make(chan os.Signal, 1) + signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) + <-sigChan + + log.Info("Shutting down...") + }, +} + +func init() { + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file path") +} + +func main() { + if err := rootCmd.Execute(); err != nil { + log.Fatal(err) + os.Exit(1) + } +} + +func loadConfig(path string) (*ContributoorConfig, error) { + data, err := os.ReadFile(path) + if err != nil { + return nil, err + } + + cfg := &ContributoorConfig{} + if err := yaml.Unmarshal(data, cfg); err != nil { + return nil, err + } + + return cfg, nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b52f0fc --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module github.com/ethpandaops/contributoor-test + +go 1.23.4 + +require ( + github.com/sirupsen/logrus v1.9.3 + github.com/spf13/cobra v1.8.1 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..29f1283 --- /dev/null +++ b/go.sum @@ -0,0 +1,25 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=