Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pipebuilder/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pipebuilder"
version = "0.1.2"
version = "0.1.3"
authors = ["Li Yu <li.yu.sh0211@gmail.com>"]
edition = "2018"
license = "Apache-2.0"
Expand Down Expand Up @@ -36,7 +36,7 @@ clap = "3.0.0-beta.2"
etcd-client = "0.7.2"
flurry = "0.3.1"
http = "0.2.5"
pipebuilder_common = { version = "0.1.2", path = "../pipebuilder_common" }
pipebuilder_common = { version = "0.1.3", path = "../pipebuilder_common" }
prost = "0.8"
reqwest = "0.11.4"
serde = { version = "1.0", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion pipebuilder_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pipebuilder_common"
version = "0.1.2"
version = "0.1.3"
edition = "2018"
authors = ["Li Yu <li.yu.sh0211@gmail.com>"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion pipebuilder_common/src/api/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ pub(crate) const DISPLAY_NODE_OS_WIDTH: usize = 12;
pub(crate) const DISPLAY_SIZE_WIDTH: usize = 12;
pub(crate) const DISPLAY_VERSION_WIDTH: usize = 12;
pub(crate) const DISPLAY_ADDRESS_WIDTH: usize = 16;
pub(crate) const DISPLAY_BUILD_TARGET_PLATFORM_WIDTH: usize = 24;
pub(crate) const DISPLAY_BUILD_TARGET_PLATFORM_WIDTH: usize = 28;
pub(crate) const DISPLAY_TIMESTAMP_WIDTH: usize = 32;
pub(crate) const DISPLAY_MESSAGE_WIDTH: usize = 36;
18 changes: 9 additions & 9 deletions pipebuilder_common/src/api/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ impl Display for BuildMetadata {
let status = self.status.to_string();
let timestamp = self.timestamp.to_string();
writeln!(f,
"{id:<id_width$}{version:<version_width$}{status:<status_width$}{target_platform:<target_platform_width$}{builder_id:<id_width$}{builder_address:<address_width$}{timestamp:<timestamp_width$}{message:<message_width$}",
"{id:<id_width$}{version:<version_width$}{status:<status_width$}{builder_id:<id_width$}{builder_address:<address_width$}{target_platform:<target_platform_width$}{timestamp:<timestamp_width$}{message:<message_width$}",
id = self.id,
version = self.version,
status = status,
target_platform = target_platform,
timestamp = timestamp,
builder_id = self.builder_id,
builder_address = self.builder_address,
target_platform = target_platform,
timestamp = timestamp,
message = message,
id_width = DISPLAY_ID_WIDTH,
version_width = DISPLAY_VERSION_WIDTH,
Expand All @@ -231,17 +231,17 @@ impl PrintHeader for BuildMetadata {
col0 = "Id",
col1 = "Version",
col2 = "Status",
col3 = "Target",
col4 = "Builder Id",
col5 = "Builder Address",
col3 = "Builder Id",
col4 = "Builder Address",
col5 = "Target Platform",
col6 = "Timestamp",
col7 = "Message",
col0_width = DISPLAY_ID_WIDTH,
col1_width = DISPLAY_VERSION_WIDTH,
col2_width = DISPLAY_BUILD_STATUS_WIDTH,
col3_width = DISPLAY_BUILD_TARGET_PLATFORM_WIDTH,
col4_width = DISPLAY_ID_WIDTH,
col5_width = DISPLAY_ADDRESS_WIDTH,
col3_width = DISPLAY_ID_WIDTH,
col4_width = DISPLAY_ADDRESS_WIDTH,
col5_width = DISPLAY_BUILD_TARGET_PLATFORM_WIDTH,
col6_width = DISPLAY_TIMESTAMP_WIDTH,
col7_width = DISPLAY_MESSAGE_WIDTH,
)
Expand Down
12 changes: 3 additions & 9 deletions pipebuilder_common/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
copy_directory, create_directory, move_directory, parse_toml, remove_directory, sub_path,
write_file, write_toml, TomlManifest,
},
PATH_APP_CARGO_WORKDIR,
};
use chrono::{DateTime, Utc};
use pipegen::models::App;
Expand Down Expand Up @@ -366,19 +367,12 @@ impl Build {
// cargo build and stream log to file
let app_workspace = app_workspace(workspace, namespace, id, build_version);
let target_platform = self.target_platform.as_str();
let toml_path = sub_path(app_workspace.as_str(), PATH_APP_TOML_MANIFEST);
let target_path = sub_path(app_workspace.as_str(), PATH_APP_TARGET);
let cargo_workdir = sub_path(app_workspace.as_str(), PATH_APP_CARGO_WORKDIR);
// prepare log directory
let log_directory = app_build_log_directory(log_directory, namespace, id, build_version);
create_directory(log_directory.as_str()).await?;
let log_path = sub_path(log_directory.as_str(), PATH_APP_BUILD_LOG);
cargo_build(
toml_path.as_str(),
target_platform,
target_path.as_str(),
log_path.as_str(),
)
.await?;
cargo_build(cargo_workdir.as_str(), target_platform, log_path.as_str()).await?;
Ok(Some(BuildStatus::Publish))
}

Expand Down
1 change: 1 addition & 0 deletions pipebuilder_common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub const RESOURCE_PROJECT: &str = "project";

pub const PATH_APP: &str = "app";
pub const PATH_APP_BUILD_LOG: &str = "build.log";
pub const PATH_APP_CARGO_WORKDIR: &str = "app";
pub const PATH_APP_TOML_MANIFEST: &str = "app/Cargo.toml";
pub const PATH_APP_MAIN: &str = "app/src/main.rs";
pub const PATH_APP_TARGET: &str = "app/target";
Expand Down
16 changes: 6 additions & 10 deletions pipebuilder_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,20 @@ pub async fn cargo_fmt(manifest_path: &str) -> Result<()> {
}

// target platform: https://doc.rust-lang.org/cargo/commands/cargo-build.html#compilation-options
pub async fn cargo_build(
manifest_path: &str,
target_platform: &str,
target_directory: &str,
log_path: &str,
) -> Result<()> {
pub async fn cargo_build(cargo_workdir: &str, target_platform: &str, log_path: &str) -> Result<()> {
let log_file = fs::File::create(log_path).await?.into_std().await;
let mut cmd = Command::new(cargo_binary());
cmd.arg("build")
.arg("--manifest-path")
.arg(manifest_path)
.arg("--target")
.arg(target_platform)
.arg("--target-dir")
.arg(target_directory)
.arg("--release");
cmd.stderr(log_file);
// change cwd as cargo workdir
let current_dir = std::env::current_dir()?;
std::env::set_current_dir(cargo_workdir)?;
let code = cmd_status(cmd).await?;
// restore previous workdir
std::env::set_current_dir(current_dir)?;
match code == 0 {
true => Ok(()),
false => Err(cargo_error("build", code, String::from("check build log"))),
Expand Down