diff --git a/bin/migrator/src/legacy/v0/build.rs b/bin/migrator/src/legacy/v0/build.rs index 433ac274a..081fd1baa 100644 --- a/bin/migrator/src/legacy/v0/build.rs +++ b/bin/migrator/src/legacy/v0/build.rs @@ -226,6 +226,7 @@ impl TryFrom for monitor_client::entities::build::Build { build_args, extra_args, use_buildx, + labels: Default::default() }, }; Ok(build) diff --git a/bin/migrator/src/legacy/v0/deployment.rs b/bin/migrator/src/legacy/v0/deployment.rs index 43a9ef630..836e80c2a 100644 --- a/bin/migrator/src/legacy/v0/deployment.rs +++ b/bin/migrator/src/legacy/v0/deployment.rs @@ -382,6 +382,7 @@ impl TryFrom .docker_run_args .docker_account .unwrap_or_default(), + labels: Default::default() }, }; Ok(deployment) diff --git a/bin/periphery/src/helpers/docker/build.rs b/bin/periphery/src/helpers/docker/build.rs index 877508f63..321e2a12e 100644 --- a/bin/periphery/src/helpers/docker/build.rs +++ b/bin/periphery/src/helpers/docker/build.rs @@ -8,7 +8,7 @@ use monitor_client::entities::{ use crate::{config::periphery_config, helpers::run_monitor_command}; -use super::{docker_login, parse_extra_args}; +use super::{docker_login, parse_extra_args, parse_labels}; #[instrument] pub async fn prune_images() -> Log { @@ -29,6 +29,7 @@ pub async fn build( build_path, dockerfile_path, build_args, + labels, extra_args, use_buildx, .. @@ -50,6 +51,7 @@ pub async fn build( None => "Dockerfile".to_owned(), }; let build_args = parse_build_args(build_args); + let labels = parse_labels(labels); let extra_args = parse_extra_args(extra_args); let buildx = if *use_buildx { " buildx" } else { "" }; let image_name = get_image_name( @@ -64,7 +66,7 @@ pub async fn build( String::new() }; let command = format!( - "cd {} && docker{buildx} build{build_args}{extra_args}{image_tags} -f {dockerfile_path} .{docker_push}", + "cd {} && docker{buildx} build{build_args}{extra_args}{labels}{image_tags} -f {dockerfile_path} .{docker_push}", build_dir.display() ); if *skip_secret_interp { @@ -130,13 +132,9 @@ fn image_tags(image_name: &str, version: &Version) -> String { } fn parse_build_args(build_args: &[EnvironmentVar]) -> String { - let mut args = build_args + build_args .iter() - .map(|p| format!(" --build-arg {}={}", p.variable, p.value)) - .collect::>() - .join(""); - if !args.is_empty() { - args.push(' '); - } - args + .map(|p| format!(" --build-arg {}=\"{}\"", p.variable, p.value)) + .collect::>() + .join("") } diff --git a/bin/periphery/src/helpers/docker/container.rs b/bin/periphery/src/helpers/docker/container.rs index ece0c2c87..167e13cb9 100644 --- a/bin/periphery/src/helpers/docker/container.rs +++ b/bin/periphery/src/helpers/docker/container.rs @@ -14,7 +14,8 @@ use serror::serialize_error_pretty; use crate::{ config::periphery_config, helpers::{ - docker::parse_extra_args, get_docker_token, run_monitor_command, + docker::{parse_extra_args, parse_labels}, + get_docker_token, run_monitor_command, }, }; @@ -255,6 +256,7 @@ pub fn docker_run_command( process_args, restart, environment, + labels, extra_args, .. }, @@ -270,9 +272,10 @@ pub fn docker_run_command( let network = parse_network(network); let restart = parse_restart(restart); let environment = parse_environment(environment); + let labels = parse_labels(labels); let process_args = parse_process_args(process_args); let extra_args = parse_extra_args(extra_args); - format!("docker run -d --name {name}{container_user}{ports}{volumes}{network}{restart}{environment}{extra_args} {image}{process_args}") + format!("docker run -d --name {name}{container_user}{ports}{volumes}{network}{restart}{environment}{labels}{extra_args} {image}{process_args}") } fn parse_container_user(container_user: &String) -> String { @@ -290,7 +293,7 @@ fn parse_conversions( conversions .iter() .map(|p| format!(" {flag} {}:{}", p.local, p.container)) - .collect::>() + .collect::>() .join("") } @@ -298,7 +301,7 @@ fn parse_environment(environment: &[EnvironmentVar]) -> String { environment .iter() .map(|p| format!(" --env {}=\"{}\"", p.variable, p.value)) - .collect::>() + .collect::>() .join("") } diff --git a/bin/periphery/src/helpers/docker/mod.rs b/bin/periphery/src/helpers/docker/mod.rs index feaf22959..43b4fec0c 100644 --- a/bin/periphery/src/helpers/docker/mod.rs +++ b/bin/periphery/src/helpers/docker/mod.rs @@ -1,5 +1,5 @@ use anyhow::anyhow; -use monitor_client::entities::update::Log; +use monitor_client::entities::{update::Log, EnvironmentVar}; use run_command::async_run_command; use super::run_monitor_command; @@ -48,6 +48,14 @@ pub fn parse_extra_args(extra_args: &[String]) -> String { } } +pub fn parse_labels(labels: &[EnvironmentVar]) -> String { + labels + .iter() + .map(|p| format!(" --label {}=\"{}\"", p.variable, p.value)) + .collect::>() + .join("") +} + #[instrument] pub async fn prune_system() -> Log { let command = String::from("docker system prune -a -f"); diff --git a/client/core/rs/src/entities/build.rs b/client/core/rs/src/entities/build.rs index 533bda79d..1437987d1 100644 --- a/client/core/rs/src/entities/build.rs +++ b/client/core/rs/src/entities/build.rs @@ -94,6 +94,10 @@ pub struct BuildConfig { #[builder(default)] pub build_args: Vec, + #[serde(default)] + #[builder(default)] + pub labels: Vec, + #[serde(default)] #[builder(default)] pub extra_args: Vec, diff --git a/client/core/rs/src/entities/deployment.rs b/client/core/rs/src/entities/deployment.rs index 8b1badfed..bbfa33ce1 100644 --- a/client/core/rs/src/entities/deployment.rs +++ b/client/core/rs/src/entities/deployment.rs @@ -86,6 +86,10 @@ pub struct DeploymentConfig { #[builder(default)] pub environment: Vec, + #[serde(default)] + #[builder(default)] + pub labels: Vec, + #[serde(default = "default_network")] #[builder(default = "default_network()")] #[partial_default(default_network())]