mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
Remove rules_docker, make multiarch images canonical (#13324)
* Remove rules_docker * Update base image
This commit is contained in:
@@ -1,36 +1,26 @@
|
||||
load("@rules_pkg//pkg:pkg.bzl", "pkg_tar")
|
||||
load("@io_bazel_rules_docker//contrib:passwd.bzl", "passwd_entry", "passwd_file")
|
||||
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
|
||||
load("//tools:build_settings.bzl", "base_image")
|
||||
load("@rules_distroless//distroless:defs.bzl", "passwd")
|
||||
|
||||
################################################################################
|
||||
## Docker images as non-root user ##
|
||||
################################################################################
|
||||
|
||||
# Create a passwd file with a root and nonroot user and uid.
|
||||
passwd_entry(
|
||||
name = "root_user",
|
||||
gid = 0,
|
||||
tags = ["manual"],
|
||||
uid = 0,
|
||||
username = "root",
|
||||
)
|
||||
|
||||
passwd_entry(
|
||||
name = "nonroot_user",
|
||||
info = "nonroot",
|
||||
tags = ["manual"],
|
||||
uid = 1001,
|
||||
username = "nonroot",
|
||||
)
|
||||
|
||||
passwd_file(
|
||||
passwd(
|
||||
name = "passwd",
|
||||
entries = [
|
||||
":root_user",
|
||||
":nonroot_user",
|
||||
passwds = [
|
||||
dict(
|
||||
gecos = ["root"],
|
||||
gid = 0,
|
||||
home = "/root",
|
||||
shell = "/bin/bash",
|
||||
uid = 0,
|
||||
username = "root",
|
||||
),
|
||||
dict(
|
||||
gecos = ["nonroot"],
|
||||
gid = 1001,
|
||||
home = "/home/nonroot",
|
||||
shell = "/bin/bash",
|
||||
uid = 1001,
|
||||
username = "nonroot",
|
||||
),
|
||||
],
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
# Create a tar file containing the created passwd file
|
||||
@@ -43,64 +33,6 @@ pkg_tar(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
CC_DEFAULT_BASE = select({
|
||||
"@io_bazel_rules_docker//:debug": "@cc_debug_image_base_amd64//image",
|
||||
"@io_bazel_rules_docker//:fastbuild": "@cc_image_base_amd64//image",
|
||||
"@io_bazel_rules_docker//:optimized": "@cc_image_base_amd64//image",
|
||||
"//conditions:default": "@cc_image_base_amd64//image",
|
||||
})
|
||||
|
||||
GO_DEFAULT_BASE = select({
|
||||
"@io_bazel_rules_docker//:debug": "@go_debug_image_base_amd64//image",
|
||||
"@io_bazel_rules_docker//:fastbuild": "@go_image_base_amd64//image",
|
||||
"@io_bazel_rules_docker//:optimized": "@go_image_base_amd64//image",
|
||||
"//conditions:default": "@go_image_base_amd64//image",
|
||||
})
|
||||
|
||||
# Include it in our base image as a tar.
|
||||
container_image(
|
||||
name = "cc_image",
|
||||
base = CC_DEFAULT_BASE,
|
||||
tags = ["manual"],
|
||||
tars = [":passwd_tar"],
|
||||
user = "root",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
container_image(
|
||||
name = "go_image",
|
||||
base = GO_DEFAULT_BASE,
|
||||
tags = ["manual"],
|
||||
tars = [":passwd_tar"],
|
||||
user = "root",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
base_image(
|
||||
name = "base_image",
|
||||
build_setting_default = "cc_image",
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "base_image_alpine",
|
||||
flag_values = {"//tools:base_image": "alpine"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "base_image_cc",
|
||||
flag_values = {"//tools:base_image": "cc_image"},
|
||||
)
|
||||
|
||||
container_image(
|
||||
name = "alpine_cc_image",
|
||||
base = "@alpine_cc_linux_amd64//image",
|
||||
tags = ["manual"],
|
||||
tars = [":passwd_tar"],
|
||||
user = "root",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Create a bash tar layer for docker images. This allows docker images to have access to the "bash"
|
||||
# command and improves debugging abilities on the image.
|
||||
genrule(
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
|
||||
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
|
||||
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle")
|
||||
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
|
||||
load("//tools:prysm_image.bzl", "prysm_image_upload")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@@ -34,35 +32,12 @@ go_library(
|
||||
],
|
||||
)
|
||||
|
||||
go_image(
|
||||
name = "image",
|
||||
base = "//tools:cc_image",
|
||||
binary = ":bootnode",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "bootnode",
|
||||
embed = [":go_default_library"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
container_bundle(
|
||||
name = "image_bundle",
|
||||
images = {
|
||||
"gcr.io/prysmaticlabs/prysm/bootnode:latest": ":image",
|
||||
"gcr.io/prysmaticlabs/prysm/bootnode:{DOCKER_TAG}": ":image",
|
||||
},
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
docker_push(
|
||||
name = "push_images",
|
||||
bundle = ":image_bundle",
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["bootnode_test.go"],
|
||||
@@ -80,3 +55,15 @@ go_test(
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
prysm_image_upload(
|
||||
name = "push_images",
|
||||
binary = ":bootnode",
|
||||
entrypoint = ["/bootnode"],
|
||||
repository = "gcr.io/prysmaticlabs/prysm/bootnode",
|
||||
symlinks = {
|
||||
# Backwards compatibility for images that depended on the old filepath.
|
||||
"/app/tools/bootnode/bootnode": "/bootnode",
|
||||
},
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
|
||||
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
|
||||
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle")
|
||||
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
|
||||
load("//tools:prysm_image.bzl", "prysm_image_upload")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@@ -26,25 +24,14 @@ go_binary(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_image(
|
||||
name = "image",
|
||||
base = "//tools:go_image",
|
||||
binary = "enr-calculator",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
container_bundle(
|
||||
name = "image_bundle",
|
||||
images = {
|
||||
"gcr.io/prysmaticlabs/prysm/enr-calculator:latest": ":image",
|
||||
"gcr.io/prysmaticlabs/prysm/enr-calculator:{DOCKER_TAG}": ":image",
|
||||
prysm_image_upload(
|
||||
name = "push_images",
|
||||
binary = ":enr-calculator",
|
||||
entrypoint = ["/enr-calculator"],
|
||||
repository = "gcr.io/prysmaticlabs/prysm/enr-calculator",
|
||||
symlinks = {
|
||||
# Backwards compatibility for images that depended on the old filepath.
|
||||
"/app/tools/enr-calculator/enr-calculator": "/enr-calculator",
|
||||
},
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
docker_push(
|
||||
name = "push_images",
|
||||
bundle = ":image_bundle",
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
|
||||
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
|
||||
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle")
|
||||
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
|
||||
load("//tools:prysm_image.bzl", "prysm_image_upload")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@@ -24,25 +22,14 @@ go_binary(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_image(
|
||||
name = "image",
|
||||
base = "//tools:go_image",
|
||||
prysm_image_upload(
|
||||
name = "push_images",
|
||||
binary = ":eth1exporter",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
container_bundle(
|
||||
name = "image_bundle",
|
||||
images = {
|
||||
"gcr.io/prysmaticlabs/prysm/eth1monitor:latest": ":image",
|
||||
"gcr.io/prysmaticlabs/prysm/eth1monitor:{DOCKER_TAG}": ":image",
|
||||
entrypoint = ["/eth1exporter"],
|
||||
repository = "gcr.io/prysmaticlabs/prysm/eth1monitor",
|
||||
symlinks = {
|
||||
# Backwards compatibility for images that depended on the old filepath.
|
||||
"/app/tools/eth1exporter/eth1exporter": "/eth1exporter",
|
||||
},
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
docker_push(
|
||||
name = "push_images",
|
||||
bundle = ":image_bundle",
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
load("@io_bazel_rules_docker//container:providers.bzl", "ImageInfo")
|
||||
|
||||
# Defines the debug transition implementation to enforce dbg mode.
|
||||
def _debug_transition_impl(settings, attr):
|
||||
return {
|
||||
"//command_line_option:compilation_mode": "dbg",
|
||||
}
|
||||
|
||||
# Defines a starlark transition which enforces dbg compilation mode.
|
||||
build_in_debug_mode = transition(
|
||||
implementation = _debug_transition_impl,
|
||||
inputs = [],
|
||||
outputs = ["//command_line_option:compilation_mode"],
|
||||
)
|
||||
|
||||
def _alpine_transition_impl(settings, attr):
|
||||
return {
|
||||
"//tools:base_image": "alpine",
|
||||
}
|
||||
|
||||
use_alpine = transition(
|
||||
implementation = _alpine_transition_impl,
|
||||
inputs = [],
|
||||
outputs = ["//tools:base_image"],
|
||||
)
|
||||
|
||||
# Defines a rule implementation that essentially returns all of the providers from the image attr.
|
||||
def _go_image_debug_impl(ctx):
|
||||
img = ctx.attr.image[0]
|
||||
|
||||
return [
|
||||
img[ImageInfo],
|
||||
img[OutputGroupInfo],
|
||||
]
|
||||
|
||||
# Defines a rule that specifies a starlark transition to enforce debug compilation mode for debug
|
||||
# images.
|
||||
go_image_debug = rule(
|
||||
implementation = _go_image_debug_impl,
|
||||
attrs = {
|
||||
"image": attr.label(
|
||||
cfg = build_in_debug_mode,
|
||||
executable = True,
|
||||
),
|
||||
# Whitelist is required or bazel complains.
|
||||
"_whitelist_function_transition": attr.label(default = "@bazel_tools//tools/whitelists/function_transition_whitelist"),
|
||||
},
|
||||
)
|
||||
go_image_alpine = rule(
|
||||
_go_image_debug_impl,
|
||||
attrs = {
|
||||
"image": attr.label(
|
||||
cfg = use_alpine,
|
||||
executable = True,
|
||||
),
|
||||
# Whitelist is required or bazel complains.
|
||||
"_whitelist_function_transition": attr.label(default = "@bazel_tools//tools/whitelists/function_transition_whitelist"),
|
||||
},
|
||||
)
|
||||
@@ -1,8 +1,6 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
|
||||
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
|
||||
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle")
|
||||
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
|
||||
load("//tools:prysm_image.bzl", "prysm_image_upload")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@@ -18,33 +16,6 @@ go_binary(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
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 = ":http-request-sink",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
container_bundle(
|
||||
name = "image_bundle",
|
||||
images = {
|
||||
"gcr.io/prysmaticlabs/prysm/http-request-sink:latest": ":image",
|
||||
"gcr.io/prysmaticlabs/prysm/http-request-sink:{DOCKER_TAG}": ":image",
|
||||
},
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
docker_push(
|
||||
name = "push_images",
|
||||
bundle = ":image_bundle",
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["main_test.go"],
|
||||
@@ -54,3 +25,15 @@ go_test(
|
||||
"//testing/require:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
prysm_image_upload(
|
||||
name = "push_images",
|
||||
binary = ":http-request-sink",
|
||||
entrypoint = ["/http-request-sink"],
|
||||
repository = "gcr.io/prysmaticlabs/prysm/http-request-sink",
|
||||
symlinks = {
|
||||
# Backwards compatibility for images that depended on the old filepath.
|
||||
"/app/tools/http-request-sink/http-request-sink": "/http-request-sink",
|
||||
},
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
|
||||
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
|
||||
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle")
|
||||
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
|
||||
load("//tools:prysm_image.bzl", "prysm_image_upload")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
@@ -25,31 +23,20 @@ go_library(
|
||||
],
|
||||
)
|
||||
|
||||
go_image(
|
||||
name = "image",
|
||||
base = "//tools:cc_image",
|
||||
binary = ":pcli",
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "pcli",
|
||||
embed = [":go_default_library"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
container_bundle(
|
||||
name = "image_bundle",
|
||||
images = {
|
||||
"gcr.io/prysmaticlabs/prysm/pcli:latest": ":image",
|
||||
"gcr.io/prysmaticlabs/prysm/pcli:{DOCKER_TAG}": ":image",
|
||||
prysm_image_upload(
|
||||
name = "push_images",
|
||||
binary = ":pcli",
|
||||
entrypoint = ["/pcli"],
|
||||
repository = "gcr.io/prysmaticlabs/prysm/pcli",
|
||||
symlinks = {
|
||||
# Backwards compatibility for images that depended on the old filepath.
|
||||
"/app/tools/pcli/pcli": "/pcli",
|
||||
},
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
docker_push(
|
||||
name = "push_images",
|
||||
bundle = ":image_bundle",
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user