From e7b5d867d02265bae0d7a95318bb11448a0ab7eb Mon Sep 17 00:00:00 2001 From: Justin Trudell Date: Wed, 4 Dec 2024 17:17:53 -0800 Subject: [PATCH] [antlir2] Use disk for /tmp during rpm builds Summary: See https://fb.workplace.com/groups/codetestingqa/posts/9412044228875340/ -- this is causing issues on Sandcastle for some RPMs. Opt to broadly move to disk as I expect the perf cost to be minimal (we're just dumping artifacts into here post-build, not really doing a significant amount of I/O). I'll land this after the freeze. Test Plan: ``` $ buck2 run mode/opt -c antlir.rc_targets=all //registry/builder/rpm/tests:fb-rpm-builder-test.base -- --no-publish ... BUILD SUCCEEDED { "linux": { "aarch64": { "primary": "/data/users/jtru/fbsource/buck-out/v2/gen/fbcode/7377c200435b9daa/registry/builder/rpm/tests/__fb-rpm-builder-test.base--rpm-stripped--aarch64__/fb-rpm-builder-test.base--rpm-stripped--aarch64.rpm", "debug": "/data/users/jtru/fbsource/buck-out/v2/gen/fbcode/7377c200435b9daa/registry/builder/rpm/tests/__fb-rpm-builder-test.base--rpm-debuginfo--aarch64__/fb-rpm-builder-test.base--rpm-debuginfo--aarch64.rpm" }, "x86_64": { "primary": "/data/users/jtru/fbsource/buck-out/v2/gen/fbcode/fc0450a833f3ffe7/registry/builder/rpm/tests/__fb-rpm-builder-test.base--rpm-stripped--x86_64__/fb-rpm-builder-test.base--rpm-stripped--x86_64.rpm", "debug": "/data/users/jtru/fbsource/buck-out/v2/gen/fbcode/fc0450a833f3ffe7/registry/builder/rpm/tests/__fb-rpm-builder-test.base--rpm-debuginfo--x86_64__/fb-rpm-builder-test.base--rpm-debuginfo--x86_64.rpm" } } } ``` Reviewed By: naveedgol Differential Revision: D66508035 fbshipit-source-id: a10854694a03353e824440fc8778dfbce469cdbc --- antlir/antlir2/antlir2_packager/src/rpm.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/antlir/antlir2/antlir2_packager/src/rpm.rs b/antlir/antlir2/antlir2_packager/src/rpm.rs index e98e175461c..a78d86d0350 100644 --- a/antlir/antlir2/antlir2_packager/src/rpm.rs +++ b/antlir/antlir2/antlir2_packager/src/rpm.rs @@ -26,7 +26,6 @@ use nix::unistd::Group; use nix::unistd::Uid; use nix::unistd::User; use serde::Deserialize; -use tempfile::NamedTempFile; use crate::run_cmd; use crate::BuildAppliance; @@ -330,18 +329,18 @@ AutoProv: {autoprov} spec.push_str(extra_file); spec.push('\n'); } - let mut rpm_spec_file = - NamedTempFile::new().context("failed to create tempfile for rpm spec")?; - rpm_spec_file - .write(spec.as_bytes()) - .context("while writing rpm spec file")?; let output_dir = tempfile::tempdir().context("while creating temp dir for rpm output")?; - // create the arch-specific output dir explicitly so that it'll be // owned by the build user on the host, not root std::fs::create_dir(output_dir.path().join(arch)).context("while creating output dir")?; + // Note we use a standard dir for /tmp rather than tmpfs because we write full + // build artifacts here, and can thus easily run out of ramdisk + let tmp = tempfile::tempdir().context("while creating temp dir for rpm build")?; + let rpm_spec_file = tmp.path().join("rpmspec"); + std::fs::write(rpm_spec_file, spec.as_bytes()).context("while writing rpm spec file")?; + let mut isol_context = IsolationContext::builder(self.build_appliance.path()); isol_context .ephemeral(false) @@ -353,10 +352,9 @@ AutoProv: {autoprov} std::env::current_dir()?, )) .working_directory(Path::new("/__antlir2__/working_directory")) - .inputs((Path::new("/tmp/rpmspec"), rpm_spec_file.path())) .inputs((Path::new("/__antlir2__/root"), layer)) .outputs((Path::new("/__antlir2__/out"), output_dir.path())) - .tmpfs(Path::new("/tmp")) + .outputs((Path::new("/tmp"), tmp.path())) .tmpfs(Path::new("/dev")) .inputs(Path::new("/dev/null")); #[cfg(facebook)]