From 388c7b10c173bde9303b383533f2ba53b4b3ed39 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: Fri, 12 May 2023 04:09:44 +0000
Subject: [PATCH] Update generate-deploy-stages.sh

---
 generate-deploy-stages.sh | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/generate-deploy-stages.sh b/generate-deploy-stages.sh
index 39cc05e..2cc1b8b 100644
--- a/generate-deploy-stages.sh
+++ b/generate-deploy-stages.sh
@@ -8,21 +8,22 @@ cat $TRIGGER_PAYLOAD | python3 -c "import sys, json; print(json.loads(json.load(
 TAG=$(cat ${TRIGGER_PAYLOAD} | python3 -c "import sys, json; print(json.loads(json.load(sys.stdin)['payload'])['ref'])" | grep "uat")
 touch deploy.yml
 if [ ! -z "${TAG}" ]; then
-  git clone https://github.com/MAAP-Project/maap-workspaces.git
+  git clone --single-branch --branch ${TAG} https://github.com/MAAP-Project/maap-workspaces.git
   pushd maap-workspaces
-  git checkout ${TAG}
-  ls -l 
-  find "base_images" -depth 1 -type d > ${basedir}/images.txt
+  ls -d base_images/*/* > ${basedir}/images.txt
   cat ${basedir}/images.txt
   template="${basedir}/deploy.yml.tmpl"
   cat ${basedir}/images.txt | while read image
   do
-    export BASE_IMAGE_TYPE=$(basename ${image})
-    export TAG=${TAG}
-    export DIT_REGISTRY=${DIT_REGISTRY}
-    cat ${template} | CI_JOB_TOKEN='$CI_JOB_TOKEN' CI_REGISTRY='$CI_REGISTRY' envsubst >> deploy.yml
+    if [[ "$image" == base_images/*/* ]]; then
+      second_dir=$(echo "$image" | cut -d'/' -f2)
+      export BASE_IMAGE_TYPE=${second_dir}
+      export TAG=${TAG}
+      export DIT_REGISTRY=${DIT_REGISTRY}
+      cat ${template} | CI_JOB_TOKEN='$CI_JOB_TOKEN' CI_REGISTRY='$CI_REGISTRY' envsubst >> deploy.yml
+    fi
   done
 fi
 
-echo "Generate deploy.yaml"
+echo "Generate stages.yaml"
 cat deploy.yml || true
-- 
GitLab