Skip to content

Commit

Permalink
Add alpine based docker images for validator and beacon chain (#5214)
Browse files Browse the repository at this point in the history
* Add alpine based images for validator and beacon chain

* Use an alpine image with glibc

* manual tags on transitional targets

* poke buildkite

* poke buildkite
  • Loading branch information
prestonvanloon authored Mar 26, 2020
1 parent e077d3d commit 3792bf6
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 4 deletions.
12 changes: 12 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ load(

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")

bls_dependencies()
Expand Down
30 changes: 28 additions & 2 deletions beacon-chain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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//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")

go_library(
Expand Down Expand Up @@ -37,7 +37,11 @@ go_image(
"main.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",
goos = "linux",
importpath = "github.com/prysmaticlabs/prysm/beacon-chain",
Expand Down Expand Up @@ -76,6 +80,7 @@ container_bundle(
go_image_debug(
name = "image_debug",
image = ":image",
tags = ["manual"],
)

container_bundle(
Expand All @@ -87,6 +92,21 @@ container_bundle(
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(
name = "push_images",
bundle = ":image_bundle",
Expand All @@ -99,6 +119,12 @@ docker_push(
tags = ["manual"],
)

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

go_binary(
name = "beacon-chain",
embed = [":go_default_library"],
Expand Down
24 changes: 24 additions & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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//cc:image.bzl", CC_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(
name = "kubesec",
Expand Down Expand Up @@ -61,3 +62,26 @@ container_image(
user = "root",
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"],
)
22 changes: 22 additions & 0 deletions tools/binary_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ build_in_debug_mode = transition(
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]
Expand All @@ -61,3 +72,14 @@ go_image_debug = rule(
"_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 changes: 9 additions & 0 deletions tools/build_settings.bzl
Original file line number Diff line number Diff line change
@@ -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),
)
30 changes: 28 additions & 2 deletions validator/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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//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")

go_library(
Expand Down Expand Up @@ -37,7 +37,11 @@ go_image(
"main.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",
goos = "linux",
importpath = "github.com/prysmaticlabs/prysm/validator",
Expand Down Expand Up @@ -76,6 +80,7 @@ container_bundle(
go_image_debug(
name = "image_debug",
image = ":image",
tags = ["manual"],
)

container_bundle(
Expand All @@ -87,6 +92,21 @@ container_bundle(
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(
name = "push_images",
bundle = ":image_bundle",
Expand All @@ -99,6 +119,12 @@ docker_push(
tags = ["manual"],
)

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

go_binary(
name = "validator",
embed = [":go_default_library"],
Expand Down

0 comments on commit 3792bf6

Please sign in to comment.