fix build
This commit is contained in:
parent
48476d5cf4
commit
76d7118df8
1 changed files with 46 additions and 23 deletions
41
src/main.rs
41
src/main.rs
|
@ -56,9 +56,7 @@ async fn launch(config: String) {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.mount_assets()
|
.mount_assets()
|
||||||
.mount(
|
.mount("/", routes![
|
||||||
"/",
|
|
||||||
routes![
|
|
||||||
routes::index_page,
|
routes::index_page,
|
||||||
routes::pkg_route,
|
routes::pkg_route,
|
||||||
routes::push::upload_pkg,
|
routes::push::upload_pkg,
|
||||||
|
@ -73,8 +71,7 @@ async fn launch(config: String) {
|
||||||
routes::user::change_password_post,
|
routes::user::change_password_post,
|
||||||
routes::ui::repo::repo_arch_json,
|
routes::ui::repo::repo_arch_json,
|
||||||
routes::ui::pkg::pkg_json
|
routes::ui::pkg::pkg_json
|
||||||
],
|
])
|
||||||
)
|
|
||||||
.manage(config)
|
.manage(config)
|
||||||
.manage(shell)
|
.manage(shell)
|
||||||
.launch()
|
.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 current_dir = std::env::current_dir().expect("Failed to get current directory");
|
||||||
let uid = nix::unistd::Uid::current().as_raw();
|
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");
|
let sign_key = std::env::var("SIGN_KEY");
|
||||||
|
|
||||||
// Build the Docker command
|
// Build the Docker command
|
||||||
let mut docker_script = vec![
|
let mut docker_script = vec![
|
||||||
"set -e".to_string(),
|
"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 -Syu --noconfirm".to_string(),
|
||||||
"pacman -S --noconfirm rsync base-devel".to_string(),
|
"pacman -S --noconfirm rsync base-devel".to_string(),
|
||||||
];
|
];
|
||||||
|
|
||||||
if ci {
|
if ci {
|
||||||
|
// Symlink the build directory to current dir
|
||||||
let symlink_cmd = format!(
|
let symlink_cmd = format!(
|
||||||
"ln -s {} /build",
|
"ln -s {} /build",
|
||||||
std::env::current_dir().unwrap().display()
|
std::env::current_dir().unwrap().display()
|
||||||
);
|
);
|
||||||
docker_script.extend([symlink_cmd]);
|
docker_script.extend([symlink_cmd]);
|
||||||
} else {
|
} else {
|
||||||
|
// Copy over to build directory
|
||||||
docker_script.extend(["rsync -a /workdir/ /build/".to_string()]);
|
docker_script.extend(["rsync -a /workdir/ /build/".to_string()]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Create a `build` user
|
||||||
docker_script.extend([
|
docker_script.extend([
|
||||||
"useradd -m build".to_string(),
|
"useradd -m build".to_string(),
|
||||||
"echo 'ALL ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers".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 {
|
if ci {
|
||||||
|
// Change ownership to `build` user
|
||||||
let chown_cmd = format!(
|
let chown_cmd = format!(
|
||||||
"chown -R build {}",
|
"chown -R build {}",
|
||||||
std::env::current_dir().unwrap().display()
|
std::env::current_dir().unwrap().display()
|
||||||
|
@ -125,11 +132,13 @@ pub fn build(image: &str, ci: bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ci {
|
if ci {
|
||||||
|
// Copy custom `pacman.conf`
|
||||||
if std::fs::exists("./pacman.conf").unwrap() {
|
if std::fs::exists("./pacman.conf").unwrap() {
|
||||||
println!("-> Using custom pacman.conf");
|
println!("-> Using custom pacman.conf");
|
||||||
docker_script.extend(["cp -v ./workdir/pacman.conf /etc/pacman.conf".to_string()]);
|
docker_script.extend(["cp -v ./workdir/pacman.conf /etc/pacman.conf".to_string()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy custom `makepkg.conf`
|
||||||
if std::fs::exists("./makepkg.conf").unwrap() {
|
if std::fs::exists("./makepkg.conf").unwrap() {
|
||||||
println!("-> Using custom makepkg.conf");
|
println!("-> Using custom makepkg.conf");
|
||||||
docker_script.extend(["cp -v ./workdir/pacman.conf /etc/makepkg.conf".to_string()]);
|
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 {
|
if let Ok(sign_key) = sign_key {
|
||||||
println!("Found signing key. Package will be signed.");
|
println!("Found signing key. Package will be signed.");
|
||||||
|
|
||||||
|
// Prepare sign key
|
||||||
let sign_key = sign_key.trim();
|
let sign_key = sign_key.trim();
|
||||||
let sign_key = sign_key.replace('\n', "\\n");
|
let sign_key = sign_key.replace('\n', "\\n");
|
||||||
|
|
||||||
|
// Import sign key
|
||||||
let import_cmd = format!("echo -e '{sign_key}'|gpg --import");
|
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 import_cmd_user = format!("su build -c \"echo -e '{sign_key}'|gpg --import\"");
|
||||||
let export_var_cmd = format!(
|
let export_var_cmd = format!(
|
||||||
|
@ -148,6 +161,8 @@ pub fn build(image: &str, ci: bool) {
|
||||||
let trust_cmd = format!(
|
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'"
|
"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([
|
docker_script.extend([
|
||||||
import_cmd,
|
import_cmd,
|
||||||
import_cmd_user,
|
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(),
|
"su build -w GPGKEY -c 'cd /build && makepkg -s -C -c --skippgpcheck --sign --noconfirm'".to_string(),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
|
// Build unsigned package
|
||||||
docker_script.extend([
|
docker_script.extend([
|
||||||
"su build -w GPGKEY -c 'cd /build && makepkg -c -C -s --noconfirm --skippgpcheck'"
|
"su build -w GPGKEY -c 'cd /build && makepkg -c -C -s --noconfirm --skippgpcheck'"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let move_pkg = format!("rsync -a --chown={uid}:{uid} /build/*.pkg.tar.* /workdir/");
|
||||||
if !ci {
|
if !ci {
|
||||||
|
// Move the package afterwards
|
||||||
docker_script.extend([move_pkg]);
|
docker_script.extend([move_pkg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the Docker run command
|
// Build the Docker run command
|
||||||
let status = if ci {
|
let status = if ci {
|
||||||
|
// If CI: run on the host directly
|
||||||
Command::new("bash")
|
Command::new("bash")
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
.stdout(Stdio::inherit())
|
.stdout(Stdio::inherit())
|
||||||
|
@ -177,6 +196,7 @@ pub fn build(image: &str, ci: bool) {
|
||||||
} else {
|
} else {
|
||||||
// TODO : mount custom pacman.conf + makepkg.conf
|
// TODO : mount custom pacman.conf + makepkg.conf
|
||||||
|
|
||||||
|
// Containerized build
|
||||||
let workdir_vol = format!("{}:/workdir", current_dir.display());
|
let workdir_vol = format!("{}:/workdir", current_dir.display());
|
||||||
let mut args = vec![
|
let mut args = vec![
|
||||||
"run",
|
"run",
|
||||||
|
@ -185,8 +205,10 @@ pub fn build(image: &str, ci: bool) {
|
||||||
&workdir_vol, // Mount current dir to /workdir
|
&workdir_vol, // Mount current dir to /workdir
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Volume setup
|
||||||
let mut extra_vols = Vec::new();
|
let mut extra_vols = Vec::new();
|
||||||
|
|
||||||
|
// pacman.conf
|
||||||
if std::fs::exists("./pacman.conf").unwrap() {
|
if std::fs::exists("./pacman.conf").unwrap() {
|
||||||
println!("-> Using custom pacman.conf");
|
println!("-> Using custom pacman.conf");
|
||||||
extra_vols.push(format!(
|
extra_vols.push(format!(
|
||||||
|
@ -195,6 +217,7 @@ pub fn build(image: &str, ci: bool) {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// makepkg.conf
|
||||||
if std::fs::exists("./makepkg.conf").unwrap() {
|
if std::fs::exists("./makepkg.conf").unwrap() {
|
||||||
println!("-> Using custom makepkg.conf");
|
println!("-> Using custom makepkg.conf");
|
||||||
extra_vols.push(format!(
|
extra_vols.push(format!(
|
||||||
|
@ -215,7 +238,7 @@ pub fn build(image: &str, ci: bool) {
|
||||||
|
|
||||||
args.extend([
|
args.extend([
|
||||||
"-w", "/workdir", // Set working directory
|
"-w", "/workdir", // Set working directory
|
||||||
image, // Docker Base Image
|
image, // Base Image
|
||||||
"bash", "-c", &cmd,
|
"bash", "-c", &cmd,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -230,7 +253,7 @@ pub fn build(image: &str, ci: bool) {
|
||||||
.stdout(Stdio::inherit())
|
.stdout(Stdio::inherit())
|
||||||
.args(args)
|
.args(args)
|
||||||
.status()
|
.status()
|
||||||
.expect("Failed to start Docker or podman")
|
.expect("Failed to start container")
|
||||||
};
|
};
|
||||||
|
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue