diff --git a/dkbuild b/dkbuild index c644e53..404ebee 100755 --- a/dkbuild +++ b/dkbuild @@ -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. Exemple: - setdists d9 d10 d11 + setdists d11 d10 d9 if dist d9; then include d9/dkbuild elif dist d10; then @@ -1345,12 +1345,8 @@ function parse_dist() { version="${dist%-*}" dist="${dist##*-}" fi - if [ "${2:-dist}" == dist ]; then upvar dist "$dist" - else local "$2"; upvar "$2" "$dist" - fi - if [ "${3:-version}" == version ]; then upvar version "$version" - else local "$3"; upvar "$3" "$version" - fi + local "${2:-dist}"; upvar "${2:-dist}" "$dist" + local "${3:-version}"; upvar "${3:-version}" "$version" } function parse_profile() { @@ -1359,12 +1355,8 @@ function parse_profile() { version="${profile%-*}" profile="${profile##*-}" fi - if [ "${2:-profile}" == profile ]; then upvar profile "$profile" - else local "$2"; upvar "$2" "$profile" - fi - if [ "${3:-version}" == version ]; then upvar version "$version" - else local "$3"; upvar "$3" "$version" - fi + local "${2:-profile}"; upvar "${2:-profile}" "$profile" + local "${3:-version}"; upvar "${3:-version}" "$version" } 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 HAVE_DVERSION declare -A dones if [ -n "$before" ]; then @@ -1490,6 +1483,12 @@ function foreach_dists_profiles() { fi for dist in "${DISTS[@]}"; do 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 parse_dist "$DIST" DIST DVERSION [ "$DIST" == "$dist" ] || continue @@ -1854,6 +1853,7 @@ function define_functions_cmd() { local pull="${DEFAULTS[build_pull]}" local host_mappings="${DEFAULTS[build_host-mappings]-__UNDEFINED__}" [ "$host_mappings" == __UNDEFINED__ ] && host_mappings="${DEFAULTS[docker_host-mappings]}" + local set_tags="${DEFAULTS[build_set-tags]}" local add_tags="${DEFAULTS[build_add-tags]}" local images="${DEFAULTS[build_images]}" local push="${DEFAULTS[build_push]}" @@ -1868,6 +1868,8 @@ function define_functions_cmd() { pull) pull=1;; pull=*) pull="${1#pull=}";; 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-tags=*) add_tags="${1#add-tags=}";; 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} [ -n "$images" ] || images="$IMAGE" + eval "set_tags=($set_tags)" eval "add_tags=($add_tags)" eval "images=($images)" local tag imagetag autotag=1 local -a imagetags - for imagetag in "${images[@]}"; do - if [[ "$imagetag" == *:* ]]; then - # le tag est déjà spécifié - autotag= - imagetags+=("$imagetag") - elif [ -n "$VERSION" -a -n "$DIST" ]; then - imagetags+=("$imagetag:$DIST" "$imagetag:$VERSION-$DIST") - for tag in "${add_tags[@]}"; do - imagetags+=("$imagetag:$tag") - done - elif [ -n "$VERSION" ]; then - imagetags+=("$imagetag:$VERSION") - for tag in "${add_tags[@]}"; do - imagetags+=("$imagetag:$tag") - done - elif [ -n "$DIST" ]; then - imagetags+=("$imagetag:$DIST") - for tag in "${add_tags[@]}"; do - imagetags+=("$imagetag:$tag") - done - fi - done + if [ ${#set_tags[*]} -gt 0 ]; then + autotag= + for imagetag in "${images[@]}"; do + if [[ "$imagetag" == *:* ]]; then + # le tag est déjà spécifié + imagetags+=("$imagetag") + else + for tag in "${set_tags[@]}" "${add_tags[@]}"; do + imagetags+=("$imagetag:$tag") + done + fi + done + else + for imagetag in "${images[@]}"; do + if [[ "$imagetag" == *:* ]]; then + # le tag est déjà spécifié + autotag= + imagetags+=("$imagetag") + else + for tag in "${add_tags[@]}"; do + imagetags+=("$imagetag:$tag") + 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 "$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 - profile DEFAULT && imagetags+=("$imagetag:latest") + if profile DEFAULT; then + imagetags+=("$imagetag:latest") + fi else imagetags+=("$imagetag:latest") fi