From da48e5c1039d758704ed1c246593f0d4433f9051 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Sat, 17 Jan 2026 15:18:57 +0100 Subject: [PATCH] Actualiser bashlib.sh --- bashlib.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/bashlib.sh b/bashlib.sh index 7dc272b..2715f28 100644 --- a/bashlib.sh +++ b/bashlib.sh @@ -63,3 +63,41 @@ check_command() { fi } +# buildAnnotations [] +buildAnnotations() { + local dockerfile="$1" + local tag="$2" + local commit="${3:-}" + + if [[ ! -f "$dockerfile" ]]; then + error "Dockerfile not found" "$dockerfile" + fi + + local annotations="" + + # Parser les labels OCI existants + while IFS= read -r line; do + # Match LABEL org.opencontainers.image.* + if [[ "$line" =~ ^LABEL[[:space:]]+org\.opencontainers\.image\.([a-zA-Z0-9._-]+)=\"([^\"]*)\" ]]; then + local key="org.opencontainers.image.${BASH_REMATCH[1]}" + local value="${BASH_REMATCH[2]}" + annotations="$annotations --annotation $key=\"$value\"" + fi + done < "$dockerfile" + + # Ajouter date de build + annotations="$annotations --annotation org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" + + # Ajouter le tag de version + if [[ -n "$tag" ]]; then + annotations="$annotations --annotation org.opencontainers.image.version=$tag" + fi + + # Ajouter le commit git si fourni + if [[ -n "$commit" ]]; then + annotations="$annotations --annotation org.opencontainers.image.revision=$commit" + fi + + echo "$annotations" +} +