Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions backend/aurcache/src/builder/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Builder {
);

let pkgname = self.package_model.name.get()?;
let host_active_build_path = create_active_build_path(pkgname.to_string())?;
let host_active_build_path = create_active_build_path(pkgname)?;

let create_info = self
.create_build_container(target_platform, BUILDER_IMAGE)
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Builder {
"Build {}: Remove shared build folder",
self.build_model.id.get()?
);
fs::remove_dir(host_active_build_path)?;
fs::remove_dir_all(host_active_build_path)?;
Ok(())
}

Expand Down Expand Up @@ -266,7 +266,7 @@ impl Builder {

/// move built files from build container to host and add them to the repo
async fn move_and_add_pkgs(&self, host_build_path: PathBuf) -> anyhow::Result<()> {
let archive_paths = fs::read_dir(host_build_path.clone())?.collect::<Vec<_>>();
let archive_paths: Vec<_> = fs::read_dir(&host_build_path)?.collect::<Result<_, _>>()?;
if archive_paths.is_empty() {
bail!("No files found in build directory");
}
Expand Down Expand Up @@ -299,18 +299,23 @@ impl Builder {
}

for archive in archive_paths {
let archive = archive?;
let archive_name = archive
.file_name()
.to_str()
.ok_or(anyhow!("Failed to get string from filename"))?
.to_string();

// Archives could end in .tar, .tar.zst, .tar.lz4, ...
if !archive_name.contains(".pkg.tar") {
continue;
}

let pkg_path = format!(
"./repo/{}/{}",
self.build_model.platform.get()?,
archive_name
);
fs::copy(archive.path(), pkg_path.clone())?;
fs::copy(archive.path(), &pkg_path)?;
// remove old file from shared path
fs::remove_file(archive.path())?;

Expand Down
36 changes: 19 additions & 17 deletions backend/aurcache/src/builder/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ impl Builder {

let build_flags = self.package_model.build_flags.get()?.split(";").join(" ");
// create new docker container for current build
let build_dir_base = "/var/cache/makepkg/pkg";
let host_build_path_docker = match get_build_mode() {
let host_build_dir = match get_build_mode() {
BuildMode::DinD(cfg) => cfg.aurcache_build_path,
BuildMode::Host(cfg) => cfg.build_artifact_dir_host,
};
let mountpoints = vec![format!("{}:{}", host_build_path_docker, build_dir_base)];
let container_build_dir = "/build";
let mountpoints = vec![format!("{}/{name}:{}", host_build_dir, container_build_dir)];

let mut mounts = vec![];

Expand Down Expand Up @@ -176,13 +176,22 @@ impl Builder {
mounts.push(mnt);
}

let (makepkg_config, makepkg_config_path) =
create_makepkg_config(name.clone(), build_dir_base)?;
let (makepkg_config, makepkg_config_path) = create_makepkg_config(container_build_dir)?;

// Note that `paru -G {name}` will download the pkgbase of {name},
// which might be a different name if it's a split package.
let build_cmd = format!(
"sudo pacman-key --init && sudo pacman-key --populate archlinux && paru {build_flags} {name}"
"
cd {container_build_dir}
paru -G {name}
paru {build_flags} *
"
);
info!("Build command: {build_cmd}");
let cmd = format!("cat <<EOF > {makepkg_config_path}\n{makepkg_config}\nEOF\n{build_cmd}");
let cmd = format!(
"cat <<EOF > {makepkg_config_path}\n{makepkg_config}\nEOF
{build_cmd}"
);

let (cpu_limit, memory_limit) = limits_from_env();

Expand All @@ -191,23 +200,16 @@ impl Builder {

let build_id = self.build_model.id.get()?;
let container_name = format!("aurcache_build_{filtered_name}_{build_id}");
let auto_remove = cfg!(not(debug_assertions));
let conf = ContainerCreateBody {
image: Some(image_name.to_string()),
attach_stdout: Some(true),
attach_stderr: Some(true),
open_stdin: Some(false),
user: Some("ab".to_string()),
cmd: Some(vec![
"sh".to_string(),
"-l".to_string(),
"-c".to_string(),
cmd,
]),
cmd: Some(vec!["sh".to_string(), "-lec".to_string(), cmd]),
host_config: Some(HostConfig {
#[cfg(debug_assertions)]
auto_remove: Some(false),
#[cfg(not(debug_assertions))]
auto_remove: Some(true),
auto_remove: Some(auto_remove),
nano_cpus: Some(cpu_limit as i64),
memory_swap: Some(memory_limit),
binds: Some(mountpoints),
Expand Down
10 changes: 4 additions & 6 deletions backend/aurcache/src/builder/makepkg_utils.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
pub fn create_makepkg_config(
name: String,
build_dir_base: &str,
) -> anyhow::Result<(String, String)> {
pub fn create_makepkg_config(build_dir_base: &str) -> anyhow::Result<(String, String)> {
let makepkg_config = format!(
"\
"
MAKEFLAGS=-j$(nproc)
PKGDEST={build_dir_base}/{name}"
PKGDEST={build_dir_base}
"
);
let makepkg_config_path = "/var/ab/.config/pacman/makepkg.conf";
Ok((makepkg_config, makepkg_config_path.to_string()))
Expand Down
10 changes: 4 additions & 6 deletions backend/aurcache/src/builder/path_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use std::os::unix::fs::PermissionsExt;
use std::path::PathBuf;
use std::{env, fs};

pub fn create_active_build_path(pkg_name: String) -> anyhow::Result<PathBuf> {
pub fn create_active_build_path(pkg_name: &str) -> anyhow::Result<PathBuf> {
// this path is hardcoded at /app/builds/<pkgname>
let mut path = env::current_dir()?;
path.push("builds");
path.push(pkg_name);
fs::create_dir_all(path.clone())?;
fs::set_permissions(path.clone(), Permissions::from_mode(0o777))?;
let path = env::current_dir()?.join("builds").join(pkg_name);
fs::create_dir_all(&path)?;
fs::set_permissions(&path, Permissions::from_mode(0o777))?;

Ok(path)
}
2 changes: 1 addition & 1 deletion backend/aurcache/src/package/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn package_add(
};
let build_flags = build_flags.unwrap_or_else(|| {
vec![
"-Syu".to_string(),
"-B".to_string(),
"--noconfirm".to_string(),
"--noprogressbar".to_string(),
"--color never".to_string(),
Expand Down