Skip to content

Commit 006f967

Browse files
authored
feat: Forward args to docker command (#1355)
* chore: Move parse_image_version function * feat: Forward args to docker command * chore: Add deprecation note to help text
1 parent 00731d6 commit 006f967

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

rust/boil/src/build/cli.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct BuildArguments {
2828
/// The image version being built.
2929
#[arg(
3030
short, long,
31-
value_parser = parse_image_version,
31+
value_parser = BuildArguments::parse_image_version,
3232
default_value_t = Self::default_image_version(),
3333
help_heading = "Image Options"
3434
)]
@@ -112,15 +112,33 @@ pub struct BuildArguments {
112112
pub strip_architecture: bool,
113113

114114
/// Loads the image into the local image store.
115+
///
116+
/// DEPRECATED: Use -- --load instead.
115117
#[arg(long, help_heading = "Build Options")]
118+
#[deprecated(since = "0.1.7", note = "Use -- --load instead")]
116119
pub load: bool,
117120

118121
/// Dry run. This does not build the image(s) but instead prints out the bakefile.
119122
#[arg(short, long, alias = "dry")]
120123
pub dry_run: bool,
124+
125+
/// Arguments passed after '--' which are directly passed to the Docker command.
126+
///
127+
/// Care needs to be taken, because these arguments can override/modify the behaviour defined
128+
/// via the generated Bakefile. A few save arguments include but are not limited to: --load,
129+
/// --no-cache, --progress.
130+
#[arg(raw = true)]
131+
pub rest: Vec<String>,
121132
}
122133

123134
impl BuildArguments {
135+
fn parse_image_version(input: &str) -> Result<Version, ParseImageVersionError> {
136+
let version = Version::from_str(input).context(ParseVersionSnafu)?;
137+
ensure!(version.build.is_empty(), ContainsBuildMetadataSnafu);
138+
139+
Ok(version)
140+
}
141+
124142
fn default_image_version() -> Version {
125143
"0.0.0-dev".parse().expect("must be a valid SemVer")
126144
}
@@ -151,13 +169,6 @@ pub enum ParseImageVersionError {
151169
ContainsBuildMetadata,
152170
}
153171

154-
pub fn parse_image_version(input: &str) -> Result<Version, ParseImageVersionError> {
155-
let version = Version::from_str(input).context(ParseVersionSnafu)?;
156-
ensure!(version.build.is_empty(), ContainsBuildMetadataSnafu);
157-
158-
Ok(version)
159-
}
160-
161172
#[derive(Debug, PartialEq, Snafu, EnumDiscriminants)]
162173
pub enum ParseHostPortError {
163174
#[snafu(display("unexpected empty input"))]

rust/boil/src/build/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub enum Error {
4848
}
4949

5050
/// This is the `boil build` command handler function.
51-
pub fn run_command(args: BuildArguments, config: Config) -> Result<(), Error> {
51+
pub fn run_command(args: Box<BuildArguments>, config: Config) -> Result<(), Error> {
5252
// TODO (@Techassi): Parse Dockerfile instead to build the target graph
5353
// Validation
5454
ensure!(
@@ -77,10 +77,12 @@ pub fn run_command(args: BuildArguments, config: Config) -> Result<(), Error> {
7777
// or by building the image ourself.
7878

7979
// Finally invoke the docker buildx bake command
80+
#[allow(deprecated)]
8081
let mut child = Command::new("docker")
8182
.arg("buildx")
8283
.arg("bake")
8384
.arg_if(args.load, "--load")
85+
.args(args.rest)
8486
.arg("--file")
8587
.arg("-")
8688
.stdin(Stdio::piped())

rust/boil/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub enum Command {
2727
///
2828
/// Requires docker with the buildx extension.
2929
#[command(alias = "some-chicken")]
30-
Build(BuildArguments),
30+
Build(Box<BuildArguments>),
3131

3232
/// Display various structured outputs in JSON format.
3333
Show(ShowArguments),

0 commit comments

Comments
 (0)