Skip to content

Commit

Permalink
Add Goland Standard "cmd" Pattern for Slasher Binaries (#8542)
Browse files Browse the repository at this point in the history
* vis

* gaz

* imports

* slasher img

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
  • Loading branch information
rauljordan and farazdagi committed Mar 3, 2021
1 parent ff329df commit d215607
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 92 deletions.
88 changes: 88 additions & 0 deletions cmd/slasher/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
load("@prysm//tools/go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle", "container_image")
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")

go_library(
name = "go_default_library",
srcs = [
"log.go",
"main.go",
"usage.go",
],
importpath = "github.com/prysmaticlabs/prysm/cmd/slasher",
visibility = ["//slasher:__subpackages__"],
deps = [
"//cmd/slasher/flags:go_default_library",
"//shared/cmd:go_default_library",
"//shared/debug:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/journald:go_default_library",
"//shared/logutil:go_default_library",
"//shared/tos:go_default_library",
"//shared/version:go_default_library",
"//slasher/db:go_default_library",
"//slasher/node:go_default_library",
"@com_github_joonix_log//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
],
)

go_test(
name = "go_default_test",
size = "small",
srcs = ["usage_test.go"],
embed = [":go_default_library"],
visibility = ["//slasher:__pkg__"],
deps = [
"//shared/featureconfig:go_default_library",
"//shared/testutil/assert:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],
)

go_image(
name = "image",
base = "//tools:cc_image",
binary = ":slasher",
tags = ["manual"],
visibility = ["//slasher:__pkg__"],
)

container_image(
name = "image_with_creation_time",
base = "image",
stamp = True,
visibility = ["//slasher:__pkg__"],
)

container_bundle(
name = "image_bundle",
images = {
"gcr.io/prysmaticlabs/prysm/slasher:latest": ":image_with_creation_time",
"gcr.io/prysmaticlabs/prysm/slasher:{DOCKER_TAG}": ":image_with_creation_time",
"index.docker.io/prysmaticlabs/prysm-slasher:latest": ":image_with_creation_time",
"index.docker.io/prysmaticlabs/prysm-slasher:{DOCKER_TAG}": ":image_with_creation_time",
},
tags = ["manual"],
visibility = ["//slasher:__pkg__"],
)

docker_push(
name = "push_images",
bundle = ":image_bundle",
tags = ["manual"],
visibility = ["//slasher:__pkg__"],
)

go_binary(
name = "slasher",
embed = [":go_default_library"],
visibility = [
"//endtoend:__pkg__",
"//slasher:__subpackages__",
],
)
7 changes: 5 additions & 2 deletions slasher/flags/BUILD.bazel → cmd/slasher/flags/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ load("@prysm//tools/go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["flags.go"],
importpath = "github.com/prysmaticlabs/prysm/slasher/flags",
visibility = ["//visibility:public"],
importpath = "github.com/prysmaticlabs/prysm/cmd/slasher/flags",
visibility = [
"//cmd/slasher:__subpackages__",
"//slasher:__subpackages__",
],
deps = ["@com_github_urfave_cli_v2//:go_default_library"],
)
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion slasher/main.go → cmd/slasher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"runtime"

joonix "github.com/joonix/log"
"github.com/prysmaticlabs/prysm/cmd/slasher/flags"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/prysmaticlabs/prysm/shared/tos"
"github.com/prysmaticlabs/prysm/shared/version"
"github.com/prysmaticlabs/prysm/slasher/db"
"github.com/prysmaticlabs/prysm/slasher/flags"
"github.com/prysmaticlabs/prysm/slasher/node"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
Expand Down
2 changes: 1 addition & 1 deletion slasher/usage.go → cmd/slasher/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"io"
"sort"

"github.com/prysmaticlabs/prysm/cmd/slasher/flags"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/slasher/flags"
"github.com/urfave/cli/v2"
)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion endtoend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ go_test(
args = ["-test.v"],
data = [
"//cmd/beacon-chain",
"//slasher",
"//cmd/slasher",
"//tools/bootnode",
"//cmd/validator",
"@com_github_ethereum_go_ethereum//cmd/geth",
Expand Down
2 changes: 1 addition & 1 deletion endtoend/components/slasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// StartSlashers starts slasher clients for use within E2E, connected to all beacon nodes.
func StartSlashers(t *testing.T) {
binaryPath, found := bazel.FindBinary("slasher", "slasher")
binaryPath, found := bazel.FindBinary("cmd/slasher", "slasher")
if !found {
t.Log(binaryPath)
t.Fatal("Slasher binary not found")
Expand Down
94 changes: 12 additions & 82 deletions slasher/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,83 +1,13 @@
load("@prysm//tools/go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle", "container_image")
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")

go_library(
name = "go_default_library",
srcs = [
"log.go",
"main.go",
"usage.go",
],
importpath = "github.com/prysmaticlabs/prysm/slasher",
visibility = ["//slasher:__subpackages__"],
deps = [
"//shared/cmd:go_default_library",
"//shared/debug:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/journald:go_default_library",
"//shared/logutil:go_default_library",
"//shared/tos:go_default_library",
"//shared/version:go_default_library",
"//slasher/db:go_default_library",
"//slasher/flags:go_default_library",
"//slasher/node:go_default_library",
"@com_github_joonix_log//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@com_github_x_cray_logrus_prefixed_formatter//:go_default_library",
],
)

go_test(
name = "go_default_test",
size = "small",
srcs = ["usage_test.go"],
embed = [":go_default_library"],
deps = [
"//shared/featureconfig:go_default_library",
"//shared/testutil/assert:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],
)

go_image(
name = "image",
base = "//tools:cc_image",
binary = ":slasher",
tags = ["manual"],
visibility = ["//visibility:private"],
)

container_image(
name = "image_with_creation_time",
base = "image",
stamp = True,
)

container_bundle(
name = "image_bundle",
images = {
"gcr.io/prysmaticlabs/prysm/slasher:latest": ":image_with_creation_time",
"gcr.io/prysmaticlabs/prysm/slasher:{DOCKER_TAG}": ":image_with_creation_time",
"index.docker.io/prysmaticlabs/prysm-slasher:latest": ":image_with_creation_time",
"index.docker.io/prysmaticlabs/prysm-slasher:{DOCKER_TAG}": ":image_with_creation_time",
},
tags = ["manual"],
)

docker_push(
name = "push_images",
bundle = ":image_bundle",
tags = ["manual"],
)

go_binary(
name = "slasher",
embed = [":go_default_library"],
visibility = [
"//endtoend:__pkg__",
],
load("//tools:target_migration.bzl", "moved_targets")

moved_targets(
[
":push_images",
":image_bundle",
":image_with_creation_time",
":image",
":go_default_test",
":slasher",
],
"//cmd/slasher",
)
5 changes: 4 additions & 1 deletion slasher/db/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ go_library(
"restore.go",
],
importpath = "github.com/prysmaticlabs/prysm/slasher/db",
visibility = ["//slasher:__subpackages__"],
visibility = [
"//cmd/slasher:__subpackages__",
"//slasher:__subpackages__",
],
deps = [
"//shared/cmd:go_default_library",
"//shared/fileutil:go_default_library",
Expand Down
7 changes: 5 additions & 2 deletions slasher/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ go_library(
"node.go",
],
importpath = "github.com/prysmaticlabs/prysm/slasher/node",
visibility = ["//slasher:__subpackages__"],
visibility = [
"//cmd/slasher:__subpackages__",
"//slasher:__subpackages__",
],
deps = [
"//cmd/slasher/flags:go_default_library",
"//shared:go_default_library",
"//shared/backuputil:go_default_library",
"//shared/cmd:go_default_library",
Expand All @@ -25,7 +29,6 @@ go_library(
"//slasher/db:go_default_library",
"//slasher/db/kv:go_default_library",
"//slasher/detection:go_default_library",
"//slasher/flags:go_default_library",
"//slasher/rpc:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion slasher/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"syscall"

"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/cmd/slasher/flags"
"github.com/prysmaticlabs/prysm/shared"
"github.com/prysmaticlabs/prysm/shared/backuputil"
"github.com/prysmaticlabs/prysm/shared/cmd"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/prysmaticlabs/prysm/slasher/db"
"github.com/prysmaticlabs/prysm/slasher/db/kv"
"github.com/prysmaticlabs/prysm/slasher/detection"
"github.com/prysmaticlabs/prysm/slasher/flags"
"github.com/prysmaticlabs/prysm/slasher/rpc"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
Expand Down

0 comments on commit d215607

Please sign in to comment.