From 58a0bce5c986eb8a1cc5041894fc8c0a269f6b4d Mon Sep 17 00:00:00 2001
From: Jon Azpiazu <jon.azpiazu@tecnalia.com>
Date: Tue, 23 Nov 2021 09:46:11 +0100
Subject: [PATCH] Add comments to script

---
 scripts/enforce_labels.bash | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/scripts/enforce_labels.bash b/scripts/enforce_labels.bash
index 8f6f195..f0ab26d 100644
--- a/scripts/enforce_labels.bash
+++ b/scripts/enforce_labels.bash
@@ -1,4 +1,7 @@
 #!/bin/bash
+# From a given list of labels, check which of them are already defined in the provided docker image; if any of the labels
+# is not defined, a new image with the same name is generated with the label(s) added.
+# Labels already defined are not modified.
 
 if [ "$#" -ne 1 ]; then
     echo "Usage: $0 IMAGE_NAME"
@@ -7,6 +10,7 @@ fi
 
 image_name="$1"
 
+# list of labels to be enforced
 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
@@ -14,14 +18,17 @@ if ! docker inspect --type=image "$1" > /dev/null ; then
     exit 0
 fi
 
+# check if every label is defined
 for label in "${!enforced_labels[@]}" ; do
     if ! docker inspect -f "{{json .Config.Labels }}" "$image_name" | jq -e '.['\""$label"\"']' > /dev/null ; then
         echo "Key not found"
         echo "$label = ${enforced_labels[$label]}"
+        # add missing label to the arguments to be provided to `docker build`
         label_args+=" --label $label=\"${enforced_labels[$label]}\""
     fi
 done
 
+# generate new image
 if [ -n "${label_args+x}" ]; then
     run_command="echo \"FROM $image_name\" | docker build $label_args -t $image_name -"
     eval "$run_command"
-- 
GitLab