Skip to content

Commit

Permalink
[antlir2][migration] add back 'default_mountpoint'
Browse files Browse the repository at this point in the history
Summary:
Re-implement `default_mountpoint` which was removed a while ago but turns out
we actually do need to reasonably auto-migrate images that do `layer_mount`s of
fbpkgs.

Test Plan:
```
❯ buck audit providers fbcode//bot_generated/antlir/fbpkg/db:zoncolan.tools/latest-USE-fbpkg.fetched_layer.antlir2
...
DefaultMountpointInfo( default_mountpoint="/packages/zoncolan.tools" )
```

Reviewed By: justintrudell

Differential Revision: D50080493

fbshipit-source-id: 47febd3ef0bd85602c9f500cf834d1d0147d30f8
  • Loading branch information
vmagro authored and facebook-github-bot committed Oct 10, 2023
1 parent 5c97fde commit dea97df
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
62 changes: 45 additions & 17 deletions antlir/antlir2/bzl/feature/mount.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ load("//antlir/antlir2/features:defs.bzl", "FeaturePluginInfo")
load("//antlir/bzl:target_helpers.bzl", "antlir_dep")
load("//antlir/bzl:types.bzl", "types")
load(":dependency_layer_info.bzl", "layer_dep", "layer_dep_analyze")
load(":ensure_dirs_exist.bzl", "ensure_subdirs_exist")
load(":ensure_dirs_exist.bzl", "ensure_dir_exists_analyze", "ensure_subdirs_exist")
load(":feature_info.bzl", "FeatureAnalysis", "ParseTimeDependency", "ParseTimeFeature")
load(":install.bzl", "install")

# IMO this is a misfeature, but it is used in many places throughout the legacy
# antlir1 world so we need to keep it around for a while
DefaultMountpointInfo = provider(fields = ["default_mountpoint"])

def layer_mount(
*,
source: str | Select,
Expand All @@ -27,6 +31,12 @@ def layer_mount(
deps = {
"source": ParseTimeDependency(dep = source, providers = [LayerInfo]),
},
exec_deps = {
"ensure_dir_exists_plugin": ParseTimeDependency(
dep = antlir2_dep("features:ensure_dir_exists"),
providers = [FeaturePluginInfo],
),
},
kwargs = {
"host_source": None,
"is_directory": None,
Expand All @@ -37,14 +47,14 @@ def layer_mount(
),
]

# TODO(T153572212): antlir2 requires the image author to pre-create the mountpoint
if mkdir or (_implicit_from_antlir1 and mountpoint):
features.extend(
ensure_subdirs_exist(
into_dir = paths.dirname(mountpoint),
subdirs_to_create = paths.basename(mountpoint),
),
)
if not _implicit_from_antlir1 and not mountpoint:
fail("antlir2 layer_mount requires mountpoint to be set")

if mkdir:
features.extend(ensure_subdirs_exist(
into_dir = paths.dirname(mountpoint),
subdirs_to_create = paths.basename(mountpoint),
))
return features

def host_mount(
Expand All @@ -66,10 +76,15 @@ def host_mount(
"_implicit_from_antlir1": False,
},
deps = {},
exec_deps = {
"ensure_dir_exists_plugin": ParseTimeDependency(
dep = antlir2_dep("features:ensure_dir_exists"),
providers = [FeaturePluginInfo],
),
},
)]

# TODO(T153572212): antlir2 requires the image author to pre-create the mountpoint
if create_mountpoint or (_implicit_from_antlir1 and mountpoint):
if create_mountpoint or _implicit_from_antlir1:
if is_directory:
features.extend(
ensure_subdirs_exist(
Expand Down Expand Up @@ -117,12 +132,14 @@ def mount_analyze(
host_source: str | None,
_implicit_from_antlir1: bool,
plugin: FeaturePluginInfo,
deps: dict[str, Dependency] = {}) -> FeatureAnalysis:
deps: dict[str, Dependency] = {},
exec_deps: dict[str, Dependency] = {}) -> list[FeatureAnalysis]:
features = []
if source_kind == "layer":
source = deps.pop("source")
if not mountpoint:
mountpoint = source[LayerInfo].default_mountpoint
return FeatureAnalysis(
mountpoint = source[DefaultMountpointInfo].default_mountpoint
features.append(FeatureAnalysis(
feature_type = "mount",
data = mount_record(
layer = layer_mount_record(
Expand All @@ -133,9 +150,9 @@ def mount_analyze(
),
required_layers = [source[LayerInfo]],
plugin = plugin,
)
))
elif source_kind == "host":
return FeatureAnalysis(
features.append(FeatureAnalysis(
feature_type = "mount",
data = mount_record(
host = host_mount_record(
Expand All @@ -146,6 +163,17 @@ def mount_analyze(
layer = None,
),
plugin = plugin,
)
))
else:
fail("invalid source_kind '{}'".format(source_kind))

# TODO(T153572212): antlir2 requires the image author to pre-create the mountpoint
if _implicit_from_antlir1:
features.append(ensure_dir_exists_analyze(
dir = mountpoint,
mode = 0o755,
user = "root",
group = "root",
plugin = exec_deps["ensure_dir_exists_plugin"][FeaturePluginInfo],
))
return features
6 changes: 6 additions & 0 deletions antlir/antlir2/bzl/image/layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ load("//antlir/antlir2/bzl/dnf:defs.bzl", "compiler_plan_to_local_repos", "repod
load("//antlir/antlir2/bzl/feature:feature.bzl", "feature_attrs", "feature_rule", "regroup_features", "shared_features_attrs")
load(
"//antlir/antlir2/bzl/feature:mount.bzl",
"DefaultMountpointInfo",
"mount_record", # @unused Used as type
)
# @oss-disable
Expand Down Expand Up @@ -441,6 +442,10 @@ def _impl_with_features(features: ProviderCollection, *, ctx: AnalysisContext) -
providers.append(
_implicit_image_test(final_subvol, ctx.attrs._implicit_image_test[ExternalRunnerTestInfo]),
)

if ctx.attrs.default_mountpoint:
providers.append(DefaultMountpointInfo(default_mountpoint = ctx.attrs.default_mountpoint))

return providers

_layer_attrs = {
Expand All @@ -450,6 +455,7 @@ _layer_attrs = {
attrs.dep(providers = [LayerInfo]),
default = None,
),
"default_mountpoint": attrs.option(attrs.string(), default = None),
"dnf_additional_repos": attrs.list(
attrs.one_of(
attrs.dep(providers = [RepoInfo]),
Expand Down
1 change: 1 addition & 0 deletions antlir/bzl/fetched_package_layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def _fetched_package_layer(
"antlir_fetched_package__name={}".format(package),
"antlir_fetched_package__tag={}".format(tag),
],
antlir2_default_mountpoint = "/packages/" + package,
)

# Deliberately not usable stand-alone, use `fetched_package_layers_from_db`
Expand Down
2 changes: 2 additions & 0 deletions antlir/bzl/image_layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def image_layer(
antlir2_features = [],
antlir1_features = [],
antlir2_allow_ignored_flavor_config_override: bool = False,
antlir2_default_mountpoint: str | None = None,
**image_layer_kwargs):
"""
Arguments
Expand Down Expand Up @@ -157,6 +158,7 @@ def image_layer(
visibility = get_visibility(image_layer_kwargs.get("visibility")),
# Antlir1 provisioning images explicitly install package-devel stub, we need to allow them here.
dnf_excluded_rpms = ["aziot-identity-service"],
default_mountpoint = antlir2_default_mountpoint,
)
else:
antlir2_shim.fake_buck1_layer(name = name)
Expand Down

0 comments on commit dea97df

Please sign in to comment.