Enable building debian packages using harness

next
Sayan Nandan 3 years ago
parent b018f14e1c
commit 1734a62e98
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -34,7 +34,7 @@ use std::path::PathBuf;
use std::process::Command;
use zip::{write::FileOptions, ZipWriter};
const BINARIES: [&str; 4] = ["skyd", "sky-bench", "skysh", "sky-migrate"];
pub const BINARIES: [&str; 4] = ["skyd", "sky-bench", "skysh", "sky-migrate"];
fn concat_path(binary_name: &str, body: impl AsRef<Path>) -> PathBuf {
let mut pb = PathBuf::from(body.as_ref());
@ -65,7 +65,8 @@ fn get_bundle_name() -> String {
filename
}
pub fn run_bundle() -> HarnessResult<()> {
/// Builds binaries in release mode and returns the target folder path
pub fn build_release() -> HarnessResult<PathBuf> {
let mut build_args = vec!["build".to_owned()];
let mut target_folder = PathBuf::from("target");
match util::get_var(util::VAR_TARGET) {
@ -79,21 +80,18 @@ pub fn run_bundle() -> HarnessResult<()> {
target_folder.push("release");
// assemble build args
build_args.extend([
"-p".into(),
"skyd".into(),
"-p".into(),
"sky-bench".into(),
"-p".into(),
"skysh".into(),
"-p".into(),
"sky-migrate".into(),
"--release".into(),
]);
for binary in BINARIES {
build_args.extend(["-p".to_owned(), binary.to_owned()])
}
build_args.push("--release".into());
let mut cmd = Command::new("cargo");
cmd.args(&build_args);
util::handle_child("build release binaries", cmd)?;
Ok(target_folder)
}
pub fn run_bundle() -> HarnessResult<()> {
let target_folder = self::build_release()?;
// now package
package_binaries(target_folder)?;
Ok(())

@ -24,6 +24,7 @@
*
*/
use crate::linuxpkg::LinuxPackageType;
use crate::{HarnessError, HarnessResult};
use std::{env, process};
@ -42,11 +43,13 @@ SUBCOMMANDS:
pub enum HarnessWhat {
Test,
Bundle,
LinuxPackage(LinuxPackageType),
}
impl HarnessWhat {
const CLI_TEST: &'static str = "test";
const CLI_BUNDLE: &'static str = "bundle";
const CLI_DEB: &'static str = "deb";
const CLI_ARG_HELP: &'static str = "--help";
const CLI_ARG_HELP_SHORT: &'static str = "-h";
pub fn from_env() -> HarnessResult<Self> {
@ -63,6 +66,7 @@ impl HarnessWhat {
Self::CLI_TEST => HarnessWhat::Test,
Self::CLI_BUNDLE => HarnessWhat::Bundle,
Self::CLI_ARG_HELP_SHORT | Self::CLI_ARG_HELP => display_help(),
Self::CLI_DEB => HarnessWhat::LinuxPackage(LinuxPackageType::Deb),
unknown_arg => return Err(HarnessError::UnknownCommand(unknown_arg.to_string())),
};
Ok(ret)

@ -0,0 +1,87 @@
/*
* Created on Thu Mar 17 2022
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2022, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use crate::bundle::build_release;
use crate::{util, HarnessResult};
use libsky::VERSION;
use std::process::Command;
pub enum LinuxPackageType {
Deb,
}
impl LinuxPackageType {
fn get_extension(&self) -> String {
match self {
Self::Deb => ".deb".to_owned(),
}
}
fn get_file_name(&self) -> String {
let mut filename = format!("skytable-v{VERSION}");
match util::get_var(util::VAR_ARTIFACT) {
Some(artifact) => {
filename.push('-');
filename.push_str(&artifact);
}
None => {}
}
filename.push_str(&self.get_extension());
filename
}
}
pub fn create_linuxpkg(package_type: LinuxPackageType) -> HarnessResult<()> {
info!("Building binaries for Linux package");
let _ = build_release()?;
info!("Creating Linux package");
let filename = package_type.get_file_name();
match package_type {
LinuxPackageType::Deb => {
// install cargo-deb
util::handle_child("install cargo-deb", cmd!("cargo", "install", "cargo-deb"))?;
// assemble the command
let mut build_args = vec!["deb".to_owned()];
match util::get_var(util::VAR_TARGET) {
Some(t) => {
build_args.push("--target".to_string());
build_args.push(t);
}
None => {}
}
build_args.extend([
"--no-build".to_owned(),
"--manifest-path=server/Cargo.toml".to_owned(),
"--output".to_owned(),
filename.to_owned(),
]);
let mut command = Command::new("cargo");
command.args(build_args);
util::handle_child("build dpkg", command)?;
}
}
info!("Done building Linux package: {filename}");
Ok(())
}

@ -31,6 +31,8 @@ mod util;
mod bundle;
mod cli;
mod error;
mod linuxpkg;
mod presetup;
mod test;
use crate::{
cli::HarnessWhat,
@ -51,9 +53,11 @@ fn main() {
fn runner() -> HarnessResult<()> {
let harness = cli::HarnessWhat::from_env()?;
presetup::install_deps()?;
match harness {
HarnessWhat::Test => test::run_test()?,
HarnessWhat::Bundle => bundle::run_bundle()?,
HarnessWhat::LinuxPackage(pkg) => linuxpkg::create_linuxpkg(pkg)?,
}
Ok(())
}

@ -0,0 +1,53 @@
/*
* Created on Thu Mar 17 2022
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2022, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use crate::{util, HarnessResult};
const TARGET_I686_GNU_LINUX: &str = "i686-unknown-linux-gnu";
const TARGET_X86_64_MUSL_LINUX: &str = "x86_64-unknown-linux-musl";
/// Install system deps
pub fn install_deps() -> HarnessResult<()> {
info!("Installing additional deps for this platform ...");
let install = match util::get_var(util::VAR_TARGET) {
Some(t) => match t.as_str() {
TARGET_I686_GNU_LINUX => cmd!(
"bash",
"-c",
"sudo apt-get update && sudo apt install gcc-multilib -y"
),
TARGET_X86_64_MUSL_LINUX => cmd!(
"bash",
"-c",
"sudo apt-get update && sudo apt install musl-tools -y"
),
_ => return Ok(()),
},
None => return Ok(()),
};
util::handle_child("install system deps", install)?;
Ok(())
}
Loading…
Cancel
Save