Skip to content

Commit bba099d

Browse files
committed
fix(boil): Write cache config in proper format
1 parent 132719d commit bba099d

1 file changed

Lines changed: 40 additions & 8 deletions

File tree

rust/boil/src/core/bakefile.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
collections::{BTreeMap, btree_map::Entry},
3-
fmt::Debug,
3+
fmt::{Debug, Display},
44
ops::{Deref, DerefMut},
55
path::PathBuf,
66
};
@@ -349,7 +349,7 @@ impl Bakefile {
349349
image_registry,
350350
&cli_args.registry_namespace,
351351
&image_name,
352-
&cli_args.image_version,
352+
&image_version,
353353
&metadata.vendor_tag_prefix,
354354
&cli_args.image_version,
355355
cli_args.target_platform.architecture(),
@@ -568,6 +568,7 @@ impl Bakefile {
568568
// TODO (@Techassi): Figure out of we can use borrowed data in here. This would avoid a whole bunch
569569
// of cloning.
570570
#[derive(Debug, Default, Serialize)]
571+
#[serde(rename_all = "kebab-case")]
571572
pub struct BakefileTarget {
572573
/// Defines build arguments for the target.
573574
#[serde(
@@ -714,22 +715,53 @@ pub struct BakefileGroup {
714715
targets: Vec<String>,
715716
}
716717

717-
#[derive(Clone, Debug, Serialize)]
718-
#[serde(tag = "type", rename_all = "lowercase")]
718+
#[derive(Clone, Debug)]
719719
pub enum CacheStorageBackend {
720720
Registry {
721721
/// Full name of the cache image to import.
722-
#[serde(rename = "ref")]
723722
reference: String,
724723

725-
#[serde(skip_serializing_if = "Option::is_none")]
724+
/// Specifies which layers to cache
726725
mode: Option<CacheMode>,
727726
},
728727
}
729728

730-
#[derive(Clone, Copy, Debug, Serialize)]
731-
#[serde(rename_all = "lowercase")]
729+
impl Display for CacheStorageBackend {
730+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
731+
match self {
732+
CacheStorageBackend::Registry { reference, mode } => {
733+
f.write_str("type=registry")?;
734+
f.write_fmt(format_args!(",ref={reference}"))?;
735+
736+
if let Some(mode) = mode {
737+
f.write_fmt(format_args!(",mode={mode}"))?;
738+
}
739+
740+
Ok(())
741+
}
742+
}
743+
}
744+
}
745+
746+
impl Serialize for CacheStorageBackend {
747+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
748+
where
749+
S: serde::Serializer,
750+
{
751+
serializer.serialize_str(&self.to_string())
752+
}
753+
}
754+
755+
#[derive(Clone, Copy, Debug)]
732756
pub enum CacheMode {
733757
// We currently only support max, because we want to cache every layer
734758
Max,
735759
}
760+
761+
impl Display for CacheMode {
762+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
763+
match self {
764+
CacheMode::Max => write!(f, "max"),
765+
}
766+
}
767+
}

0 commit comments

Comments
 (0)