Skip to content

Commit

Permalink
[antlir2] Install Chef planned fbpkgs
Browse files Browse the repository at this point in the history
Summary: Install chef `planned` fbpkgs.

Test Plan:
Chef bloats images with lots of new files so unfortunately `image-diff-test` cannot be used here.  Replaced it with `image_sh_test`

```
$ buck2 test fbcode//antlir/antlir2/test_images/facebook/chef_solo/fbpkg:chef-image-test
Buck UI: https://www.internalfb.com/buck2/3ee09bbe-7dc2-4905-a507-a0f152350a30
Test UI: https://www.internalfb.com/intern/testinfra/testrun/2251800001295617
Network: Up: 0 B  Down: 0 B
Jobs completed: 4. Time elapsed: 4.2s.
Tests finished: Pass 1. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: epilatow

Differential Revision: D47351564

fbshipit-source-id: 6613bf6723983576d641826e3360c868dda02cf7
  • Loading branch information
Serge Dubrouski authored and facebook-github-bot committed Jul 19, 2023
1 parent 61f8715 commit bc90d8b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
7 changes: 7 additions & 0 deletions antlir/antlir2/antlir2/src/cmd/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ struct SetupArgs {
output: PathBuf,
#[clap(flatten)]
dnf: super::DnfCompileishArgs,
#[cfg(facebook)]
#[clap(flatten)]
fbpkg: super::FbpkgCompileishArgs,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -199,6 +202,8 @@ impl Map {
root: subvol.path().to_owned(),
external: compileish,
dnf: self.setup.dnf,
#[cfg(facebook)]
fbpkg: self.setup.fbpkg,
},
external,
}
Expand All @@ -216,6 +221,8 @@ impl Map {
root: subvol.path().to_owned(),
external: compileish,
dnf: self.setup.dnf,
#[cfg(facebook)]
fbpkg: self.setup.fbpkg,
},
external,
}
Expand Down
24 changes: 24 additions & 0 deletions antlir/antlir2/antlir2/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ mod depgraph;
mod map;
mod plan;
mod shell;
#[cfg(facebook)]
use antlir2_compile::facebook::FbpkgContext;
#[cfg(facebook)]
use antlir2_compile::facebook::ResolvedFbpkgInfoJsonFile;
pub(crate) use compile::Compile;
pub(crate) use depgraph::Depgraph;
pub(crate) use map::Map;
Expand All @@ -48,6 +52,9 @@ pub(self) struct Compileish {
pub(crate) external: CompileishExternal,
#[clap(flatten)]
pub(crate) dnf: DnfCompileishArgs,
#[cfg(facebook)]
#[clap(flatten)]
pub(crate) fbpkg: FbpkgCompileishArgs,
}

#[derive(Parser, Debug)]
Expand All @@ -63,6 +70,14 @@ pub(self) struct DnfCompileishArgs {
pub(crate) excluded_rpms: Option<JsonFile<BTreeSet<String>>>,
}

#[cfg(facebook)]
#[derive(Parser, Debug)]
pub(self) struct FbpkgCompileishArgs {
#[clap(long = "resolved-fbpkgs")]
/// Path to resolced fbpkgs json file
pub(crate) resolved_fbpkgs: Option<ResolvedFbpkgInfoJsonFile>,
}

#[derive(Parser, Debug)]
/// Compile arguments that are _always_ passed from external sources (in other
/// words, by buck2 actions) and are never generated by internal code in the
Expand Down Expand Up @@ -96,6 +111,8 @@ impl Compileish {
versionlock: dnf_versionlock,
excluded_rpms: dnf_excluded_rpms,
},
#[cfg(facebook)]
fbpkg: FbpkgCompileishArgs { resolved_fbpkgs },
} = self;
let mut v = vec![
Cow::Borrowed(OsStr::new("--label")),
Expand All @@ -117,6 +134,11 @@ impl Compileish {
v.push(Cow::Borrowed(OsStr::new("--dnf-excluded-rpms")));
v.push(Cow::Borrowed(excluded_rpms.path().as_os_str()));
}
#[cfg(facebook)]
if let Some(resolved_fbpkgs) = resolved_fbpkgs {
v.push(Cow::Borrowed(OsStr::new("--resolved-fbpkgs")));
v.push(Cow::Borrowed(resolved_fbpkgs.path().as_os_str()));
}
for dep in image_dependencies {
v.push(Cow::Borrowed(OsStr::new("--image-dependency")));
v.push(Cow::Borrowed(dep.as_os_str()));
Expand All @@ -143,6 +165,8 @@ impl Compileish {
.unwrap_or_default(),
),
plan,
#[cfg(facebook)]
FbpkgContext::new(self.fbpkg.resolved_fbpkgs.clone()),
)
.map_err(Error::Compile)
}
Expand Down
8 changes: 7 additions & 1 deletion antlir/antlir2/antlir2_compile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod clone;
mod ensure_dir_exists;
mod extract;
#[cfg(facebook)]
mod facebook;
pub mod facebook;
mod genrule;
mod install;
pub mod plan;
Expand Down Expand Up @@ -101,6 +101,9 @@ pub struct CompilerContext {
dnf: DnfContext,
/// Pre-computed plan for this compilation phase
plan: Option<plan::Plan>,
#[cfg(facebook)]
/// Resolved fbpkgs from plan
fbpkg: facebook::FbpkgContext,
}

#[derive(Debug)]
Expand Down Expand Up @@ -163,13 +166,16 @@ impl CompilerContext {
root: PathBuf,
dnf: DnfContext,
plan: Option<plan::Plan>,
#[cfg(facebook)] fbpkg: facebook::FbpkgContext,
) -> Result<Self> {
Ok(Self {
label,
target_arch,
root,
dnf,
plan,
#[cfg(facebook)]
fbpkg,
})
}

Expand Down
23 changes: 23 additions & 0 deletions antlir/antlir2/bzl/image/layer.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

# @lint-ignore-every BUCKFORMAT

load("//antlir/antlir2/bzl:build_phase.bzl", "BuildPhase", "build_phase")
load("//antlir/antlir2/bzl:compat.bzl", "compat")
load("//antlir/antlir2/bzl:lazy.bzl", "lazy")
Expand All @@ -13,6 +15,7 @@ load("//antlir/antlir2/bzl/feature:defs.bzl", "feature")
load("//antlir/bzl:build_defs.bzl", "alias")
load("//antlir/bzl:constants.bzl", "REPO_CFG")
load("//antlir/rpm/dnf2buck:repo.bzl", "RepoSetInfo")
# @oss-disable
load("//antlir/bzl/build_defs.bzl", "config", "get_visibility")
load(":depgraph.bzl", "build_depgraph")
load(":mounts.bzl", "all_mounts", "nspawn_mount_args")
Expand Down Expand Up @@ -92,6 +95,7 @@ def _impl(ctx: "context") -> ["provider"]:
# expect it in starlark instead of a cli/json projection.
all_features = list(ctx.attrs.features[FeatureInfo].features.traverse())

# @oss-disable
dnf_available_repos = (ctx.attrs.dnf_available_repos or flavor_info.dnf_info.default_repo_set)[RepoSetInfo]
dnf_repodatas = repodata_only_local_repos(ctx, dnf_available_repos)
dnf_versionlock = ctx.attrs.dnf_versionlock or flavor_info.dnf_info.default_versionlock
Expand Down Expand Up @@ -211,16 +215,29 @@ def _impl(ctx: "context") -> ["provider"]:
plan,
flavor_info.dnf_info.reflink_flavor,
)

# @oss-disable
# @oss-disable
# @oss-disable
# @oss-disable
# @oss-disable
# @oss-disable
else:
plan = None
dnf_repos_dir = ctx.actions.symlinked_dir(identifier_prefix + "empty-dnf-repos", {})
# @oss-disable
# @oss-disable

logs["compile"] = ctx.actions.declare_output(identifier_prefix + "compile.log")
# @oss-disable
# @oss-disable

cmd, final_subvol = _map_image(
build_appliance = build_appliance[LayerInfo],
cmd = cmd_args(
cmd_args(dnf_repos_dir, format = "--dnf-repos={}"),
cmd_args(dnf_versionlock, format = "--dnf-versionlock={}") if dnf_versionlock else cmd_args(),
# @oss-disable
"compile",
compileish_args,
cmd_args(plan, format = "--plan={}") if plan else cmd_args(),
Expand Down Expand Up @@ -336,6 +353,12 @@ _layer = rule(
impl = _impl,
attrs = {
"antlir_internal_build_appliance": attrs.bool(default = False, doc = "mark if this image is a build appliance and is allowed to not have a flavor"),
# @oss-disable
# @oss-disable
# @oss-disable
# @oss-disable
# @oss-disable
# @oss-disable
"build_appliance": attrs.option(
attrs.dep(providers = [LayerInfo]),
default = None,
Expand Down

0 comments on commit bc90d8b

Please sign in to comment.