antlir/bzl/image_layer_runtime.bzl (36 lines of code) (raw):

# Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. load("@bazel_skylib//lib:shell.bzl", "shell") load(":image_utils.bzl", "image_utils") load(":oss_shim.bzl", "buck_command_alias") load(":query.bzl", "layer_deps_query") load(":target_helpers.bzl", "antlir_dep", "targets_and_outputs_arg_list") def _add_run_in_subvol_target(name, kind, extra_args = None): target = name + "=" + kind buck_command_alias( name = target, exe = antlir_dep("nspawn_in_subvol:run"), args = [ "--layer", "$(location {})".format(shell.quote(":" + name)), ] + (extra_args or []) + targets_and_outputs_arg_list( name = target, query = layer_deps_query( layer = image_utils.current_target(name), ), ), antlir_rule = "user-internal", ) def add_runtime_targets(layer, runtime): runtime = runtime or [] if "container" not in runtime: runtime.append("container") for elem in runtime: if elem == "container": _add_run_in_subvol_target(layer, "container") elif elem == "systemd": _add_run_in_subvol_target(layer, "systemd", extra_args = ["--boot", "--append-console"]) else: fail("Unsupported runtime encountered: {}".format(elem))