Improve anti-staging checker. 30/114430/7
authorJakub Latusek <j.latusek@samsung.com>
Fri, 30 Oct 2020 09:32:01 +0000 (10:32 +0100)
committerSylvain Desbureaux <sylvain.desbureaux@orange.com>
Tue, 3 Nov 2020 08:08:24 +0000 (08:08 +0000)
Checking if images are in release repository.

Signed-off-by: Jakub Latusek <j.latusek@samsung.com>
Issue-ID: OOM-2616
Change-Id: Ibb4f7e51fb3a1afcebaecd04ca3e1a4bf62dd467

kubernetes/Makefile
kubernetes/contrib/tools/check-for-staging-images.sh [new file with mode: 0755]

index db361fb..ca46ad8 100644 (file)
@@ -32,7 +32,7 @@ SUBMODS := robot aai
 EXCLUDES := config oneclick readiness test dist helm $(PARENT_CHART) dcae $(SUBMODS)
 HELM_CHARTS := $(filter-out $(EXCLUDES), $(sort $(patsubst %/.,%,$(wildcard */.)))) $(PARENT_CHART)
 
 EXCLUDES := config oneclick readiness test dist helm $(PARENT_CHART) dcae $(SUBMODS)
 HELM_CHARTS := $(filter-out $(EXCLUDES), $(sort $(patsubst %/.,%,$(wildcard */.)))) $(PARENT_CHART)
 
-.PHONY: $(EXCLUDES) $(HELM_CHARTS)
+.PHONY: $(EXCLUDES) $(HELM_CHARTS) check-for-staging-images
 
 all: $(COMMON_CHARTS_DIR) $(SUBMODS) $(HELM_CHARTS) plugins
 
 
 all: $(COMMON_CHARTS_DIR) $(SUBMODS) $(HELM_CHARTS) plugins
 
@@ -96,5 +96,10 @@ repo:
 repo-stop:
        @pkill $(HELM_BIN)
        @$(HELM_BIN) repo remove local
 repo-stop:
        @pkill $(HELM_BIN)
        @$(HELM_BIN) repo remove local
+
+check-for-staging-images:
+       $(ROOT_DIR)/contrib/tools/check-for-staging-images.sh
+
 %:
        @:
 %:
        @:
+
diff --git a/kubernetes/contrib/tools/check-for-staging-images.sh b/kubernetes/contrib/tools/check-for-staging-images.sh
new file mode 100755 (executable)
index 0000000..ce51b30
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+# Copyright © 2020 Samsung Electronics
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+BASE_URL="https://nexus3.onap.org/repository/docker.release"
+
+if [ "$GERRIT_BRANCH" == "staging" ]; then
+    exit 0
+fi
+
+USED_IMAGES=$(grep -r -E -o -h ':\s*onap/.*:.*' | sed -e 's/^: //' -e 's/^ //' | sort | uniq)
+REPO_IMAGES=$(curl -s $BASE_URL/v2/_catalog | jq -r '.repositories[]')
+NOT_AVAILABLE_IMAGES=$(echo "$USED_IMAGES" | grep -vE  "$(echo "$REPO_IMAGES" | tr "\n" "|" | sed 's/|$//')")
+USED_IMAGES=$(echo "$USED_IMAGES" | grep -E "$(echo "$REPO_IMAGES" | tr "\n" "|" | sed 's/|$//')")
+for i in $USED_IMAGES; do
+    TMP_IMG=$(echo "$i" | cut -d ":" -f1)
+    TMP_TAG=$(echo "$i" | cut -d ":" -f2)
+    if [ "$LAST_IMG" != "$TMP_IMG" ]; then
+        AVAILABLE_TAGS=$(curl -s $BASE_URL/v2/$TMP_IMG/tags/list | jq -r '.tags[]')
+    fi
+    if ! echo "$AVAILABLE_TAGS" | grep "$TMP_TAG" > /dev/null; then
+        NOT_AVAILABLE_IMAGES="$NOT_AVAILABLE_IMAGES\n$i"
+    fi
+    LAST_IMG="$TMP_IMG"
+    printf "."
+done
+printf "\n"
+if [ -n "$NOT_AVAILABLE_IMAGES" ]; then
+    echo "[ERROR] Only release images are allowed in helm charts."
+    echo "[ERROR] Images not found in release repo:"
+    echo -e "$NOT_AVAILABLE_IMAGES"
+    exit 1
+fi
+exit 0
\ No newline at end of file