提交 f5614f87 authored 作者: Serhij S's avatar Serhij S

pro live update

上级 8b3c047e
...@@ -140,6 +140,8 @@ pub struct FlashCommand { ...@@ -140,6 +140,8 @@ pub struct FlashCommand {
help = "Put remote in RUN mode after flashing, for Docker: run the container" help = "Put remote in RUN mode after flashing, for Docker: run the container"
)] )]
pub run: bool, pub run: bool,
#[clap(long, help = "Perform live update (requires RoboPLC Pro)")]
pub live: bool,
} }
#[derive(Parser)] #[derive(Parser)]
...@@ -179,6 +181,7 @@ pub struct FlashExec { ...@@ -179,6 +181,7 @@ pub struct FlashExec {
pub file: Option<PathBuf>, pub file: Option<PathBuf>,
pub force: bool, pub force: bool,
pub run: bool, pub run: bool,
pub live: bool,
pub program_args: Vec<String>, pub program_args: Vec<String>,
pub program_env: BTreeMap<String, String>, pub program_env: BTreeMap<String, String>,
} }
...@@ -192,6 +195,7 @@ impl From<FlashCommand> for FlashExec { ...@@ -192,6 +195,7 @@ impl From<FlashCommand> for FlashExec {
file: cmd.file, file: cmd.file,
force: cmd.force, force: cmd.force,
run: cmd.run, run: cmd.run,
live: cmd.live,
program_args: Vec::new(), program_args: Vec::new(),
program_env: BTreeMap::new(), program_env: BTreeMap::new(),
} }
...@@ -220,6 +224,7 @@ impl From<ExecCommand> for FlashExec { ...@@ -220,6 +224,7 @@ impl From<ExecCommand> for FlashExec {
file: cmd.file, file: cmd.file,
force: cmd.force, force: cmd.force,
run: false, run: false,
live: false,
program_args: cmd.args, program_args: cmd.args,
program_env, program_env,
} }
......
...@@ -5,7 +5,7 @@ use std::{ ...@@ -5,7 +5,7 @@ use std::{
}; };
use colored::Colorize as _; use colored::Colorize as _;
use serde_json::json; use serde::Serialize;
use ureq::Agent; use ureq::Agent;
use ureq_multipart::MultipartBuilder; use ureq_multipart::MultipartBuilder;
use which::which; use which::which;
...@@ -18,7 +18,7 @@ use crate::{ ...@@ -18,7 +18,7 @@ use crate::{
API_PREFIX, API_PREFIX,
}; };
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
fn flash_file( fn flash_file(
url: &str, url: &str,
key: &str, key: &str,
...@@ -26,6 +26,7 @@ fn flash_file( ...@@ -26,6 +26,7 @@ fn flash_file(
file: &Path, file: &Path,
force: bool, force: bool,
run: bool, run: bool,
live: bool,
exec_only: bool, exec_only: bool,
program_args: Vec<String>, program_args: Vec<String>,
program_env: BTreeMap<String, String>, program_env: BTreeMap<String, String>,
...@@ -37,6 +38,9 @@ fn flash_file( ...@@ -37,6 +38,9 @@ fn flash_file(
return crate::exec::exec(url, key, file, force, program_args, program_env); return crate::exec::exec(url, key, file, force, program_args, program_env);
} }
if let Some(docker_img) = url.strip_prefix("docker://") { if let Some(docker_img) = url.strip_prefix("docker://") {
if run {
return Err("Live update for Docker images is not supported".into());
}
let tag = std::env::var("ROBOPLC_DOCKER_TAG").unwrap_or_else(|_| { let tag = std::env::var("ROBOPLC_DOCKER_TAG").unwrap_or_else(|_| {
crate::TARGET_PACKAGE_VERSION crate::TARGET_PACKAGE_VERSION
.get() .get()
...@@ -81,17 +85,20 @@ fn flash_file( ...@@ -81,17 +85,20 @@ fn flash_file(
} }
} }
} else { } else {
#[derive(Serialize)]
struct Payload {
#[serde(skip_serializing_if = "std::ops::Not::not")]
force: bool,
#[serde(skip_serializing_if = "std::ops::Not::not")]
run: bool,
#[serde(skip_serializing_if = "std::ops::Not::not")]
live: bool,
}
let (content_type, data) = MultipartBuilder::new() let (content_type, data) = MultipartBuilder::new()
.add_file("file", file)? .add_file("file", file)?
.add_text( .add_text(
"params", "params",
&serde_json::to_string(&json! { &serde_json::to_string(&Payload { force, run, live })?,
{
"force": force,
"run": run,
}
})?,
)? )?
.finish()?; .finish()?;
agent agent
...@@ -104,13 +111,14 @@ fn flash_file( ...@@ -104,13 +111,14 @@ fn flash_file(
Ok(()) Ok(())
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
fn run_build_custom( fn run_build_custom(
url: &str, url: &str,
key: &str, key: &str,
agent: Agent, agent: Agent,
force: bool, force: bool,
run: bool, run: bool,
live: bool,
cmd: &str, cmd: &str,
file: &Path, file: &Path,
exec_only: bool, exec_only: bool,
...@@ -138,6 +146,7 @@ fn run_build_custom( ...@@ -138,6 +146,7 @@ fn run_build_custom(
file, file,
force, force,
run, run,
live,
exec_only, exec_only,
program_args, program_args,
program_env, program_env,
...@@ -163,6 +172,7 @@ pub fn flash( ...@@ -163,6 +172,7 @@ pub fn flash(
&file, &file,
opts.force, opts.force,
opts.run, opts.run,
opts.live,
exec_only, exec_only,
opts.program_args, opts.program_args,
opts.program_env, opts.program_env,
...@@ -174,6 +184,7 @@ pub fn flash( ...@@ -174,6 +184,7 @@ pub fn flash(
agent, agent,
opts.force, opts.force,
opts.run, opts.run,
opts.live,
&custom_cmd, &custom_cmd,
&build_custom &build_custom
.file .file
...@@ -253,6 +264,7 @@ pub fn flash( ...@@ -253,6 +264,7 @@ pub fn flash(
&binary_name, &binary_name,
opts.force, opts.force,
opts.run, opts.run,
opts.live,
exec_only, exec_only,
opts.program_args, opts.program_args,
opts.program_env, opts.program_env,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论