CI Procedure for Adding an External database(3.0)
To be able to use an external database in the CI pipeline there are a few steps that need to be handled:
- Add a helm chart for the database in the directory /Test/Helm. The example uses Postgres as the database.
- Add files to set up the basics for the database. Like Users, Schemas, Database, etc. These files should be placed in the directory /Test/Database.
The example uses a bash script to run the different SQL files, this is good practice to simplify the pipeline.sh script. - Then the files used to setup the database tables need to be added in directory /Database.Â
The example uses the upgrader.jar from platform to update the database, the upgrader is using LiquiBase to handle this. See Liquibase for more information.
If the upgrader will be used the base changeLog XML file needs to contain db.changelog. The same directory also needs to include a file named db.version_tag.xml including changeSet to tag the database with a version. Finally the pipeline.sh script needs to be updated with a function to setup the database.
The example code looks like this:function setup_audit_database { # Be sure that all directories exist if [[ -d Database/audit ]] && [[ -d Test/Database/audit/ ]] && [[ -d Test/Helm/postgresql/ ]] then echo "Installing Postgres for Audit..." helm upgrade --install audit-postgresql ./Test/Helm/postgresql/ --wait --set fullnameOverride=audit-postgresql --set global.postgresql.postgresqlPassword=test --set persistence.enabled=false --namespace $NAMESPACE > /dev/null tar -cf init.tar -C Test/Database/audit/ init tar -cf change.tar -C Database/ audit kubectl cp init.tar $NAMESPACE/$PLATFORM_POD:/tmp kubectl cp change.tar $NAMESPACE/$PLATFORM_POD:/tmp echo "Initilize Audit database" kubectl exec $PLATFORM_POD --namespace $NAMESPACE -- bash -c "set -e;cd /tmp; tar --warning=no-unknown-keyword -xf init.tar; rm init.tar; export PGPASSWORD=test;cd init;./postgre_create_instance.sh" echo "Setup tables in Audit database" upgrader=$(kubectl exec $PLATFORM_POD --namespace $NAMESPACE -- bash -c "ls -1d upgrade/upgrade*") kubectl exec $PLATFORM_POD --namespace $NAMESPACE -- bash -c "set -e;cd /tmp; tar --warning=no-unknown-keyword -xf change.tar; rm change.tar;java -jar /opt/mz/$upgrader db-upgrade -b . -c audit/ -h audit-postgresql -p 5432 -n audit -t postgresql pguser/test" rm -rf init.tar change.tar fi }