Skip to content

Commit a072df4

Browse files
committed
feat: NODE-1236 - Bazel base image target
1 parent 6c88412 commit a072df4

File tree

20 files changed

+620
-114
lines changed

20 files changed

+620
-114
lines changed

ic-os/bootloader/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ genrule(
1414
"bootloader-tree.tar",
1515
],
1616
cmd = "$(location build-bootloader-tree.sh) -o $@",
17+
tags = ["manual"],
1718
target_compatible_with = [
1819
"@platforms//os:linux",
1920
],
@@ -25,6 +26,7 @@ vfat_image(
2526
src = ":bootloader-tree.tar",
2627
partition_size = "100M",
2728
subdir = "boot/efi",
29+
tags = ["manual"],
2830
target_compatible_with = [
2931
"@platforms//os:linux",
3032
],

ic-os/defs.bzl

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ load("//bazel:defs.bzl", "gzip_compress", "sha256sum2url", "zstd_compress")
77
load("//bazel:output_files.bzl", "output_files")
88
load("//gitlab-ci/src/artifacts:upload.bzl", "upload_artifacts")
99
load("//ic-os/bootloader:defs.bzl", "build_grub_partition")
10-
load("//toolchains/sysimage:toolchain.bzl", "build_container_filesystem", "disk_image", "ext4_image", "sha256sum", "tar_extract", "upgrade_image")
10+
load("//toolchains/sysimage:toolchain.bzl", "build_container_base_image", "build_container_filesystem", "disk_image", "ext4_image", "sha256sum", "tar_extract", "upgrade_image")
1111

1212
def icos_build(
1313
name,
@@ -18,6 +18,7 @@ def icos_build(
1818
upgrades = True,
1919
vuln_scan = True,
2020
visibility = None,
21+
build_local_base_image = False,
2122
ic_version = "//bazel:version.txt"):
2223
"""
2324
Generic ICOS build tooling.
@@ -31,6 +32,7 @@ def icos_build(
3132
upgrades: if True, build upgrade images as well
3233
vuln_scan: if True, create targets for vulnerability scanning
3334
visibility: See Bazel documentation
35+
build_local_base_image: if True, build the base images from scratch. Do not download the docker.io base image.
3436
ic_version: the label pointing to the target that returns IC version
3537
"""
3638

@@ -67,13 +69,39 @@ def icos_build(
6769

6870
build_container_filesystem_config_file = Label(image_deps.get("build_container_filesystem_config_file"))
6971

70-
build_container_filesystem(
71-
name = "rootfs-tree.tar",
72-
context_files = [image_deps["container_context_files"]],
73-
config_file = build_container_filesystem_config_file,
74-
target_compatible_with = ["@platforms//os:linux"],
75-
tags = ["manual"],
76-
)
72+
if build_local_base_image:
73+
base_image_tag = "base-image-" + name # Reuse for build_container_filesystem_tar
74+
package_files_arg = "PACKAGE_FILES=packages.common"
75+
if "dev" in mode:
76+
package_files_arg += " packages.dev"
77+
78+
build_container_base_image(
79+
name = "base_image.tar",
80+
context_files = [image_deps["container_context_files"]],
81+
image_tag = base_image_tag,
82+
dockerfile = image_deps["base_dockerfile"],
83+
build_args = [package_files_arg],
84+
target_compatible_with = ["@platforms//os:linux"],
85+
tags = ["manual"],
86+
)
87+
88+
build_container_filesystem(
89+
name = "rootfs-tree.tar",
90+
context_files = [image_deps["container_context_files"]],
91+
config_file = build_container_filesystem_config_file,
92+
base_image_tar_file = ":base_image.tar",
93+
base_image_tar_file_tag = base_image_tag,
94+
target_compatible_with = ["@platforms//os:linux"],
95+
tags = ["manual"],
96+
)
97+
else:
98+
build_container_filesystem(
99+
name = "rootfs-tree.tar",
100+
context_files = [image_deps["container_context_files"]],
101+
config_file = build_container_filesystem_config_file,
102+
target_compatible_with = ["@platforms//os:linux"],
103+
tags = ["manual"],
104+
)
77105

78106
tar_extract(
79107
name = "file_contexts",
@@ -566,6 +594,7 @@ EOF
566594
":update-img-test.tar.gz",
567595
] if upgrades else []),
568596
visibility = visibility,
597+
tags = ["manual"] if build_local_base_image else [],
569598
)
570599

571600
# end def icos_build

ic-os/guestos/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ filegroup(
2121
ext4_image(
2222
name = "partition-config.tar",
2323
partition_size = "100M",
24+
tags = ["manual"],
2425
target_compatible_with = [
2526
"@platforms//os:linux",
2627
],

ic-os/guestos/defs.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def image_deps(mode, malicious = False):
1919
"""
2020

2121
deps = {
22+
"base_dockerfile": "//ic-os/guestos:rootfs/Dockerfile.base",
23+
2224
# Define rootfs and bootfs
2325
"bootfs": {
2426
# base layer
@@ -75,9 +77,17 @@ def image_deps(mode, malicious = False):
7577
"dev": {
7678
"build_container_filesystem_config_file": "//ic-os/guestos/envs/dev:build_container_filesystem_config.txt",
7779
},
80+
"local-base-dev": {
81+
# Use the non-local-base file
82+
"build_container_filesystem_config_file": "//ic-os/guestos/envs/dev:build_container_filesystem_config.txt",
83+
},
7884
"dev-malicious": {
7985
"build_container_filesystem_config_file": "//ic-os/guestos/envs/dev-malicious:build_container_filesystem_config.txt",
8086
},
87+
"local-base-prod": {
88+
# Use the non-local-base file
89+
"build_container_filesystem_config_file": "//ic-os/guestos/envs/prod:build_container_filesystem_config.txt",
90+
},
8191
"prod": {
8292
"build_container_filesystem_config_file": "//ic-os/guestos/envs/prod:build_container_filesystem_config.txt",
8393
},
@@ -90,6 +100,9 @@ def image_deps(mode, malicious = False):
90100
"dev": {
91101
"//ic-os/guestos:rootfs/allow_console_root": "/etc/allow_console_root:0644",
92102
},
103+
"local-base-dev": {
104+
"//ic-os/guestos:rootfs/allow_console_root": "/etc/allow_console_root:0644",
105+
},
93106
}
94107

95108
deps["rootfs"].update(extra_rootfs_deps.get(mode, {}))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("//ic-os:defs.bzl", "icos_build")
2+
load("//ic-os/guestos:defs.bzl", "image_deps")
3+
4+
exports_files(["build_container_filesystem_config.txt"])
5+
6+
# The macro contains several targets.
7+
# Check
8+
# //ic-os/guestos/BUILD.bazel for examples
9+
# or //ic-os/defs.bzl for the full list of targets.
10+
icos_build(
11+
name = "local-base-dev",
12+
build_local_base_image = True,
13+
ic_version = "//bazel:rc_only_version.txt",
14+
image_deps_func = image_deps,
15+
upload_prefix = None, # Do not upload locally built base images
16+
visibility = ["//visibility:public"],
17+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("//ic-os:defs.bzl", "icos_build")
2+
load("//ic-os/guestos:defs.bzl", "image_deps")
3+
4+
exports_files(["build_container_filesystem_config.txt"])
5+
6+
# The macro contains several targets.
7+
# Check
8+
# //ic-os/guestos/BUILD.bazel for examples
9+
# or //ic-os/defs.bzl for the full list of targets.
10+
icos_build(
11+
name = "local-base-prod",
12+
build_local_base_image = True,
13+
image_deps_func = image_deps,
14+
upload_prefix = None, # Do not upload locally built base images
15+
visibility = ["//visibility:public"],
16+
)

ic-os/hostos/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ filegroup(
1919
ext4_image(
2020
name = "partition-config.tar",
2121
partition_size = "100M",
22+
tags = ["manual"],
2223
target_compatible_with = [
2324
"@platforms//os:linux",
2425
],

ic-os/hostos/defs.bzl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def image_deps(mode, _malicious = False):
2121
"""
2222

2323
deps = {
24+
"base_dockerfile": "//ic-os/hostos:rootfs/Dockerfile.base",
25+
2426
# Define rootfs and bootfs
2527
"bootfs": {
2628
# base layer
@@ -57,6 +59,14 @@ def image_deps(mode, _malicious = False):
5759
"dev": {
5860
"build_container_filesystem_config_file": "//ic-os/hostos/envs/dev:build_container_filesystem_config.txt",
5961
},
62+
"local-base-dev": {
63+
# Use the non-local-base file
64+
"build_container_filesystem_config_file": "//ic-os/hostos/envs/dev:build_container_filesystem_config.txt",
65+
},
66+
"local-base-prod": {
67+
# Use the non-local-base file
68+
"build_container_filesystem_config_file": "//ic-os/hostos/envs/prod:build_container_filesystem_config.txt",
69+
},
6070
"prod": {
6171
"build_container_filesystem_config_file": "//ic-os/hostos/envs/prod:build_container_filesystem_config.txt",
6272
},
@@ -82,7 +92,7 @@ def _custom_partitions():
8292
pv_uuid = "eu0VQE-HlTi-EyRc-GceP-xZtn-3j6t-iqEwyv",
8393
# The image is pretty big, therefore it is usually much faster to just rebuild it instead of fetching from the cache.
8494
# TODO(IDX-2221): remove this when CI jobs and bazel infrastructure will run in the same clusters.
85-
tags = ["no-remote-cache"],
95+
tags = ["no-remote-cache", "manual"],
8696
target_compatible_with = [
8797
"@platforms//os:linux",
8898
],
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("//ic-os:defs.bzl", "icos_build")
2+
load("//ic-os/hostos:defs.bzl", "image_deps")
3+
4+
exports_files(["build_container_filesystem_config.txt"])
5+
6+
# The macro contains several targets.
7+
# Check
8+
# //ic-os/hostos/BUILD.bazel for examples
9+
# or //ic-os/defs.bzl for the full list of targets.
10+
icos_build(
11+
name = "local-base-dev",
12+
build_local_base_image = True,
13+
ic_version = "//bazel:rc_only_version.txt",
14+
image_deps_func = image_deps,
15+
upload_prefix = None, # Do not upload locally built base images
16+
visibility = ["//visibility:public"],
17+
vuln_scan = False,
18+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("//ic-os:defs.bzl", "icos_build")
2+
load("//ic-os/hostos:defs.bzl", "image_deps")
3+
4+
exports_files(["build_container_filesystem_config.txt"])
5+
6+
# The macro contains several targets.
7+
# Check
8+
# //ic-os/hostos/BUILD.bazel for examples
9+
# or //ic-os/defs.bzl for the full list of targets.
10+
icos_build(
11+
name = "local-base-prod",
12+
build_local_base_image = True,
13+
image_deps_func = image_deps,
14+
upload_prefix = None, # Do not upload locally built base images
15+
visibility = ["//visibility:public"],
16+
vuln_scan = False,
17+
)

0 commit comments

Comments
 (0)