mirror of
https://github.com/moghtech/komodo.git
synced 2026-03-11 17:44:19 -05:00
implement docker tag support
This commit is contained in:
@@ -226,6 +226,7 @@ impl TryFrom<Build> for monitor_client::entities::build::Build {
|
||||
build_args,
|
||||
extra_args,
|
||||
use_buildx,
|
||||
labels: Default::default()
|
||||
},
|
||||
};
|
||||
Ok(build)
|
||||
|
||||
@@ -382,6 +382,7 @@ impl TryFrom<Deployment>
|
||||
.docker_run_args
|
||||
.docker_account
|
||||
.unwrap_or_default(),
|
||||
labels: Default::default()
|
||||
},
|
||||
};
|
||||
Ok(deployment)
|
||||
|
||||
@@ -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::<Vec<String>>()
|
||||
.join("");
|
||||
if !args.is_empty() {
|
||||
args.push(' ');
|
||||
}
|
||||
args
|
||||
.map(|p| format!(" --build-arg {}=\"{}\"", p.variable, p.value))
|
||||
.collect::<Vec<_>>()
|
||||
.join("")
|
||||
}
|
||||
|
||||
@@ -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::<Vec<String>>()
|
||||
.collect::<Vec<_>>()
|
||||
.join("")
|
||||
}
|
||||
|
||||
@@ -298,7 +301,7 @@ fn parse_environment(environment: &[EnvironmentVar]) -> String {
|
||||
environment
|
||||
.iter()
|
||||
.map(|p| format!(" --env {}=\"{}\"", p.variable, p.value))
|
||||
.collect::<Vec<String>>()
|
||||
.collect::<Vec<_>>()
|
||||
.join("")
|
||||
}
|
||||
|
||||
|
||||
@@ -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::<Vec<_>>()
|
||||
.join("")
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn prune_system() -> Log {
|
||||
let command = String::from("docker system prune -a -f");
|
||||
|
||||
@@ -94,6 +94,10 @@ pub struct BuildConfig {
|
||||
#[builder(default)]
|
||||
pub build_args: Vec<EnvironmentVar>,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
pub labels: Vec<EnvironmentVar>,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
pub extra_args: Vec<String>,
|
||||
|
||||
@@ -86,6 +86,10 @@ pub struct DeploymentConfig {
|
||||
#[builder(default)]
|
||||
pub environment: Vec<EnvironmentVar>,
|
||||
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
pub labels: Vec<EnvironmentVar>,
|
||||
|
||||
#[serde(default = "default_network")]
|
||||
#[builder(default = "default_network()")]
|
||||
#[partial_default(default_network())]
|
||||
|
||||
Reference in New Issue
Block a user