Skip to content

Commit

Permalink
Make debs, rpms, and docker images multiarch
Browse files Browse the repository at this point in the history
  • Loading branch information
ixdy committed Feb 23, 2019
1 parent 7a938eb commit dfdfc2e
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 88 deletions.
33 changes: 25 additions & 8 deletions build/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"])
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle", "container_image")
load("@io_k8s_repo_infra//defs:build.bzl", "release_filegroup")
load(":code_generation_test.bzl", "code_generation_test_suite")
load(":platforms.bzl", "for_platforms")

code_generation_test_suite(
name = "code_generation_tests",
Expand Down Expand Up @@ -30,23 +31,38 @@ filegroup(
# in build/common.sh.
DOCKERIZED_BINARIES = {
"cloud-controller-manager": {
"base": "@debian-base-amd64//image",
"base": select(for_platforms(
for_node = "@debian-base-{ARCH}//image",
only_os = "linux",
)),
"target": "//cmd/cloud-controller-manager:cloud-controller-manager",
},
"kube-apiserver": {
"base": "@debian-base-amd64//image",
"base": select(for_platforms(
for_node = "@debian-base-{ARCH}//image",
only_os = "linux",
)),
"target": "//cmd/kube-apiserver:kube-apiserver",
},
"kube-controller-manager": {
"base": "@debian-base-amd64//image",
"base": select(for_platforms(
for_node = "@debian-base-{ARCH}//image",
only_os = "linux",
)),
"target": "//cmd/kube-controller-manager:kube-controller-manager",
},
"kube-scheduler": {
"base": "@debian-base-amd64//image",
"base": select(for_platforms(
for_node = "@debian-base-{ARCH}//image",
only_os = "linux",
)),
"target": "//cmd/kube-scheduler:kube-scheduler",
},
"kube-proxy": {
"base": "@debian-iptables-amd64//image",
"base": select(for_platforms(
for_node = "@debian-iptables-{ARCH}//image",
only_os = "linux",
)),
"target": "//cmd/kube-proxy:kube-proxy",
},
}
Expand All @@ -55,9 +71,10 @@ DOCKERIZED_BINARIES = {
name = binary + "-internal",
base = meta["base"],
cmd = ["/usr/bin/" + binary],
debs = [
"//build/debs:%s.deb" % binary,
],
debs = select(for_platforms(
for_node = ["//build/debs:%s-{ARCH}.deb" % binary],
only_os = "linux",
)),
stamp = True,
symlinks = {
# Some cluster startup scripts expect to find the binaries in /usr/local/bin,
Expand Down
155 changes: 101 additions & 54 deletions build/debs/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package(default_visibility = ["//visibility:public"])

load("@io_k8s_repo_infra//defs:deb.bzl", "k8s_deb", "deb_data")
load("@io_k8s_repo_infra//defs:deb.bzl", "deb_data", "k8s_deb")
load("@io_k8s_repo_infra//defs:build.bzl", "release_filegroup")
load("@io_k8s_repo_infra//defs:pkg.bzl", "pkg_tar")
load(
"//build:platforms.bzl",
"CLIENT_PLATFORMS",
"NODE_PLATFORMS",
"SERVER_PLATFORMS",
"for_platforms",
)
load("//build:workspace.bzl", "CNI_VERSION", "CRI_TOOLS_VERSION")

# We do not include kube-scheduler, kube-controller-manager,
Expand All @@ -12,44 +19,72 @@ load("//build:workspace.bzl", "CNI_VERSION", "CRI_TOOLS_VERSION")
# images.
release_filegroup(
name = "debs",
srcs = [
":cri-tools.deb",
":kubeadm.deb",
":kubectl.deb",
":kubelet.deb",
":kubernetes-cni.deb",
],
)
conditioned_srcs = for_platforms(
default = [],
for_client = [":kubectl-{ARCH}.deb"],
for_node = [
":cri-tools-{ARCH}.deb",
":kubeadm-{ARCH}.deb",
":kubelet-{ARCH}.deb",
":kubernetes-cni-{ARCH}.deb",
],
only_os = "linux",
),
)

# Create aliases from the non-arch names to the arch-specific names for backwards compatibility
alias(
name = "kubectl",
actual = select(for_platforms(
for_client = ":kubectl-{ARCH}",
only_os = "linux",
)),
)

[alias(
name = pkg,
actual = select(for_platforms(
for_node = ":%s-{ARCH}" % pkg,
only_os = "linux",
)),
) for pkg in [
"cri-tools",
"kubeadm",
"kubelet",
"kubernetes-cni",
]]

[deb_data(
name = binary,
name = "kubectl",
data = [
{
"files": ["//cmd/" + binary],
"files": ["//cmd/kubectl"],
"mode": "0755",
"dir": "/usr/bin",
},
],
) for binary in [
"cloud-controller-manager",
"kubectl",
"kube-apiserver",
"kube-controller-manager",
"kube-proxy",
]]
goarch = arch,
) for arch in CLIENT_PLATFORMS["linux"]]

deb_data(
name = "kube-scheduler",
[[deb_data(
name = binary,
data = [
{
"files": ["//cmd/kube-scheduler"],
"files": ["//cmd/" + binary],
"mode": "0755",
"dir": "/usr/bin",
},
],
)
goarch = arch,
) for binary in [
"cloud-controller-manager",
"kube-apiserver",
"kube-controller-manager",
"kube-proxy",
"kube-scheduler",
]] for arch in SERVER_PLATFORMS["linux"]]

deb_data(
[deb_data(
name = "kubelet",
data = [
{
Expand All @@ -63,9 +98,10 @@ deb_data(
"dir": "/lib/systemd/system",
},
],
)
goarch = arch,
) for arch in NODE_PLATFORMS["linux"]]

deb_data(
[deb_data(
name = "kubeadm",
data = [
{
Expand All @@ -89,63 +125,70 @@ deb_data(
"dir": "/etc/sysctl.d",
},
],
)
goarch = arch,
) for arch in NODE_PLATFORMS["linux"]]

pkg_tar(
name = "kubernetes-cni-data",
[pkg_tar(
name = "kubernetes-cni-data-%s" % goarch,
package_dir = "/opt/cni/bin",
deps = ["@kubernetes_cni//file"],
)
deps = ["@kubernetes_cni_%s//file" % goarch],
) for goarch in NODE_PLATFORMS["linux"]]

pkg_tar(
name = "cri-tools-data",
[pkg_tar(
name = "cri-tools-data-%s" % goarch,
package_dir = "/usr/bin",
deps = ["@cri_tools//file"],
)
deps = ["@cri_tools_%s//file" % goarch],
) for goarch in NODE_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "cloud-controller-manager",
description = "Kubernetes Cloud Controller Manager",
goarch = arch,
version_file = "//build:os_package_version",
)
) for arch in SERVER_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "kubectl",
description = """Kubernetes Command Line Tool
The Kubernetes command line tool for interacting with the Kubernetes API.
""",
goarch = arch,
version_file = "//build:os_package_version",
)
) for arch in CLIENT_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "kube-apiserver",
description = "Kubernetes API Server",
goarch = arch,
version_file = "//build:os_package_version",
)
) for arch in SERVER_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "kube-controller-manager",
description = "Kubernetes Controller Manager",
goarch = arch,
version_file = "//build:os_package_version",
)
) for arch in SERVER_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "kube-scheduler",
description = "Kubernetes Scheduler",
goarch = arch,
version_file = "//build:os_package_version",
)
) for arch in SERVER_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "kube-proxy",
depends = [
"iptables (>= 1.4.21)",
"iproute2",
],
description = "Kubernetes Service Proxy",
goarch = arch,
version_file = "//build:os_package_version",
)
) for arch in NODE_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "kubelet",
depends = [
"conntrack",
Expand All @@ -161,10 +204,11 @@ k8s_deb(
description = """Kubernetes Node Agent
The node agent of Kubernetes, the container cluster manager
""",
goarch = arch,
version_file = "//build:os_package_version",
)
) for arch in NODE_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "kubeadm",
depends = [
"kubelet (>= 1.8.0)",
Expand All @@ -175,23 +219,26 @@ k8s_deb(
description = """Kubernetes Cluster Bootstrapping Tool
The Kubernetes command line tool for bootstrapping a Kubernetes cluster.
""",
goarch = arch,
postinst = "postinst",
version_file = "//build:os_package_version",
)
) for arch in NODE_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "kubernetes-cni",
description = """Kubernetes Packaging of CNI
The Container Networking Interface tools for provisioning container networks.
""",
goarch = arch,
version = CNI_VERSION,
)
) for arch in NODE_PLATFORMS["linux"]]

k8s_deb(
[k8s_deb(
name = "cri-tools",
description = """Container Runtime Interface tools (crictl)""",
goarch = arch,
version = CRI_TOOLS_VERSION,
)
) for arch in NODE_PLATFORMS["linux"]]

filegroup(
name = "package-srcs",
Expand Down
36 changes: 36 additions & 0 deletions build/platforms.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,39 @@ TEST_PLATFORMS = {
"amd64",
],
}

def go_platform_constraint(os, arch):
return "@io_bazel_rules_go//go/platform:%s_%s" % (os, arch)

def _update_dict_for_platform_category(d, value, platforms, only_os = None):
if not value:
return
for os, arches in platforms.items():
if only_os and os != only_os:
continue
for arch in arches:
constraint = go_platform_constraint(os, arch)
if type(value) == "list":
d.setdefault(constraint, []).extend(
[v.format(OS = os, ARCH = arch) for v in value],
)
else:
if constraint in d:
fail("duplicate entry for constraint %s", constraint)
d[constraint] = value.format(OS = os, ARCH = arch)

def for_platforms(
for_client = None,
for_node = None,
for_server = None,
for_test = None,
default = None,
only_os = None):
d = {}
if default != None:
d["//conditions:default"] = default
_update_dict_for_platform_category(d, for_client, CLIENT_PLATFORMS, only_os)
_update_dict_for_platform_category(d, for_node, NODE_PLATFORMS, only_os)
_update_dict_for_platform_category(d, for_server, SERVER_PLATFORMS, only_os)
_update_dict_for_platform_category(d, for_test, TEST_PLATFORMS, only_os)
return d
Loading

0 comments on commit dfdfc2e

Please sign in to comment.