mirror of
https://github.com/moghtech/komodo.git
synced 2026-04-28 11:49:39 -05:00
support docker buildx build and passing arbitrary extra args
This commit is contained in:
@@ -155,6 +155,12 @@ pub struct DockerBuildArgs {
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
pub build_args: Vec<EnvironmentVar>,
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
pub extra_args: Vec<String>,
|
||||
#[serde(default)]
|
||||
#[builder(default)]
|
||||
pub use_buildx: bool,
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
|
||||
@@ -6,7 +6,7 @@ use types::{Build, DockerBuildArgs, EnvironmentVar, Log, Version};
|
||||
|
||||
use crate::helpers::run_monitor_command;
|
||||
|
||||
use super::docker_login;
|
||||
use super::{docker_login, parse_extra_args};
|
||||
|
||||
pub async fn prune_images() -> Log {
|
||||
let command = format!("docker image prune -a -f");
|
||||
@@ -32,6 +32,8 @@ pub async fn build(
|
||||
build_path,
|
||||
dockerfile_path,
|
||||
build_args,
|
||||
extra_args,
|
||||
use_buildx,
|
||||
} = docker_build_args
|
||||
.as_ref()
|
||||
.ok_or(anyhow!("build missing docker build args"))?;
|
||||
@@ -46,6 +48,12 @@ pub async fn build(
|
||||
None => "Dockerfile".to_owned(),
|
||||
};
|
||||
let build_args = parse_build_args(build_args);
|
||||
let extra_args = parse_extra_args(extra_args);
|
||||
let buildx = if *use_buildx {
|
||||
" buildx"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let image_name = get_image_name(&name, docker_account, docker_organization);
|
||||
let image_tags = image_tags(&image_name, &version);
|
||||
let docker_push = if using_account {
|
||||
@@ -54,7 +62,7 @@ pub async fn build(
|
||||
String::new()
|
||||
};
|
||||
let command = format!(
|
||||
"cd {} && docker build {build_args}{image_tags} -f {dockerfile_path} .{docker_push}",
|
||||
"cd {} && docker{buildx} build {build_args}{extra_args}{image_tags} -f {dockerfile_path} .{docker_push}",
|
||||
build_dir.display()
|
||||
);
|
||||
if *skip_secret_interp {
|
||||
|
||||
@@ -7,7 +7,7 @@ use types::{
|
||||
Conversion, Deployment, DockerContainerStats, DockerRunArgs, EnvironmentVar, Log, RestartMode,
|
||||
};
|
||||
|
||||
use crate::helpers::run_monitor_command;
|
||||
use crate::helpers::{run_monitor_command, docker::parse_extra_args};
|
||||
|
||||
use super::docker_login;
|
||||
|
||||
@@ -197,12 +197,3 @@ fn parse_post_image(post_image: &Option<String>) -> String {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_extra_args(extra_args: &Vec<String>) -> String {
|
||||
let args = extra_args.join(" ");
|
||||
if args.len() > 0 {
|
||||
format!(" {args}")
|
||||
} else {
|
||||
args
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,3 +38,12 @@ pub async fn docker_login(
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_extra_args(extra_args: &Vec<String>) -> String {
|
||||
let args = extra_args.join(" ");
|
||||
if args.len() > 0 {
|
||||
format!(" {args}")
|
||||
} else {
|
||||
args
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user