enforce_labels.bash 727 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash

image_name="$1"

declare -A enforced_labels=( ["com.jfrog.artifactory.retention.maxCount"]="10" ["com.jfrog.artifactory.retention.maxDays"]="7")

if ! docker inspect --type=image $1 > /dev/null ; then 
    echo "Error: image does not exist"
    exit 0
fi

for label in "${!enforced_labels[@]}" ; do     
    if ! docker inspect -f "{{json .Config.Labels }}" $image_name | jq -e '.['\"$label\"']' ; then 
        echo "Key not found" 
        echo "$label = ${enforced_labels[$label]}"
        label_args+=" --label $label=\"${enforced_labels[$label]}\""
    fi    
done

if [ -v label_args ]; then 
    run_command="echo \"FROM $image_name\" | docker build $label_args -t $image_name -"
    eval "$run_command"
fi