mirror of https://github.com/k3s-io/k3s
bazel: add docker_push rules
parent
5b7602a525
commit
8495f7c9ed
20
build/BUILD
20
build/BUILD
|
@ -2,7 +2,7 @@ package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
load("@io_k8s_repo_infra//defs:build.bzl", "release_filegroup")
|
load("@io_k8s_repo_infra//defs:build.bzl", "release_filegroup")
|
||||||
load(":code_generation_test.bzl", "code_generation_test_suite")
|
load(":code_generation_test.bzl", "code_generation_test_suite")
|
||||||
load(":container.bzl", "multi_arch_container")
|
load(":container.bzl", "multi_arch_container", "multi_arch_container_push")
|
||||||
load(":platforms.bzl", "SERVER_PLATFORMS", "for_platforms")
|
load(":platforms.bzl", "SERVER_PLATFORMS", "for_platforms")
|
||||||
|
|
||||||
code_generation_test_suite(
|
code_generation_test_suite(
|
||||||
|
@ -69,7 +69,12 @@ DOCKERIZED_BINARIES = {
|
||||||
for_server = ["//build/debs:%s-{ARCH}.deb" % binary],
|
for_server = ["//build/debs:%s-{ARCH}.deb" % binary],
|
||||||
only_os = "linux",
|
only_os = "linux",
|
||||||
)),
|
)),
|
||||||
docker_tags = ["k8s.gcr.io/%s:{{STABLE_DOCKER_TAG}}" % binary],
|
# Since the multi_arch_container macro replaces the {ARCH} format string,
|
||||||
|
# we need to escape the stamping vars.
|
||||||
|
# Also see comment above about why the push tags use ARCH while the
|
||||||
|
# non-push tags do not.
|
||||||
|
docker_push_tags = ["{{STABLE_DOCKER_PUSH_REGISTRY}}/%s-{ARCH}:{{STABLE_DOCKER_TAG}}" % binary],
|
||||||
|
docker_tags = ["{{STABLE_DOCKER_REGISTRY}}/%s:{{STABLE_DOCKER_TAG}}" % binary],
|
||||||
stamp = True,
|
stamp = True,
|
||||||
symlinks = {
|
symlinks = {
|
||||||
# Some cluster startup scripts expect to find the binaries in /usr/local/bin,
|
# Some cluster startup scripts expect to find the binaries in /usr/local/bin,
|
||||||
|
@ -80,6 +85,17 @@ DOCKERIZED_BINARIES = {
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
) for binary, meta in DOCKERIZED_BINARIES.items()]
|
) for binary, meta in DOCKERIZED_BINARIES.items()]
|
||||||
|
|
||||||
|
# Also roll up all images into a single bundle to push with one target.
|
||||||
|
multi_arch_container_push(
|
||||||
|
name = "server-images",
|
||||||
|
architectures = SERVER_PLATFORMS["linux"],
|
||||||
|
docker_tags_images = {
|
||||||
|
"{{STABLE_DOCKER_PUSH_REGISTRY}}/%s-{ARCH}:{{STABLE_DOCKER_TAG}}" % binary: "%s-internal" % binary
|
||||||
|
for binary in DOCKERIZED_BINARIES.keys()
|
||||||
|
},
|
||||||
|
tags = ["manual"],
|
||||||
|
)
|
||||||
|
|
||||||
[genrule(
|
[genrule(
|
||||||
name = binary + "_docker_tag",
|
name = binary + "_docker_tag",
|
||||||
srcs = [meta["target"]],
|
srcs = [meta["target"]],
|
||||||
|
|
|
@ -13,12 +13,16 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle", "container_image")
|
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle", "container_image")
|
||||||
|
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
|
||||||
load("//build:platforms.bzl", "go_platform_constraint")
|
load("//build:platforms.bzl", "go_platform_constraint")
|
||||||
|
|
||||||
# multi_arch_container produces a private internal container_image, multiple
|
# multi_arch_container produces a private internal container_image, multiple
|
||||||
# arch-specific tagged container_bundles (named NAME-ARCH) and aliases
|
# arch-specific tagged container_bundles (named NAME-ARCH) and aliases
|
||||||
# from NAME and NAME.tar to the appropriately NAME-ARCH container_bundle target
|
# from NAME and NAME.tar to the appropriately NAME-ARCH container_bundle target
|
||||||
# for the currently-configured architecture.
|
# for the currently-configured architecture.
|
||||||
|
# Additionally, if docker_push_tags is provided, uses multi_arch_container_push
|
||||||
|
# to create container_bundles named push-NAME-ARCH with the provided push tags,
|
||||||
|
# along with a push-NAME docker_push target.
|
||||||
# Args:
|
# Args:
|
||||||
# name: name used for the alias; the internal container_image and
|
# name: name used for the alias; the internal container_image and
|
||||||
# container_bundles are based on this name
|
# container_bundles are based on this name
|
||||||
|
@ -29,7 +33,10 @@ load("//build:platforms.bzl", "go_platform_constraint")
|
||||||
# docker_tags: list of docker tags to apply to the image. The format string
|
# docker_tags: list of docker tags to apply to the image. The format string
|
||||||
# {ARCH} will be replaced with the configured GOARCH; any stamping variables
|
# {ARCH} will be replaced with the configured GOARCH; any stamping variables
|
||||||
# should be escaped, e.g. {{STABLE_MY_VAR}}.
|
# should be escaped, e.g. {{STABLE_MY_VAR}}.
|
||||||
# tags: will be applied to all rules
|
# docker_push_tags: list of docker tags to apply to the image for pushing.
|
||||||
|
# The format string {ARCH} will be replaced with the configured GOARCH;
|
||||||
|
# any stamping variables should be escaped, e.g. {{STABLE_MY_VAR}}.
|
||||||
|
# tags: will be applied to all targets
|
||||||
# visiblity: will be applied only to the container_bundles; the internal
|
# visiblity: will be applied only to the container_bundles; the internal
|
||||||
# container_image is private
|
# container_image is private
|
||||||
# All other args will be applied to the internal container_image.
|
# All other args will be applied to the internal container_image.
|
||||||
|
@ -38,6 +45,7 @@ def multi_arch_container(
|
||||||
architectures,
|
architectures,
|
||||||
base,
|
base,
|
||||||
docker_tags,
|
docker_tags,
|
||||||
|
docker_push_tags = None,
|
||||||
tags = None,
|
tags = None,
|
||||||
visibility = None,
|
visibility = None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
@ -70,3 +78,45 @@ def multi_arch_container(
|
||||||
for arch in architectures
|
for arch in architectures
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if docker_push_tags:
|
||||||
|
multi_arch_container_push(
|
||||||
|
name = name,
|
||||||
|
architectures = architectures,
|
||||||
|
docker_tags_images = {docker_push_tag: ":%s-internal" % name for docker_push_tag in docker_push_tags},
|
||||||
|
tags = tags,
|
||||||
|
)
|
||||||
|
|
||||||
|
# multi_arch_container_push creates container_bundles named push-NAME-ARCH for
|
||||||
|
# the provided architectures, populating them with the images directory.
|
||||||
|
# It additionally creates a push-NAME docker_push rule which can be run to
|
||||||
|
# push the images to a Docker repository.
|
||||||
|
# Args:
|
||||||
|
# name: name used for targets created by this macro; the internal
|
||||||
|
# container_bundles are based on this name
|
||||||
|
# architectures: list of architectures (in GOARCH naming parlance) to
|
||||||
|
# configure
|
||||||
|
# docker_tags_images: dictionary mapping docker tag to the corresponding
|
||||||
|
# container_image target. The format string {ARCH} will be replaced
|
||||||
|
# in tags with the configured GOARCH; any stamping variables should be
|
||||||
|
# escaped, e.g. {{STABLE_MY_VAR}}.
|
||||||
|
# tags: applied to container_bundle targets
|
||||||
|
def multi_arch_container_push(
|
||||||
|
name,
|
||||||
|
architectures,
|
||||||
|
docker_tags_images,
|
||||||
|
tags = None):
|
||||||
|
for arch in architectures:
|
||||||
|
container_bundle(
|
||||||
|
name = "push-%s-%s" % (name, arch),
|
||||||
|
images = {tag.format(ARCH = arch): image for tag, image in docker_tags_images.items()},
|
||||||
|
tags = tags,
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
)
|
||||||
|
docker_push(
|
||||||
|
name = "push-%s" % name,
|
||||||
|
bundle = select({
|
||||||
|
go_platform_constraint(os = "linux", arch = arch): "push-%s-%s" % (name, arch)
|
||||||
|
for arch in architectures
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
|
@ -32,8 +32,10 @@ filegroup(
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: also add container_push rules,
|
# TODO: collect all relevant docker_push targets into one target that can be run:
|
||||||
# and don't forget about the conformance and hyperkube images
|
# //build:push-server-images
|
||||||
|
# //cluster/images/conformance:push-conformance
|
||||||
|
# //cluster/images/hyperkube:push-hyperkube
|
||||||
gcs_upload(
|
gcs_upload(
|
||||||
name = "push-build",
|
name = "push-build",
|
||||||
data = [
|
data = [
|
||||||
|
|
|
@ -28,9 +28,10 @@ multi_arch_container(
|
||||||
"-c",
|
"-c",
|
||||||
"/run_e2e.sh",
|
"/run_e2e.sh",
|
||||||
],
|
],
|
||||||
# {ARCH} is replaced by the macro, but STABLE_DOCKER_TAG is replaced by the
|
# {ARCH} is replaced by the macro, but STABLE_ vars are replaced by the
|
||||||
# build stamping, so we need to escape it
|
# build stamping, so we need to escape them
|
||||||
docker_tags = ["k8s.gcr.io/conformance-{ARCH}:{{STABLE_DOCKER_TAG}}"],
|
docker_push_tags = ["{{STABLE_DOCKER_PUSH_REGISTRY}}/conformance-{ARCH}:{{STABLE_DOCKER_TAG}}"],
|
||||||
|
docker_tags = ["{{STABLE_DOCKER_REGISTRY}}/conformance-{ARCH}:{{STABLE_DOCKER_TAG}}"],
|
||||||
env = {
|
env = {
|
||||||
"E2E_FOCUS": "\[Conformance\]",
|
"E2E_FOCUS": "\[Conformance\]",
|
||||||
"E2E_SKIP": "",
|
"E2E_SKIP": "",
|
||||||
|
|
|
@ -5,9 +5,10 @@ multi_arch_container(
|
||||||
name = "hyperkube",
|
name = "hyperkube",
|
||||||
architectures = SERVER_PLATFORMS["linux"],
|
architectures = SERVER_PLATFORMS["linux"],
|
||||||
base = "@debian-hyperkube-base-{ARCH}//image",
|
base = "@debian-hyperkube-base-{ARCH}//image",
|
||||||
# {ARCH} is replaced by the macro, but STABLE_DOCKER_TAG is replaced by the
|
# {ARCH} is replaced by the macro, but STABLE_ vars are replaced by the
|
||||||
# build stamping, so we need to escape it
|
# build stamping, so we need to escape them
|
||||||
docker_tags = ["k8s.gcr.io/hyperkube-{ARCH}:{{STABLE_DOCKER_TAG}}"],
|
docker_push_tags = ["{{STABLE_DOCKER_PUSH_REGISTRY}}/hyperkube-{ARCH}:{{STABLE_DOCKER_TAG}}"],
|
||||||
|
docker_tags = ["{{STABLE_DOCKER_REGISTRY}}/hyperkube-{ARCH}:{{STABLE_DOCKER_TAG}}"],
|
||||||
files = [
|
files = [
|
||||||
"//cmd/hyperkube",
|
"//cmd/hyperkube",
|
||||||
],
|
],
|
||||||
|
|
|
@ -38,6 +38,8 @@ STABLE_BUILD_SCM_REVISION ${KUBE_GIT_VERSION-}
|
||||||
STABLE_BUILD_MAJOR_VERSION ${KUBE_GIT_MAJOR-}
|
STABLE_BUILD_MAJOR_VERSION ${KUBE_GIT_MAJOR-}
|
||||||
STABLE_BUILD_MINOR_VERSION ${KUBE_GIT_MINOR-}
|
STABLE_BUILD_MINOR_VERSION ${KUBE_GIT_MINOR-}
|
||||||
STABLE_DOCKER_TAG ${KUBE_GIT_VERSION/+/_}
|
STABLE_DOCKER_TAG ${KUBE_GIT_VERSION/+/_}
|
||||||
|
STABLE_DOCKER_REGISTRY ${KUBE_DOCKER_REGISTRY:-k8s.gcr.io}
|
||||||
|
STABLE_DOCKER_PUSH_REGISTRY ${KUBE_DOCKER_PUSH_REGISTRY:-${KUBE_DOCKER_REGISTRY:-staging-k8s.gcr.io}}
|
||||||
gitCommit ${KUBE_GIT_COMMIT-}
|
gitCommit ${KUBE_GIT_COMMIT-}
|
||||||
gitTreeState ${KUBE_GIT_TREE_STATE-}
|
gitTreeState ${KUBE_GIT_TREE_STATE-}
|
||||||
gitVersion ${KUBE_GIT_VERSION-}
|
gitVersion ${KUBE_GIT_VERSION-}
|
||||||
|
|
Loading…
Reference in New Issue