From cbf47d892760aa1274361dfc16a99a58baac28a1 Mon Sep 17 00:00:00 2001 From: bhumi46 Date: Tue, 3 Dec 2024 16:16:02 +0530 Subject: [PATCH] [MOSIP-38035] updated postgres init, keycloak init and prereq.sh Signed-off-by: bhumi46 --- deploy/init_values.yaml | 18 +++++++++ deploy/keycloak/keycloak-init.sh | 4 +- deploy/postgres-init.sh | 68 ++++++++++++++++++++++++-------- deploy/prereq.sh | 7 ++-- 4 files changed, 76 insertions(+), 21 deletions(-) diff --git a/deploy/init_values.yaml b/deploy/init_values.yaml index e3e9c806..60b49184 100644 --- a/deploy/init_values.yaml +++ b/deploy/init_values.yaml @@ -3,7 +3,25 @@ dbUserPasswords: databases: mosip_audit: enabled: true + host: "esignet-postgres.es-dev.mosip.net" + port: 5432 + su: + user: postgres + secret: + name: postgres-postgresql + key: postgres-password + dml: 0 + repoUrl: https://github.com/mosip/audit-manager.git branch: develop mosip_kernel: enabled: true + host: "esignet-postgres.es-dev.mosip.net" + port: 5432 + su: + user: postgres + secret: + name: postgres-postgresql + key: postgres-password + dml: 0 + repoUrl: https://github.com/mosip/commons.git branch: develop diff --git a/deploy/keycloak/keycloak-init.sh b/deploy/keycloak/keycloak-init.sh index 1a8c021f..26a1973c 100755 --- a/deploy/keycloak/keycloak-init.sh +++ b/deploy/keycloak/keycloak-init.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Initialises signup keycloak-init ## Usage: ./keycloak-init.sh [kubeconfig] @@ -34,7 +34,7 @@ $COPY_UTIL secret keycloak keycloak $NS echo "creating and adding roles to keycloak pms & mpartner_default_auth clients for ESIGNET" kubectl -n $NS delete secret --ignore-not-found=true keycloak-client-secrets -helm -n $NS delete signup-keycloak-init +helm -n $NS delete signup-keycloak-init || true helm -n $NS install signup-keycloak-init mosip/keycloak-init \ -f keycloak-init-values.yaml \ --set clientSecrets[0].name="$SIGNUP_CLIENT_SECRET_KEY" \ diff --git a/deploy/postgres-init.sh b/deploy/postgres-init.sh index 2ebf6fc1..df7eb68e 100755 --- a/deploy/postgres-init.sh +++ b/deploy/postgres-init.sh @@ -1,36 +1,72 @@ #!/bin/bash -# Script to initialize the DB. +# Script to initialize the DB. ## Usage: ./init_db.sh [kubeconfig] if [ $# -ge 1 ] ; then export KUBECONFIG=$1 fi +# Function to initialize the DB function initialize_db() { - NS=postgres + NS=signup CHART_VERSION=0.0.1-develop helm repo update + + # Confirm if the user wants to initialize DB scripts while true; do - read -p "CAUTION: all existing data will be lost. Are you sure?(Y/n)" yn - if [ $yn = "Y" ] - then - echo Removing any existing installation - helm -n $NS delete postgres-init || true - kubectl -n $NS delete secret db-common-secrets || true - echo Initializing DB - helm -n $NS install postgres-init mosip/postgres-init -f init_values.yaml --version $CHART_VERSION --wait --wait-for-jobs - break - else + read -p "Are the modules of the MOSIP platform already deployed? (Y/n): " yn + if [[ "$yn" == "Y" || "$yn" == "y" ]]; then + echo "Exiting as MOSIP platform modules are already deployed.No need to initialize db again" + exit 0 + elif [[ "$yn" == "N" || "$yn" == "n" ]]; then + echo "Initializing DB scripts for MOSIP_KERNEL and MOSIP_AUDIT, because mosip platform modules are not deployed yet" + break + else + echo "Invalid input. Please enter Y for Yes or N for No." + fi + done + + while true; do + read -p "Please confirm with "Y" once init-values.yaml is updated correctly with tag, postgres host details else "N" to exit installation: " ans + if [ "$ans" = "Y" ] || [ "$ans" = "y" ]; then break + elif [ "$ans" = "N" ] || [ "$ans" = "n" ]; then + exit 1 + else + echo "Please provide a correct option (Y or N)" fi done + + # Prompt for dbuserPassword + echo "Please provide the dbuserPassword" + read -s dbuserPassword + if [ -z "$dbuserPassword" ]; then + echo "ERROR: dbuserPassword not specified; EXITING." + exit 1 + fi + + # Initialize DB + echo "Removing any existing installation..." + helm -n $NS delete postgres-init || true + kubectl -n $NS delete secret db-common-secrets || true + ./copy_cm_func.sh secret postgres-postgresql postgres $NS + + echo "Initializing DB..." + helm -n $NS install postgres-init mosip/postgres-init -f init_values.yaml \ + --version $CHART_VERSION \ + --set dbUserPasswords.dbuserPassword="$dbuserPassword" \ + --wait --wait-for-jobs + + echo "Database initialization complete." return 0 } -# set commands for error handling. +# Set commands for error handling set -e -set -o errexit ## set -e : exit the script if any statement returns a non-true return value -set -o nounset ## set -u : exit the script if you try to use an uninitialised variable +set -o errexit ## exit the script if any statement returns a non-true return value +set -o nounset ## exit the script if you try to use an uninitialized variable set -o errtrace # trace ERR through 'time command' and other functions set -o pipefail # trace ERR through pipes -initialize_db # calling function + +# Call the function +initialize_db diff --git a/deploy/prereq.sh b/deploy/prereq.sh index 77d423d4..d4eaa9d2 100755 --- a/deploy/prereq.sh +++ b/deploy/prereq.sh @@ -50,7 +50,7 @@ function installing_prereq() { kubectl -n $NS create secret generic signup-captcha --from-literal=signup-captcha-site-key=$SSITE_KEY --from-literal=signup-captcha-secret-key=$SSECRET_KEY --dry-run=client -o yaml | kubectl apply -f - echo "Captcha secrets for esignet configured sucessfully" - ./copy_cm_func.sh secret signup-captcha $NS captcha + ../copy_cm_func.sh secret signup-captcha $NS captcha # Check if the first environment variable exists ENV_VAR_EXISTS=$(kubectl -n captcha get deployment captcha -o jsonpath="{.spec.template.spec.containers[0].env[?(@.name=='MOSIP_CAPTCHA_SECRET_SIGNUP')].name}") @@ -64,9 +64,10 @@ function installing_prereq() { echo "Environment variable 'MOSIP_CAPTCHA_SECRET_SIGNUP' exists. Updating it..." kubectl patch deployment -n captcha captcha --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/env[?(@.name==\"MOSIP_CAPTCHA_SECRET_SIGNUP\")]", "value": {"name": "MOSIP_CAPTCHA_SECRET_SIGNUP", "valueFrom": {"secretKeyRef": {"name": "signup-captcha", "key": "signup-captcha-secret-key"}}}}]' fi - + break elif [ "$ans" = "N" ] || [ "$ans" = "n" ]; then - exit 1 + echo "Exiting captcha configuration." + break # Exit the loop else echo "Please provide a correct option (Y or N)" fi