mirror of
https://codeberg.org/icewind/haze.git
synced 2026-10-01 08:44:09 +02:00
record haze version when building images and warn on out of date images
This commit is contained in:
parent
6fdadd9bad
commit
63e17d609f
3 changed files with 60 additions and 2 deletions
37
src/image.rs
37
src/image.rs
|
|
@ -5,11 +5,48 @@ use futures_util::StreamExt;
|
|||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
|
||||
use miette::{IntoDiagnostic, Result, WrapErr};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
|
||||
pub struct ImageVersion {
|
||||
pub major: u8,
|
||||
pub minor: u8,
|
||||
pub patch: u8,
|
||||
}
|
||||
|
||||
impl FromStr for ImageVersion {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
let mut parts = s.split('.');
|
||||
let major = parts.next().ok_or(())?.parse().map_err(|_| ())?;
|
||||
let minor = parts.next().ok_or(())?.parse().map_err(|_| ())?;
|
||||
let patch = parts.next().ok_or(())?.parse().map_err(|_| ())?;
|
||||
Ok(ImageVersion {
|
||||
major,
|
||||
minor,
|
||||
patch,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ImageVersion {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn image_exists(docker: &Docker, image: &str) -> bool {
|
||||
docker.inspect_image(image).await.is_ok()
|
||||
}
|
||||
|
||||
pub async fn image_version(docker: &Docker, image: &str) -> Option<ImageVersion> {
|
||||
let labels = docker.inspect_image(image).await.ok()?.config?.labels?;
|
||||
let label = labels.get("nl.icewind.haze.version")?;
|
||||
ImageVersion::from_str(label).ok()
|
||||
}
|
||||
|
||||
pub async fn update_image(docker: &Docker, image: &str) -> Result<()> {
|
||||
if image_exists(docker, image).await {
|
||||
force_pull_image(docker, image).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue