Skip to content

Commit

Permalink
Merge pull request #449 from bhumi46/release-1.1.x
Browse files Browse the repository at this point in the history
[MOSIP-36849] added postgres init script
  • Loading branch information
ckm007 authored Dec 3, 2024
2 parents 0d51efe + 81d7c8c commit 422c1e2
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 5 deletions.
27 changes: 27 additions & 0 deletions deploy/init_values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
dbUserPasswords:
dbuserPassword: ""
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
4 changes: 2 additions & 2 deletions deploy/keycloak/keycloak-init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# Initialises signup keycloak-init
## Usage: ./keycloak-init.sh [kubeconfig]

Expand Down Expand Up @@ -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" \
Expand Down
72 changes: 72 additions & 0 deletions deploy/postgres-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
# 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=signup
CHART_VERSION=1.1.0-develop
helm repo update

# Confirm if the user wants to initialize DB scripts
while true; do
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 -e
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

# Call the function
initialize_db
7 changes: 4 additions & 3 deletions deploy/prereq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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
Expand Down

0 comments on commit 422c1e2

Please sign in to comment.