feat: Include base image information in labels

This commit is contained in:
Gerald Pinder 2024-11-13 23:55:23 -05:00
parent 3674f83fd2
commit e3b246ef91
10 changed files with 246 additions and 193 deletions

View file

@ -13,6 +13,7 @@ rinja = { version = "0.3", features = ["serde_json"] }
blue-build-recipe = { version = "=0.8.20", path = "../recipe" }
blue-build-utils = { version = "=0.8.20", path = "../utils" }
chrono.workspace = true
log.workspace = true
colored.workspace = true
bon.workspace = true

View file

@ -5,6 +5,7 @@ use blue_build_utils::constants::{
CONFIG_PATH, CONTAINERFILES_PATH, CONTAINER_FILE, COSIGN_PUB_PATH, FILES_PATH,
};
use bon::Builder;
use chrono::Utc;
use colored::control::ShouldColorize;
use log::{debug, error, trace, warn};
use uuid::Uuid;
@ -27,6 +28,7 @@ pub struct ContainerFileTemplate<'a> {
registry: Cow<'a, str>,
build_scripts_image: Cow<'a, str>,
repo: Cow<'a, str>,
base_digest: Cow<'a, str>,
}
#[derive(Debug, Clone, Template, Builder)]
@ -111,6 +113,10 @@ fn config_dir_exists() -> bool {
exists
}
fn current_timestamp() -> String {
Utc::now().to_rfc3339()
}
fn should_color() -> bool {
ShouldColorize::from_env().should_colorize()
}

View file

@ -2,7 +2,7 @@
{%- include "stages.j2" %}
# Main image
FROM {{ recipe.base_image }}:{{ recipe.image_version }} AS {{ recipe.name|replace('/', "-") }}
FROM {{ recipe.base_image }}@{{ base_digest }} AS {{ recipe.name|replace('/', "-") }}
ARG RECIPE={{ recipe_path.display() }}
ARG IMAGE_REGISTRY={{ registry }}
@ -46,4 +46,7 @@ LABEL {{ blue_build_utils::constants::BUILD_ID_LABEL }}="{{ build_id }}"
LABEL org.opencontainers.image.title="{{ recipe.name }}"
LABEL org.opencontainers.image.description="{{ recipe.description }}"
LABEL org.opencontainers.image.source="{{ repo }}"
LABEL org.opencontainers.image.base.digest="{{ base_digest }}"
LABEL org.opencontainers.image.base.name="{{ recipe.base_image }}:{{ recipe.image_version }}"
LABEL org.opencontainers.image.created="{{ self::current_timestamp() }}"
LABEL io.artifacthub.package.readme-url=https://raw.githubusercontent.com/blue-build/cli/main/README.md