Skip to content
Merged
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
6 changes: 1 addition & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ git2 = "0.20.1"
glob = "0.3.2"
oci-spec = "0.9.0"
rstest = "0.26.1"
semver = { version = "1.0.26", features = ["serde"] }
regex = "1.12.3"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.140"
snafu = "0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion rust/boil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ clap_complete_nushell.workspace = true
git2.workspace = true
glob.workspace = true
oci-spec.workspace = true
semver.workspace = true
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
snafu.workspace = true
Expand Down
32 changes: 19 additions & 13 deletions rust/boil/src/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::{
fmt::{Debug, Display},
path::PathBuf,
str::FromStr,
sync::LazyLock,
};

use clap::{Args, ValueHint, value_parser};
use semver::Version;
use regex::Regex;
use snafu::{ResultExt, Snafu, ensure};
use strum::EnumDiscriminants;
use url::Host;
Expand All @@ -30,7 +31,7 @@ pub struct BuildArguments {
default_value_t = Self::default_image_version(),
help_heading = "Image Options"
)]
pub image_version: Version,
pub image_version: String,

/// Target platform of the image.
#[arg(
Expand Down Expand Up @@ -129,16 +130,24 @@ pub struct BuildArguments {
pub rest: Vec<String>,
}

// This is derived from the general rule where the length of the tag can be up to 128 chars
// See: https://github.com/opencontainers/distribution-spec/blob/main/spec.md
// But that checking needs to be at a higher layer.
static VALID_IMAGE_TAG: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[a-zA-Z0-9_][a-zA-Z0-9_.-]+$").expect("regex is valid"));

impl BuildArguments {
fn parse_image_version(input: &str) -> Result<Version, ParseImageVersionError> {
let version = Version::from_str(input).context(ParseVersionSnafu)?;
ensure!(version.build.is_empty(), ContainsBuildMetadataSnafu);
/// Ensure that the given version will be valid for use in the image tag
fn parse_image_version(version: &str) -> Result<String, ParseImageVersionError> {
if !VALID_IMAGE_TAG.is_match(version) {
return ParseVersionSnafu { version }.fail();
}

Ok(version)
Ok(version.to_owned())
}

fn default_image_version() -> Version {
"0.0.0-dev".parse().expect("must be a valid SemVer")
fn default_image_version() -> String {
"0.0.0-dev".to_owned()
}

fn default_registry() -> HostPort {
Expand All @@ -160,11 +169,8 @@ impl BuildArguments {

#[derive(Debug, Snafu)]
pub enum ParseImageVersionError {
#[snafu(display("failed to parse semantic version"))]
ParseVersion { source: semver::Error },

#[snafu(display("semantic version must not contain build metadata"))]
ContainsBuildMetadata,
#[snafu(display("invalid image tag characters for {version:?}"))]
ParseVersion { version: String },
}

#[derive(Debug, PartialEq, Snafu, EnumDiscriminants)]
Expand Down
6 changes: 0 additions & 6 deletions rust/boil/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ pub enum Error {
/// This is the `boil build` command handler function.
pub fn run_command(args: Box<BuildArguments>, config: Config) -> Result<(), Error> {
Comment thread
NickLarsenNZ marked this conversation as resolved.
// TODO (@Techassi): Parse Dockerfile instead to build the target graph
Comment thread
NickLarsenNZ marked this conversation as resolved.
// Validation
ensure!(
args.image_version.build.is_empty(),
InvalidImageVersionSnafu
);

// Create bakefile
let bakefile = Bakefile::from_cli_args(&args, config).context(CreateBakefileSnafu)?;
let image_manifest_uris = bakefile.image_manifest_uris();
Expand Down
6 changes: 2 additions & 4 deletions rust/boil/src/core/bakefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ 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, ensure};
use time::format_description::well_known::Rfc3339;

use crate::{
VersionExt,
cli::{self, HostPort},
config::{self, Config, Metadata},
constants::DOCKER_LABEL_BUILD_DATE,
Expand Down Expand Up @@ -294,7 +292,7 @@ impl Bakefile {
let target = BakefileTarget::common(
date_time,
revision,
cli_args.image_version.base_prerelease(),
cli_args.image_version.clone(),
container_build_args,
user_container_build_args,
metadata,
Expand Down Expand Up @@ -642,7 +640,7 @@ impl BakefileTarget {
fn image_version_annotation(
image_version: &str,
vendor_tag_prefix: &str,
vendor_image_version: &Version,
vendor_image_version: &str,
) -> Vec<String> {
let image_index_manifest_tag = utils::format_image_index_manifest_tag(
image_version,
Expand Down
34 changes: 0 additions & 34 deletions rust/boil/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use clap::Parser;
use semver::Version;
use snafu::{ResultExt, Snafu};

use crate::{
Expand Down Expand Up @@ -46,39 +45,6 @@ impl<T> IfContext for T {
}
}

pub trait VersionExt {
/// Returns the base of a [`Version`] as a string, eg. `1.2.3`.
fn base(&self) -> String;

/// Returns the base and prerelease of a [`Version`] as a string, eg. `1.2.3-rc.1`.
fn base_prerelease(&self) -> String;
}

impl VersionExt for Version {
fn base(&self) -> String {
let Self {
major,
minor,
patch,
..
} = self;

format!("{major}.{minor}.{patch}")
}

fn base_prerelease(&self) -> String {
let mut base = self.base();

// Well, that was a big doozy, ruined the whole release...
if !self.pre.is_empty() {
base.push('-');
base.push_str(&self.pre);
}

base
}
}

#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("failed to run build command"))]
Expand Down
4 changes: 1 addition & 3 deletions rust/boil/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::process::Command;

use semver::Version;

use crate::{cli::HostPort, core::platform::Architecture};

/// Formats and returns the image repository URI, eg. `oci.stackable.tech/sdp/opa`.
Expand All @@ -22,7 +20,7 @@ pub fn format_image_manifest_uri(image_repository_uri: &str, image_manifest_tag:
pub fn format_image_index_manifest_tag(
image_version: &str,
vendor_tag_prefix: &str,
vendor_image_version: &Version,
vendor_image_version: &str,
) -> String {
format!("{image_version}-{vendor_tag_prefix}{vendor_image_version}")
}
Expand Down
3 changes: 1 addition & 2 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

pkgs.mkShell {
packages = with pkgs; [
cargo
rustc
rustup
nodejs
zizmor
];
Expand Down
Loading