Actualiser bashlib.sh

This commit is contained in:
2026-01-17 15:18:57 +01:00
parent ab43c8df13
commit da48e5c103

View File

@@ -63,3 +63,41 @@ check_command() {
fi
}
# buildAnnotations <Dockerfile> <image_tag> [<commit_hash>]
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"
}