Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 117 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ authors = ["Stackable <[email protected]>"]
license = "Apache-2.0"

[workspace.dependencies]
cap-std = "3.4.4"
clap = { version = "4.5.41", features = ["derive"] }
clap_complete = "4.5.55"
clap_complete_nushell = "4.5.8"
Expand Down
1 change: 1 addition & 0 deletions rust/boil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repository.workspace = true
publish = false

[dependencies]
cap-std.workspace = true
clap.workspace = true
clap_complete.workspace = true
clap_complete_nushell.workspace = true
Expand Down
33 changes: 28 additions & 5 deletions rust/boil/src/build/bakefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ use std::{
path::PathBuf,
};

use cap_std::{ambient_authority, fs::Dir};
use glob::glob;
use oci_spec::image::{
ANNOTATION_AUTHORS, ANNOTATION_CREATED, ANNOTATION_DOCUMENTATION, ANNOTATION_LICENSES,
ANNOTATION_REVISION, ANNOTATION_SOURCE, ANNOTATION_VENDOR, ANNOTATION_VERSION,
};
use semver::Version;
use serde::Serialize;
use snafu::{OptionExt, ResultExt, Snafu};
use snafu::{OptionExt, ResultExt, Snafu, ensure};
use time::format_description::well_known::Rfc3339;

use crate::{
Expand Down Expand Up @@ -55,6 +56,9 @@ pub enum Error {

#[snafu(display("failed to parse build arguments"))]
ParseBuildArguments { source: ParseBuildArgumentsError },

#[snafu(display("failed to locate containerfile relative to the image folder"))]
NoSuchContainerfileExists,
}

#[derive(Debug, Snafu)]
Expand Down Expand Up @@ -329,9 +333,28 @@ impl Bakefile {
args.strip_architecture,
);

let dockerfile = PathBuf::new()
.join(&image_name)
.join(&args.target_containerfile);
// By using a cap-std Dir, we can ensure that the paths provided must be relative to
// the appropriate image folder and wont escape it by providing absolute or relative
// paths with traversals (..).
let image_dir = Dir::open_ambient_dir(&image_name, ambient_authority()).unwrap();

let containerfile_path = if let Some(custom_path) = &image_options.containerfile {
ensure!(
image_dir.exists(custom_path),
NoSuchContainerfileExistsSnafu
);

PathBuf::new().join(&image_name).join(custom_path)
} else {
ensure!(
image_dir.exists(&args.target_containerfile),
NoSuchContainerfileExistsSnafu
);

PathBuf::new()
.join(&image_name)
.join(&args.target_containerfile)
};

let target_name = if is_entry {
Self::format_entry_target_name(&image_name, &image_version)
Expand Down Expand Up @@ -359,7 +382,7 @@ impl Bakefile {
platforms: vec![args.target_platform.clone()],
// NOTE (@Techassi): Should this instead be scoped to the folder of the image we build
context: Some(PathBuf::from(".")),
dockerfile: Some(dockerfile),
dockerfile: Some(containerfile_path),
inherits: vec![COMMON_TARGET_NAME.to_owned()],
annotations,
contexts,
Expand Down
6 changes: 6 additions & 0 deletions rust/boil/src/build/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ pub struct ImageOptions {
// suffixed with _VERSION.
#[serde(default)]
pub build_arguments: BuildArguments,

/// A custom path to a Containerfile for a particular version of an image.
///
/// This is usefull for cases where the same image is being built differently depending on it's
/// version and it is too difficult/messy to do it the same Containerfile.
pub containerfile: Option<PathBuf>,
}

#[derive(Debug)]
Expand Down
Loading