From 76d7118df891decb903e9cb2c99f07e94da9aae0 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 28 Jun 2025 04:35:30 +0200 Subject: [PATCH] fix build --- src/main.rs | 69 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/src/main.rs b/src/main.rs index bba0c79..3f6de67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,25 +56,22 @@ async fn launch(config: String) { ..Default::default() }) .mount_assets() - .mount( - "/", - routes![ - routes::index_page, - routes::pkg_route, - routes::push::upload_pkg, - routes::user::login, - routes::user::login_post, - routes::user::account_page, - routes::ui::pkg_ui, - routes::ui::repo_ui, - routes::user::new_api_key, - routes::user::end_session, - routes::user::change_password, - routes::user::change_password_post, - routes::ui::repo::repo_arch_json, - routes::ui::pkg::pkg_json - ], - ) + .mount("/", routes![ + routes::index_page, + routes::pkg_route, + routes::push::upload_pkg, + routes::user::login, + routes::user::login_post, + routes::user::account_page, + routes::ui::pkg_ui, + routes::ui::repo_ui, + routes::user::new_api_key, + routes::user::end_session, + routes::user::change_password, + routes::user::change_password_post, + routes::ui::repo::repo_arch_json, + routes::ui::pkg::pkg_json + ]) .manage(config) .manage(shell) .launch() @@ -89,27 +86,36 @@ pub fn build(image: &str, ci: bool) { let current_dir = std::env::current_dir().expect("Failed to get current directory"); let uid = nix::unistd::Uid::current().as_raw(); - let move_pkg = format!("rsync -a --chown={uid}:{uid} /build/*.pkg.tar.* /workdir/"); - + // Gather signing key let sign_key = std::env::var("SIGN_KEY"); // Build the Docker command let mut docker_script = vec![ "set -e".to_string(), + "pacman-key --init".to_string(), + "pacman-key --populate archlinux".to_string(), + if Architecture::own() == Architecture::aarch64 { + "pacman-key --populate archlinux-arm".to_string() + } else { + String::new() + }, "pacman -Syu --noconfirm".to_string(), "pacman -S --noconfirm rsync base-devel".to_string(), ]; if ci { + // Symlink the build directory to current dir let symlink_cmd = format!( "ln -s {} /build", std::env::current_dir().unwrap().display() ); docker_script.extend([symlink_cmd]); } else { + // Copy over to build directory docker_script.extend(["rsync -a /workdir/ /build/".to_string()]); }; + // Create a `build` user docker_script.extend([ "useradd -m build".to_string(), "echo 'ALL ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers".to_string(), @@ -117,6 +123,7 @@ pub fn build(image: &str, ci: bool) { ]); if ci { + // Change ownership to `build` user let chown_cmd = format!( "chown -R build {}", std::env::current_dir().unwrap().display() @@ -125,11 +132,13 @@ pub fn build(image: &str, ci: bool) { } if ci { + // Copy custom `pacman.conf` if std::fs::exists("./pacman.conf").unwrap() { println!("-> Using custom pacman.conf"); docker_script.extend(["cp -v ./workdir/pacman.conf /etc/pacman.conf".to_string()]); } + // Copy custom `makepkg.conf` if std::fs::exists("./makepkg.conf").unwrap() { println!("-> Using custom makepkg.conf"); docker_script.extend(["cp -v ./workdir/pacman.conf /etc/makepkg.conf".to_string()]); @@ -138,8 +147,12 @@ pub fn build(image: &str, ci: bool) { if let Ok(sign_key) = sign_key { println!("Found signing key. Package will be signed."); + + // Prepare sign key let sign_key = sign_key.trim(); let sign_key = sign_key.replace('\n', "\\n"); + + // Import sign key let import_cmd = format!("echo -e '{sign_key}'|gpg --import"); let import_cmd_user = format!("su build -c \"echo -e '{sign_key}'|gpg --import\""); let export_var_cmd = format!( @@ -148,6 +161,8 @@ pub fn build(image: &str, ci: bool) { let trust_cmd = format!( "su build -w GPGKEY -c sh -c 'echo -e \"5\" | gpg --batch --yes --no-tty --command-fd 0 --edit-key $GPGKEY trust'" ); + + // Build signed package docker_script.extend([ import_cmd, import_cmd_user, @@ -156,18 +171,22 @@ pub fn build(image: &str, ci: bool) { "su build -w GPGKEY -c 'cd /build && makepkg -s -C -c --skippgpcheck --sign --noconfirm'".to_string(), ]); } else { + // Build unsigned package docker_script.extend([ "su build -w GPGKEY -c 'cd /build && makepkg -c -C -s --noconfirm --skippgpcheck'" .to_string(), ]); } + let move_pkg = format!("rsync -a --chown={uid}:{uid} /build/*.pkg.tar.* /workdir/"); if !ci { + // Move the package afterwards docker_script.extend([move_pkg]); } // Build the Docker run command let status = if ci { + // If CI: run on the host directly Command::new("bash") .stderr(Stdio::inherit()) .stdout(Stdio::inherit()) @@ -177,6 +196,7 @@ pub fn build(image: &str, ci: bool) { } else { // TODO : mount custom pacman.conf + makepkg.conf + // Containerized build let workdir_vol = format!("{}:/workdir", current_dir.display()); let mut args = vec![ "run", @@ -185,8 +205,10 @@ pub fn build(image: &str, ci: bool) { &workdir_vol, // Mount current dir to /workdir ]; + // Volume setup let mut extra_vols = Vec::new(); + // pacman.conf if std::fs::exists("./pacman.conf").unwrap() { println!("-> Using custom pacman.conf"); extra_vols.push(format!( @@ -195,6 +217,7 @@ pub fn build(image: &str, ci: bool) { )); } + // makepkg.conf if std::fs::exists("./makepkg.conf").unwrap() { println!("-> Using custom makepkg.conf"); extra_vols.push(format!( @@ -215,7 +238,7 @@ pub fn build(image: &str, ci: bool) { args.extend([ "-w", "/workdir", // Set working directory - image, // Docker Base Image + image, // Base Image "bash", "-c", &cmd, ]); @@ -230,7 +253,7 @@ pub fn build(image: &str, ci: bool) { .stdout(Stdio::inherit()) .args(args) .status() - .expect("Failed to start Docker or podman") + .expect("Failed to start container") }; if !status.success() {