dkbuild: début support tag & last version

This commit is contained in:
Jephté Clain 2023-01-08 13:03:40 +04:00
parent 027f9b8c45
commit 1a764f15ff
1 changed files with 50 additions and 37 deletions

87
dkbuild
View File

@ -423,7 +423,7 @@ du fichier inclus était inséré dans le script principal, à ceci près que le
répertoire courant devient temporairement celui du fichier inclus. répertoire courant devient temporairement celui du fichier inclus.
Exemple: Exemple:
setdists d9 d10 d11 setdists d11 d10 d9
if dist d9; then if dist d9; then
include d9/dkbuild include d9/dkbuild
elif dist d10; then elif dist d10; then
@ -1345,12 +1345,8 @@ function parse_dist() {
version="${dist%-*}" version="${dist%-*}"
dist="${dist##*-}" dist="${dist##*-}"
fi fi
if [ "${2:-dist}" == dist ]; then upvar dist "$dist" local "${2:-dist}"; upvar "${2:-dist}" "$dist"
else local "$2"; upvar "$2" "$dist" local "${3:-version}"; upvar "${3:-version}" "$version"
fi
if [ "${3:-version}" == version ]; then upvar version "$version"
else local "$3"; upvar "$3" "$version"
fi
} }
function parse_profile() { function parse_profile() {
@ -1359,12 +1355,8 @@ function parse_profile() {
version="${profile%-*}" version="${profile%-*}"
profile="${profile##*-}" profile="${profile##*-}"
fi fi
if [ "${2:-profile}" == profile ]; then upvar profile "$profile" local "${2:-profile}"; upvar "${2:-profile}" "$profile"
else local "$2"; upvar "$2" "$profile" local "${3:-version}"; upvar "${3:-version}" "$version"
fi
if [ "${3:-version}" == version ]; then upvar version "$version"
else local "$3"; upvar "$3" "$version"
fi
} }
function resolve_dists_profiles() { function resolve_dists_profiles() {
@ -1483,6 +1475,7 @@ function foreach_dists_profiles() {
local version dist dversion profile pversion local version dist dversion profile pversion
local VERSION DIST DVERSION PROFILE PVERSION local VERSION DIST DVERSION PROFILE PVERSION
local HAVE_DVERSION
declare -A dones declare -A dones
if [ -n "$before" ]; then if [ -n "$before" ]; then
@ -1490,6 +1483,12 @@ function foreach_dists_profiles() {
fi fi
for dist in "${DISTS[@]}"; do for dist in "${DISTS[@]}"; do
parse_dist "$dist" dist dversion parse_dist "$dist" dist dversion
HAVE_DVERSION=
for DIST in "${SETDISTS[@]}"; do
parse_dist "$DIST" DIST DVERSION
[ "$DIST" == "$dist" ] || continue
[ -n "$DVERSION" -o -n "$SETVERSION" ] && HAVE_DVERSION=1
done
for DIST in "${SETDISTS[@]}"; do for DIST in "${SETDISTS[@]}"; do
parse_dist "$DIST" DIST DVERSION parse_dist "$DIST" DIST DVERSION
[ "$DIST" == "$dist" ] || continue [ "$DIST" == "$dist" ] || continue
@ -1854,6 +1853,7 @@ function define_functions_cmd() {
local pull="${DEFAULTS[build_pull]}" local pull="${DEFAULTS[build_pull]}"
local host_mappings="${DEFAULTS[build_host-mappings]-__UNDEFINED__}" local host_mappings="${DEFAULTS[build_host-mappings]-__UNDEFINED__}"
[ "$host_mappings" == __UNDEFINED__ ] && host_mappings="${DEFAULTS[docker_host-mappings]}" [ "$host_mappings" == __UNDEFINED__ ] && host_mappings="${DEFAULTS[docker_host-mappings]}"
local set_tags="${DEFAULTS[build_set-tags]}"
local add_tags="${DEFAULTS[build_add-tags]}" local add_tags="${DEFAULTS[build_add-tags]}"
local images="${DEFAULTS[build_images]}" local images="${DEFAULTS[build_images]}"
local push="${DEFAULTS[build_push]}" local push="${DEFAULTS[build_push]}"
@ -1868,6 +1868,8 @@ function define_functions_cmd() {
pull) pull=1;; pull) pull=1;;
pull=*) pull="${1#pull=}";; pull=*) pull="${1#pull=}";;
host-mappings=*) host_mappings="${1#host-mappings=}";; host-mappings=*) host_mappings="${1#host-mappings=}";;
set-tag=*) set_tags="${1#set-tag=}";;
set-tags=*) set_tags="${1#set-tags=}";;
add-tag=*) add_tags="${1#add-tag=}";; add-tag=*) add_tags="${1#add-tag=}";;
add-tags=*) add_tags="${1#add-tags=}";; add-tags=*) add_tags="${1#add-tags=}";;
image=*) images="${1#image=}";; image=*) images="${1#image=}";;
@ -1882,37 +1884,48 @@ function define_functions_cmd() {
estep "build options:" ${build:+build} ${no_cache:+no-cache} ${pull:+pull} ${push:+push} estep "build options:" ${build:+build} ${no_cache:+no-cache} ${pull:+pull} ${push:+push}
[ -n "$images" ] || images="$IMAGE" [ -n "$images" ] || images="$IMAGE"
eval "set_tags=($set_tags)"
eval "add_tags=($add_tags)" eval "add_tags=($add_tags)"
eval "images=($images)" eval "images=($images)"
local tag imagetag autotag=1 local tag imagetag autotag=1
local -a imagetags local -a imagetags
for imagetag in "${images[@]}"; do if [ ${#set_tags[*]} -gt 0 ]; then
if [[ "$imagetag" == *:* ]]; then autotag=
# le tag est déjà spécifié for imagetag in "${images[@]}"; do
autotag= if [[ "$imagetag" == *:* ]]; then
imagetags+=("$imagetag") # le tag est déjà spécifié
elif [ -n "$VERSION" -a -n "$DIST" ]; then imagetags+=("$imagetag")
imagetags+=("$imagetag:$DIST" "$imagetag:$VERSION-$DIST") else
for tag in "${add_tags[@]}"; do for tag in "${set_tags[@]}" "${add_tags[@]}"; do
imagetags+=("$imagetag:$tag") imagetags+=("$imagetag:$tag")
done done
elif [ -n "$VERSION" ]; then fi
imagetags+=("$imagetag:$VERSION") done
for tag in "${add_tags[@]}"; do else
imagetags+=("$imagetag:$tag") for imagetag in "${images[@]}"; do
done if [[ "$imagetag" == *:* ]]; then
elif [ -n "$DIST" ]; then # le tag est déjà spécifié
imagetags+=("$imagetag:$DIST") autotag=
for tag in "${add_tags[@]}"; do imagetags+=("$imagetag")
imagetags+=("$imagetag:$tag") else
done for tag in "${add_tags[@]}"; do
fi imagetags+=("$imagetag:$tag")
done done
[ -n "$VERSION" ] && imagetags+=("$imagetag:$VERSION-$DIST")
[ -n "$DIST" -a -z "$HAVE_DVERSION" ] && imagetags+=("$imagetag:$DIST")
fi
done
fi
if [ -n "$autotag" ]; then if [ -n "$autotag" ]; then
if [ -n "$DIST" ]; then if [ -n "$DIST" ]; then
dist LATEST && imagetags+=("$imagetag:latest") if dist LATEST; then
[ -n "$HAVE_VERSION" ] && imagetags+=("$imagetag:$DIST")
imagetags+=("$imagetag:latest")
fi
elif [ -n "$PROFILE" ]; then elif [ -n "$PROFILE" ]; then
profile DEFAULT && imagetags+=("$imagetag:latest") if profile DEFAULT; then
imagetags+=("$imagetag:latest")
fi
else else
imagetags+=("$imagetag:latest") imagetags+=("$imagetag:latest")
fi fi