Add alpine based docker images for validator and beacon chain (#5214)

* Add alpine based images for validator and beacon chain

* Use an alpine image with glibc

* manual tags on transitional targets

* poke buildkite

* poke buildkite
This commit is contained in:
Preston Van Loon 2020-03-25 17:36:28 -07:00 committed by GitHub
parent e077d3ddc9
commit 3792bf67b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 4 deletions

View File

@ -117,6 +117,18 @@ load(
container_repositories() container_repositories()
load(
"@io_bazel_rules_docker//container:container.bzl",
"container_pull",
)
container_pull(
name = "alpine_cc_linux_amd64",
digest = "sha256:d5cee45549351be7a03a96c7b319b9c1808979b10888b79acca4435cc068005e",
registry = "index.docker.io",
repository = "frolvlad/alpine-glibc",
)
load("@prysm//third_party/herumi:herumi.bzl", "bls_dependencies") load("@prysm//third_party/herumi:herumi.bzl", "bls_dependencies")
bls_dependencies() bls_dependencies()

View File

@ -1,7 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@io_bazel_rules_docker//go:image.bzl", "go_image") 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//container:container.bzl", "container_bundle")
load("//tools:binary_targets.bzl", "binary_targets", "go_image_debug") load("//tools:binary_targets.bzl", "binary_targets", "go_image_alpine", "go_image_debug")
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push") load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
go_library( go_library(
@ -37,7 +37,11 @@ go_image(
"main.go", "main.go",
"usage.go", "usage.go",
], ],
base = "//tools:cc_image", base = select({
"//tools:base_image_alpine": "//tools:alpine_cc_image",
"//tools:base_image_cc": "//tools:cc_image",
"//conditions:default": "//tools:cc_image",
}),
goarch = "amd64", goarch = "amd64",
goos = "linux", goos = "linux",
importpath = "github.com/prysmaticlabs/prysm/beacon-chain", importpath = "github.com/prysmaticlabs/prysm/beacon-chain",
@ -76,6 +80,7 @@ container_bundle(
go_image_debug( go_image_debug(
name = "image_debug", name = "image_debug",
image = ":image", image = ":image",
tags = ["manual"],
) )
container_bundle( container_bundle(
@ -87,6 +92,21 @@ container_bundle(
tags = ["manual"], tags = ["manual"],
) )
go_image_alpine(
name = "image_alpine",
image = ":image",
tags = ["manual"],
)
container_bundle(
name = "image_bundle_alpine",
images = {
"gcr.io/prysmaticlabs/prysm/beacon-chain:latest-alpine": ":image_alpine",
"gcr.io/prysmaticlabs/prysm/beacon-chain:{DOCKER_TAG}-alpine": ":image_alpine",
},
tags = ["manual"],
)
docker_push( docker_push(
name = "push_images", name = "push_images",
bundle = ":image_bundle", bundle = ":image_bundle",
@ -99,6 +119,12 @@ docker_push(
tags = ["manual"], tags = ["manual"],
) )
docker_push(
name = "push_images_alpine",
bundle = ":image_bundle_alpine",
tags = ["manual"],
)
go_binary( go_binary(
name = "beacon-chain", name = "beacon-chain",
embed = [":go_default_library"], embed = [":go_default_library"],

View File

@ -3,6 +3,7 @@ load("@io_bazel_rules_docker//contrib:passwd.bzl", "passwd_entry", "passwd_file"
load("@io_bazel_rules_docker//container:container.bzl", "container_image") load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@io_bazel_rules_docker//cc:image.bzl", CC_DEFAULT_BASE = "DEFAULT_BASE") load("@io_bazel_rules_docker//cc:image.bzl", CC_DEFAULT_BASE = "DEFAULT_BASE")
load("@io_bazel_rules_docker//go:image.bzl", GO_DEFAULT_BASE = "DEFAULT_BASE") load("@io_bazel_rules_docker//go:image.bzl", GO_DEFAULT_BASE = "DEFAULT_BASE")
load("//tools:build_settings.bzl", "base_image")
alias( alias(
name = "kubesec", name = "kubesec",
@ -61,3 +62,26 @@ container_image(
user = "root", user = "root",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
base_image(
name = "base_image",
build_setting_default = "cc_image",
)
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",
tars = [":passwd_tar"],
user = "root",
visibility = ["//visibility:public"],
)

View File

@ -39,6 +39,17 @@ build_in_debug_mode = transition(
outputs = ["//command_line_option:compilation_mode"], 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. # Defines a rule implementation that essentially returns all of the providers from the image attr.
def _go_image_debug_impl(ctx): def _go_image_debug_impl(ctx):
img = ctx.attr.image[0] img = ctx.attr.image[0]
@ -61,3 +72,14 @@ go_image_debug = rule(
"_whitelist_function_transition": attr.label(default = "@bazel_tools//tools/whitelists/function_transition_whitelist"), "_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"),
},
)

9
tools/build_settings.bzl Normal file
View File

@ -0,0 +1,9 @@
BaseImageProvider = provider(fields = ["type"])
def _impl(ctx):
return BaseImageProvider(type = ctx.build_setting_value)
base_image = rule(
implementation = _impl,
build_setting = config.string(flag = True),
)

View File

@ -1,7 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@io_bazel_rules_docker//go:image.bzl", "go_image") 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//container:container.bzl", "container_bundle")
load("//tools:binary_targets.bzl", "binary_targets", "go_image_debug") load("//tools:binary_targets.bzl", "binary_targets", "go_image_alpine", "go_image_debug")
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push") load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
go_library( go_library(
@ -37,7 +37,11 @@ go_image(
"main.go", "main.go",
"usage.go", "usage.go",
], ],
base = "//tools:cc_image", base = select({
"//tools:base_image_alpine": "//tools:alpine_cc_image",
"//tools:base_image_cc": "//tools:cc_image",
"//conditions:default": "//tools:cc_image",
}),
goarch = "amd64", goarch = "amd64",
goos = "linux", goos = "linux",
importpath = "github.com/prysmaticlabs/prysm/validator", importpath = "github.com/prysmaticlabs/prysm/validator",
@ -76,6 +80,7 @@ container_bundle(
go_image_debug( go_image_debug(
name = "image_debug", name = "image_debug",
image = ":image", image = ":image",
tags = ["manual"],
) )
container_bundle( container_bundle(
@ -87,6 +92,21 @@ container_bundle(
tags = ["manual"], 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",
},
tags = ["manual"],
)
docker_push( docker_push(
name = "push_images", name = "push_images",
bundle = ":image_bundle", bundle = ":image_bundle",
@ -99,6 +119,12 @@ docker_push(
tags = ["manual"], tags = ["manual"],
) )
docker_push(
name = "push_images_alpine",
bundle = ":image_bundle_alpine",
tags = ["manual"],
)
go_binary( go_binary(
name = "validator", name = "validator",
embed = [":go_default_library"], embed = [":go_default_library"],