Skip to content

Commit

Permalink
BAH-3380 | Add script to update openmrs and elis host and port for at…
Browse files Browse the repository at this point in the history
…omfeed sync (#95)
  • Loading branch information
mohan-13 authored Dec 19, 2023
1 parent 1cf1c55 commit 6d7bae6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions package/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ ENV DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,address=8002,server=y,suspend

# Used by envsubst command for replacing environment values at runtime
RUN yum install -y gettext
RUN yum install -y nc
RUN yum install -y postgresql

ADD https://raw.githubusercontent.com/eficode/wait-for/v2.2.3/wait-for wait-for.sh

ADD https://repo.mybahmni.org/packages/build/bahmni-embedded-tomcat-8.0.42.jar /opt/bahmni-erp-connect/lib/bahmni-erp-connect.jar
COPY openerp-atomfeed-service/target/openerp-atomfeed-service.war /etc/bahmni-erp-connect/openerp-atomfeed-service.war
Expand All @@ -20,6 +24,9 @@ COPY package/resources/log4j2.properties ${WAR_DIRECTORY}/WEB-INF/classes/
COPY package/docker/templates/erp-atomfeed.properties.template /opt/bahmni-erp-connect/etc/erp-atomfeed.properties.template
COPY package/docker/scripts/run-liquibase.sh /opt/bahmni-erp-connect/etc/run-liquibase.sh
RUN chmod +x /opt/bahmni-erp-connect/etc/run-liquibase.sh
COPY package/docker/scripts/update_openmrs_host_port.sh update_openmrs_host_port.sh
RUN chmod +x update_openmrs_host_port.sh
RUN chmod +x wait-for.sh

COPY package/docker/scripts/start.sh start.sh
RUN chmod +x start.sh
Expand Down
3 changes: 3 additions & 0 deletions package/docker/scripts/start.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/sh
set -e

echo "Waiting for ${ODOO_DB_SERVER}:5432 for 3600 seconds"
sh wait-for.sh --timeout=3600 ${ODOO_DB_SERVER}:5432
echo "[INFO] Substituting Environment Variables"
envsubst < /opt/bahmni-erp-connect/etc/erp-atomfeed.properties.template > ${WAR_DIRECTORY}/WEB-INF/classes/erp-atomfeed.properties
./update_openmrs_host_port.sh
echo "[INFO] Running Liquibase migrations"
sh /opt/bahmni-erp-connect/etc/run-liquibase.sh
echo "[INFO] Starting Application"
Expand Down
17 changes: 17 additions & 0 deletions package/docker/scripts/update_openmrs_host_port.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set +e

run_sql() {
PGPASSWORD="${ODOO_DB_PASSWORD}" psql --host="${ODOO_DB_SERVER}" -U "${ODOO_DB_USERNAME}" -d odoo -t -c "$1"
}

if [ $(run_sql "select count(*) from information_schema.tables where table_name='markers' and table_schema='public';") -gt 0 ]
then
echo "Updating OpenMRS Host Port in markers and failed_events table"
run_sql "UPDATE markers SET feed_uri_for_last_read_entry = regexp_replace(feed_uri_for_last_read_entry, 'http://.*/openmrs', 'http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs'),feed_uri = regexp_replace(feed_uri, 'http://.*/openmrs', 'http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs') where feed_uri ~ 'openmrs';"
run_sql "UPDATE failed_events SET feed_uri = regexp_replace(feed_uri, 'http://.*/openmrs', 'http://${OPENMRS_HOST}:${OPENMRS_PORT}/openmrs') where feed_uri ~'openmrs';"

echo "Updating OpenELIS Host Port in markers and failed_events table"
run_sql "UPDATE markers SET feed_uri_for_last_read_entry = regexp_replace(feed_uri_for_last_read_entry, 'http://.*/openelis', 'http://${OPENELIS_HOST}:${OPENELIS_PORT}/openelis'),feed_uri = regexp_replace(feed_uri, 'http://.*/openelis', 'http://${OPENELIS_HOST}:${OPENELIS_PORT}/openelis') where feed_uri ~ 'openelis';"
run_sql "UPDATE failed_events SET feed_uri = regexp_replace(feed_uri, 'http://.*/openelis', 'http://${OPENELIS_HOST}:${OPENELIS_PORT}/openelis') where feed_uri ~'openelis';"
fi

0 comments on commit 6d7bae6

Please sign in to comment.