Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 2 additions & 5 deletions rust/boil/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ boil build airflow opa

# Display a list of all images and their declared versions as structured JSON
# output
boil show images
boil image list

# Display a list of versions of the image located in the 'airflow' folder
boil show images airflow

# Soon (hopefully) implemented
boil show graph
boil image list airflow
```
6 changes: 3 additions & 3 deletions rust/boil/src/build/cli.rs → rust/boil/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ use snafu::{ResultExt, Snafu, ensure};
use strum::EnumDiscriminants;
use url::Host;

use crate::build::{
use crate::core::{
docker::BuildArgument,
image::Image,
image::ImageSelector,
platform::{Architecture, TargetPlatform},
};

#[derive(Debug, Args)]
pub struct BuildArguments {
/// The image(s) which should be build. The format is name[=version,...].
#[arg(help_heading = "Image Options", required = true)]
pub images: Vec<Image>,
pub images: Vec<ImageSelector>,

// NOTE (@Techassi): Should this maybe be renamed to vendor_version?
/// The image version being built.
Expand Down
26 changes: 26 additions & 0 deletions rust/boil/src/cli/completions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use clap::{Args, ValueEnum};

#[derive(Debug, Args)]
pub struct CompletionsArguments {
/// Shell to generate completions for.
#[arg(value_enum)]
pub shell: Shell,
}

#[derive(Clone, Debug, ValueEnum)]
pub enum Shell {
/// Bourne Again SHell
Bash,

/// Elvish shell
Elvish,

/// Friendly Interactive SHell
Fish,

/// Z SHell
Zsh,

/// Nushell
Nushell,
}
19 changes: 15 additions & 4 deletions rust/boil/src/show/images/cli.rs → rust/boil/src/cli/image.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
use clap::{Args, ValueEnum};
use clap::{Args, Subcommand, ValueEnum};

use crate::build::image::Image;
use crate::core::image::ImageSelector;

#[derive(Debug, Args)]
pub struct ShowImagesArguments {
pub struct ImageArguments {
#[command(subcommand)]
pub command: ImageCommand,
}

#[derive(Debug, Subcommand)]
pub enum ImageCommand {
List(ImageListArguments),
}

#[derive(Debug, Args)]
pub struct ImageListArguments {
/// Optionally specify one or more images to display.
pub image: Vec<Image>,
pub image: Vec<ImageSelector>,

/// Pretty print the structured output.
#[arg(long, value_enum, default_value_t = Pretty::default())]
Expand Down
13 changes: 11 additions & 2 deletions rust/boil/src/cli.rs → rust/boil/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ use std::path::PathBuf;

use clap::{Parser, Subcommand};

use crate::{build::cli::BuildArguments, completions::CompletionsArguments, show::ShowArguments};
mod build;
mod completions;
mod image;

pub use build::*;
pub use completions::*;
pub use image::*;

#[derive(Debug, Parser)]
#[command(author, version, about)]
Expand Down Expand Up @@ -30,7 +36,10 @@ pub enum Command {
Build(Box<BuildArguments>),

/// Display various structured outputs in JSON format.
Show(ShowArguments),
Image(ImageArguments),

/// Alias for `image list`.
Images(ImageListArguments),

/// Generate shell completions.
Completions(CompletionsArguments),
Expand Down
9 changes: 2 additions & 7 deletions rust/boil/src/build/mod.rs → rust/boil/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ use std::{
use snafu::{OptionExt, ResultExt, Snafu, ensure};

use crate::{
build::{bakefile::Bakefile, cli::BuildArguments},
cli::BuildArguments,
config::Config,
core::bakefile::{self, Bakefile},
utils::CommandExt,
};

pub mod bakefile;
pub mod cli;
pub mod docker;
pub mod image;
pub mod platform;

#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("failed to create bakefile"))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
use clap::{Args, Command, CommandFactory, ValueEnum};
use clap::{Command, CommandFactory};
use clap_complete::{
Generator,
Shell::{Bash, Elvish, Fish, Zsh},
};
use clap_complete_nushell::Nushell;

use crate::cli::Cli;

#[derive(Debug, Args)]
pub struct CompletionsArguments {
/// Shell to generate completions for.
#[arg(value_enum)]
pub shell: Shell,
}

#[derive(Clone, Debug, ValueEnum)]
pub enum Shell {
/// Bourne Again SHell
Bash,

/// Elvish shell
Elvish,

/// Friendly Interactive SHell
Fish,

/// Z SHell
Zsh,

/// Nushell
Nushell,
}
use crate::cli::{Cli, CompletionsArguments, Shell};

/// This is the `boil completions` command handler function.
pub fn run_command(arguments: CompletionsArguments) {
Expand Down
10 changes: 4 additions & 6 deletions rust/boil/src/show/images/mod.rs → rust/boil/src/cmd/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ use std::{collections::BTreeMap, io::IsTerminal};
use snafu::{ResultExt, Snafu};

use crate::{
build::bakefile::{Targets, TargetsError, TargetsOptions},
show::images::cli::{Pretty, ShowImagesArguments},
cli::{ImageListArguments, Pretty},
core::bakefile::{self, Targets, TargetsOptions},
};

pub mod cli;

#[derive(Debug, Snafu)]
pub enum Error {
#[snafu(display("failed to serialize list as JSON"))]
SerializeList { source: serde_json::Error },

#[snafu(display("failed to build list of targets"))]
BuildTargets { source: TargetsError },
BuildTargets { source: bakefile::TargetsError },
}

/// This is the `boil show images` command handler function.
pub fn run_command(arguments: ShowImagesArguments) -> Result<(), Error> {
pub fn list_images(arguments: ImageListArguments) -> Result<(), Error> {
let list: BTreeMap<_, _> = if arguments.image.is_empty() {
Targets::all(TargetsOptions { only_entry: true })
.context(BuildTargetsSnafu)?
Expand Down
3 changes: 3 additions & 0 deletions rust/boil/src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod build;
pub mod completions;
pub mod image;
4 changes: 2 additions & 2 deletions rust/boil/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::Deserialize;
use snafu::{ResultExt, Snafu};
use url::Url;

use crate::build::docker::BuildArguments;
use crate::core::docker;

#[derive(Debug, Snafu)]
pub enum ConfigError {
Expand All @@ -16,7 +16,7 @@ pub enum ConfigError {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Config {
pub build_arguments: BuildArguments,
pub build_arguments: docker::BuildArguments,
pub metadata: Metadata,
}

Expand Down
2 changes: 2 additions & 0 deletions rust/boil/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Label key for the date and time on which the image was built.
pub const DOCKER_LABEL_BUILD_DATE: &str = "build-date";
50 changes: 28 additions & 22 deletions rust/boil/src/build/bakefile.rs → rust/boil/src/core/bakefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ use time::format_description::well_known::Rfc3339;

use crate::{
VersionExt,
build::{
cli::{self, HostPort},
docker::{BuildArgument, BuildArguments, LABEL_BUILD_DATE, ParseBuildArgumentsError},
image::{Image, ImageConfig, ImageConfigError, ImageOptions, VersionOptionsPair},
cli::{self, HostPort},
config::{self, Config, Metadata},
constants::DOCKER_LABEL_BUILD_DATE,
core::{
docker,
image::{ImageConfig, ImageConfigError, ImageOptions, ImageSelector, VersionOptionsPair},
platform::TargetPlatform,
},
config::{self, Config, Metadata},
utils,
};

Expand Down Expand Up @@ -55,7 +56,9 @@ pub enum Error {
CreateGraph { source: TargetsError },

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

#[snafu(display("failed to locate containerfile relative to the {path:?} directory"))]
NoSuchContainerfileExists { path: String },
Expand Down Expand Up @@ -162,7 +165,7 @@ impl Targets {
/// Returns a filtered set out of all targets by looking up selected image config files.
///
/// The search behaviour can be customized using the provided [`TargetsOptions`].
pub fn set(images: &[Image], options: TargetsOptions) -> Result<Self, TargetsError> {
pub fn set(images: &[ImageSelector], options: TargetsOptions) -> Result<Self, TargetsError> {
let mut targets = Self::default();

for image in images {
Expand Down Expand Up @@ -274,7 +277,7 @@ impl Bakefile {
/// Creates the common target, containing shared data, which will be inherited by other targets.
fn common_target(
cli_args: &cli::BuildArguments,
container_build_args: BuildArguments,
container_build_args: docker::BuildArguments,
metadata: &Metadata,
) -> Result<BakefileTarget, Error> {
let revision = Self::git_head_revision().context(GetRevisionSnafu)?;
Expand All @@ -284,7 +287,7 @@ impl Bakefile {
let mut user_container_build_args = cli_args.build_arguments.clone();
if let Some(path) = &cli_args.build_arguments_file {
let build_arguments_from_file =
BuildArguments::from_file(path).context(ParseBuildArgumentsSnafu)?;
docker::BuildArguments::from_file(path).context(ParseBuildArgumentsSnafu)?;
user_container_build_args.extend(build_arguments_from_file);
}

Expand Down Expand Up @@ -350,13 +353,13 @@ impl Bakefile {

// TODO (@Techassi): Clean this up
// TODO (@Techassi): Move the arg formatting into functions
let mut build_arguments = BuildArguments::new();
let mut build_arguments = docker::BuildArguments::new();

let local_version_docker_args: Vec<_> = image_options
.local_images
.iter()
.map(|(image_name, image_version)| {
BuildArgument::local_image_version(
docker::BuildArgument::local_image_version(
image_name.to_string(),
image_version.to_string(),
)
Expand All @@ -366,23 +369,23 @@ impl Bakefile {
build_arguments.extend(image_options.build_arguments);
build_arguments.extend(local_version_docker_args);
// TODO (@Techassi): Rename this to IMAGE_VERSION
build_arguments.insert(BuildArgument::new(
build_arguments.insert(docker::BuildArgument::new(
"PRODUCT_VERSION".to_owned(),
image_version.to_string(),
));
build_arguments.insert(BuildArgument::new(
build_arguments.insert(docker::BuildArgument::new(
"IMAGE_REPOSITORY_URI".to_owned(),
image_repository_uri,
));
build_arguments.insert(BuildArgument::new(
build_arguments.insert(docker::BuildArgument::new(
"IMAGE_INDEX_MANIFEST_TAG".to_owned(),
image_index_manifest_tag,
));
build_arguments.insert(BuildArgument::new(
build_arguments.insert(docker::BuildArgument::new(
"IMAGE_MANIFEST_TAG".to_owned(),
image_manifest_tag,
));
build_arguments.insert(BuildArgument::new(
build_arguments.insert(docker::BuildArgument::new(
"IMAGE_MANIFEST_URI".to_owned(),
image_manifest_uri.clone(),
));
Expand Down Expand Up @@ -518,8 +521,11 @@ impl Bakefile {
#[derive(Debug, Default, Serialize)]
pub struct BakefileTarget {
/// Defines build arguments for the target.
#[serde(rename = "args", skip_serializing_if = "BuildArguments::is_empty")]
pub arguments: BuildArguments,
#[serde(
rename = "args",
skip_serializing_if = "docker::BuildArguments::is_empty"
)]
pub arguments: docker::BuildArguments,

/// Adds annotations to images built with bake.
#[serde(skip_serializing_if = "Vec::is_empty")]
Expand Down Expand Up @@ -568,8 +574,8 @@ impl BakefileTarget {
date_time: String,
revision: String,
release_version: String,
container_build_args: BuildArguments,
user_container_build_args: Vec<BuildArgument>,
container_build_args: docker::BuildArguments,
user_container_build_args: Vec<docker::BuildArgument>,
metadata: &Metadata,
) -> Self {
let config::Metadata {
Expand Down Expand Up @@ -611,7 +617,7 @@ impl BakefileTarget {

let mut arguments = container_build_args;
arguments.extend(user_container_build_args);
arguments.insert(BuildArgument::new(
arguments.insert(docker::BuildArgument::new(
"RELEASE_VERSION".to_owned(),
release_version,
));
Expand All @@ -622,7 +628,7 @@ impl BakefileTarget {
let labels = BTreeMap::from([
(ANNOTATION_CREATED.to_owned(), date_time.clone()),
(ANNOTATION_REVISION.to_owned(), revision),
(LABEL_BUILD_DATE.to_owned(), date_time),
(DOCKER_LABEL_BUILD_DATE.to_owned(), date_time),
]);

Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use std::{
use serde::{Deserialize, Serialize, de::Visitor, ser::SerializeMap};
use snafu::{OptionExt, ResultExt, Snafu, ensure};

/// Label key for the date and time on which the image was built.
pub const LABEL_BUILD_DATE: &str = "build-date";

#[derive(Debug, Snafu)]
pub enum ParseBuildArgumentError {
#[snafu(display("invalid format, expected <key>=<value>"))]
Expand Down
Loading
Loading