Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Goland Standard "cmd" Pattern for Validator Binaries #8541

Merged
merged 12 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions cmd/validator/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
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("//tools:go_image.bzl", "go_image_alpine", "go_image_debug")
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/validator",
visibility = ["//validator:__subpackages__"],
deps = [
"//cmd/validator/flags:go_default_library",
"//shared/cmd:go_default_library",
"//shared/debug:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/fileutil:go_default_library",
"//shared/journald:go_default_library",
"//shared/logutil:go_default_library",
"//shared/maxprocs:go_default_library",
"//shared/tos:go_default_library",
"//shared/version:go_default_library",
"//validator/accounts:go_default_library",
"//validator/db:go_default_library",
"//validator/node:go_default_library",
"//validator/slashing-protection: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_image(
name = "image",
base = select({
"//tools:base_image_alpine": "//tools:alpine_cc_image",
"//tools:base_image_cc": "//tools:cc_image",
"//conditions:default": "//tools:cc_image",
}),
binary = ":validator",
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/validator:latest": ":image_with_creation_time",
"gcr.io/prysmaticlabs/prysm/validator:{DOCKER_TAG}": ":image_with_creation_time",
"index.docker.io/prysmaticlabs/prysm-validator:latest": ":image_with_creation_time",
"index.docker.io/prysmaticlabs/prysm-validator:{DOCKER_TAG}": ":image_with_creation_time",
},
tags = ["manual"],
)

go_image_debug(
name = "image_debug",
image = ":image",
tags = ["manual"],
)

container_bundle(
name = "image_bundle_debug",
images = {
"gcr.io/prysmaticlabs/prysm/validator:latest-debug": ":image_debug",
"gcr.io/prysmaticlabs/prysm/validator:{DOCKER_TAG}-debug": ":image_debug",
"index.docker.io/prysmaticlabs/prysm-validator:latest-debug": ":image_debug",
"index.docker.io/prysmaticlabs/prysm-validator:{DOCKER_TAG}-debug": ":image_debug",
},
tags = ["manual"],
)

go_image_alpine(
name = "image_alpine",
image = ":image",
tags = ["manual"],
)

container_bundle(
name = "image_bundle_alpine",
images = {
"gcr.io/prysmaticlabs/prysm/validator:latest-alpine": ":image_alpine",
"gcr.io/prysmaticlabs/prysm/validator:{DOCKER_TAG}-alpine": ":image_alpine",
"index.docker.io/prysmaticlabs/prysm-validator:latest-alpine": ":image_alpine",
"index.docker.io/prysmaticlabs/prysm-validator:{DOCKER_TAG}-alpine": ":image_alpine",
},
tags = ["manual"],
)

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

docker_push(
name = "push_images_debug",
bundle = ":image_bundle_debug",
tags = ["manual"],
)

docker_push(
name = "push_images_alpine",
bundle = ":image_bundle_alpine",
tags = ["manual"],
)

go_binary(
name = "validator",
embed = [":go_default_library"],
pure = "off", # Enabled unless there is a valid reason to include cgo dep.
visibility = [
"//endtoend:__pkg__",
"//validator:__subpackages__",
],
)

go_test(
name = "go_default_test",
srcs = ["usage_test.go"],
embed = [":go_default_library"],
deps = [
"//shared/featureconfig:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ go_library(
"flags.go",
"interop.go",
],
importpath = "github.com/prysmaticlabs/prysm/validator/flags",
visibility = ["//validator:__subpackages__"],
importpath = "github.com/prysmaticlabs/prysm/cmd/validator/flags",
visibility = [
"//cmd/validator:__subpackages__",
"//validator:__subpackages__",
],
deps = [
"//shared/fileutil:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion validator/main.go → cmd/validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
runtimeDebug "runtime/debug"

joonix "github.com/joonix/log"
"github.com/prysmaticlabs/prysm/cmd/validator/flags"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/prysmaticlabs/prysm/shared/version"
"github.com/prysmaticlabs/prysm/validator/accounts"
"github.com/prysmaticlabs/prysm/validator/db"
"github.com/prysmaticlabs/prysm/validator/flags"
"github.com/prysmaticlabs/prysm/validator/node"
slashingprotection "github.com/prysmaticlabs/prysm/validator/slashing-protection"
"github.com/sirupsen/logrus"
Expand Down
2 changes: 1 addition & 1 deletion validator/usage.go → cmd/validator/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/validator/flags"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/debug"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/validator/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 @@ -16,7 +16,7 @@ go_test(
"//beacon-chain",
"//slasher",
"//tools/bootnode",
"//validator",
"//cmd/validator",
"@com_github_ethereum_go_ethereum//cmd/geth",
],
shard_count = 2,
Expand Down
168 changes: 54 additions & 114 deletions validator/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,138 +1,78 @@
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("//tools:go_image.bzl", "go_image_alpine", "go_image_debug")
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/validator",
visibility = ["//validator:__subpackages__"],
deps = [
"//shared/cmd:go_default_library",
"//shared/debug:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/fileutil:go_default_library",
"//shared/journald:go_default_library",
"//shared/logutil:go_default_library",
"//shared/maxprocs:go_default_library",
"//shared/tos:go_default_library",
"//shared/version:go_default_library",
"//validator/accounts:go_default_library",
"//validator/db:go_default_library",
"//validator/flags:go_default_library",
"//validator/node:go_default_library",
"//validator/slashing-protection: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",
],
# validator/BUILD.bazel
alias(
name = "validator",
actual = "//cmd/validator:validator",
deprecation = "This target has moved to cmd/validator",
)

go_image(
name = "image",
base = select({
"//tools:base_image_alpine": "//tools:alpine_cc_image",
"//tools:base_image_cc": "//tools:cc_image",
"//conditions:default": "//tools:cc_image",
}),
binary = ":validator",
tags = ["manual"],
visibility = ["//visibility:private"],
alias(
name = "validator:push_images_debug",
actual = "//cmd/validator:push_images_debug",
deprecation = "This target has moved to cmd/validator:push_images_debug",
)

container_image(
name = "image_with_creation_time",
base = "image",
stamp = True,
alias(
name = "validator:push_images_alpine",
actual = "//cmd/validator:push_images_alpine",
deprecation = "This target has moved to cmd/validator:push_images_alpine",
)

container_bundle(
name = "image_bundle",
images = {
"gcr.io/prysmaticlabs/prysm/validator:latest": ":image_with_creation_time",
"gcr.io/prysmaticlabs/prysm/validator:{DOCKER_TAG}": ":image_with_creation_time",
"index.docker.io/prysmaticlabs/prysm-validator:latest": ":image_with_creation_time",
"index.docker.io/prysmaticlabs/prysm-validator:{DOCKER_TAG}": ":image_with_creation_time",
},
tags = ["manual"],
alias(
name = "validator:push_images",
actual = "//cmd/validator:push_images",
deprecation = "This target has moved to cmd/validator:push_images",
)

go_image_debug(
name = "image_debug",
image = ":image",
tags = ["manual"],
alias(
name = "validator:image_bundle_debug
actual = "//cmd/validator:image_bundle_debug",
deprecation = "This target has moved to cmd/validator:image_bundle_debug",
)

container_bundle(
name = "image_bundle_debug",
images = {
"gcr.io/prysmaticlabs/prysm/validator:latest-debug": ":image_debug",
"gcr.io/prysmaticlabs/prysm/validator:{DOCKER_TAG}-debug": ":image_debug",
"index.docker.io/prysmaticlabs/prysm-validator:latest-debug": ":image_debug",
"index.docker.io/prysmaticlabs/prysm-validator:{DOCKER_TAG}-debug": ":image_debug",
},
tags = ["manual"],
alias(
name = "validator:image_debug",
actual = "//cmd/validator:image_debug",
deprecation = "This target has moved to cmd/validator:image_debug",
)

go_image_alpine(
name = "image_alpine",
image = ":image",
tags = ["manual"],
alias(
name = "validator:image_bundle_alpine",
actual = "//cmd/validator:image_bundle_alpine",
deprecation = "This target has moved to cmd/validator:image_bundle_alpine",
)

container_bundle(
name = "image_bundle_alpine",
images = {
"gcr.io/prysmaticlabs/prysm/validator:latest-alpine": ":image_alpine",
"gcr.io/prysmaticlabs/prysm/validator:{DOCKER_TAG}-alpine": ":image_alpine",
"index.docker.io/prysmaticlabs/prysm-validator:latest-alpine": ":image_alpine",
"index.docker.io/prysmaticlabs/prysm-validator:{DOCKER_TAG}-alpine": ":image_alpine",
},
tags = ["manual"],
alias(
name = "validator:image_bundle",
actual = "//cmd/validator:image_bundle",
deprecation = "This target has moved to cmd/validator:image_bundle",
)

docker_push(
name = "push_images",
bundle = ":image_bundle",
tags = ["manual"],
alias(
name = "validator:image_with_creation_time",
actual = "//cmd/validator:image_with_creation_time",
deprecation = "This target has moved to cmd/validator:image_with_creation_time
rauljordan marked this conversation as resolved.
Show resolved Hide resolved
)

docker_push(
name = "push_images_debug",
bundle = ":image_bundle_debug",
tags = ["manual"],
alias(
name = "validator:image_alpine",
actual = "//cmd/validator:image_alpine",
deprecation = "This target has moved to cmd/validator:image_alpine",
)

docker_push(
name = "push_images_alpine",
bundle = ":image_bundle_alpine",
tags = ["manual"],
alias(
name = "validator:image",
actual = "//cmd/validator:image",
deprecation = "This target has moved to cmd/validator:image",
)

go_binary(
name = "validator",
embed = [":go_default_library"],
pure = "off", # Enabled unless there is a valid reason to include cgo dep.
visibility = [
"//endtoend:__pkg__",
"//validator:__subpackages__",
],
alias(
name = "validator:go_default_test",
actual = "//cmd/validator:go_default_test",
deprecation = "This target has moved to cmd/validator:go_default_test",
)

go_test(
name = "go_default_test",
srcs = ["usage_test.go"],
embed = [":go_default_library"],
deps = [
"//shared/featureconfig:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],
)
alias(
name = "validator",
actual = "//cmd/validator:go_default_library",
deprecation = "This target has moved to cmd/validator:go_default_library",
)
Loading