From 83ff39f4e2deb56c088886e042569650a3e47a4b Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Wed, 16 Dec 2015 20:13:43 -0800 Subject: [PATCH 1/4] Added index for query descriptions --- mongo_maint.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mongo_maint.sh b/mongo_maint.sh index 1f75ca6..85a3324 100755 --- a/mongo_maint.sh +++ b/mongo_maint.sh @@ -16,11 +16,13 @@ set -e -o nounset # Set db keys to prevent duplicates # mongo query_composer_development --eval \ - 'printjson( db.users.ensureIndex({ username : 1 }, { unique : true }))' + 'printjson( db.users.ensureIndex({ username : 1 }, { unique: true }))' mongo query_composer_development --eval \ - 'printjson( db.endpoints.ensureIndex({ base_url : 1 }, { unique : true }))' + 'printjson( db.endpoints.ensureIndex({ base_url : 1 }, { unique: true }))' mongo query_composer_development --eval \ - 'printjson( db.users.ensureIndex({ first_name: 1, last_name:1 }, { unique: true }))' + 'printjson( db.users.ensureIndex({ username: 1 }, { unique: true }))' +mongo query_composer_development --eval \ + 'printjson( db.queries.ensureIndex({ description: 1 }, { unique: true }))' # Dump MongoDB, report failure if unsuccessful From 6efa81468e6830bd5a534dc4e5551464b3b2ecc6 Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Wed, 16 Dec 2015 20:14:47 -0800 Subject: [PATCH 2/4] Moved cronjob into container, now using phusion/baseimage, based on official mongo 3.0 --- Dockerfile | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7bc670f..b2fb941 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile for the PDC's HubDB service # # -# HubDB for PDC-collected aggregate data. +# HubDB for PDC-collected aggregate data. Based on Mongo official 3.0. # # Example: # sudo docker pull pdcbc/hubdb @@ -14,21 +14,110 @@ # - Mongo live db: -v :/data/db/:rw # - Mongo dumps: -v :/data/dump/:rw # -FROM mongo:3.0 +# Releases +# - https://github.com/PDCbc/gateway/releases +# +# +FROM phusion/baseimage MAINTAINER derek.roberts@gmail.com ENV RELEASE 0.1.5 +################################################################################ +# Start - modified from https://hub.docker.com/_/mongo/ +################################################################################ + + +# Create users and groups +# +RUN groupadd -r mongodb; \ + useradd -r -g mongodb mongodb + + +# Packages +# +RUN apt-get update; \ + apt-get install -y --no-install-recommends \ + ca-certificates; \ + rm -rf /var/lib/apt/lists/* + + +# MongoDB +# +ENV MONGO_MAJOR 3.0 +ENV MONGO_VERSION 3.0.7 +# +RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 492EAFE8CD016A07919F1D2B9ECBEC467F0CEB10; \ + echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/$MONGO_MAJOR multiverse" > /etc/apt/sources.list.d/mongodb-org.list +RUN apt-get update; \ + apt-get install -y \ + mongodb-org=$MONGO_VERSION \ + mongodb-org-server=$MONGO_VERSION \ + mongodb-org-shell=$MONGO_VERSION \ + mongodb-org-mongos=$MONGO_VERSION \ + mongodb-org-tools=$MONGO_VERSION; \ + rm -rf /var/lib/apt/lists/* \ + /var/lib/mongodb \ + /etc/mongod.conf + + +# Volume +# +RUN mkdir -p /data/db; \ + chown -R mongodb:mongodb /data/db +VOLUME /data/db + + +# Port +# +EXPOSE 27017 + + +################################################################################ +# End - modified from https://hub.docker.com/_/mongo/ +################################################################################ + + # Packages # RUN apt-get update; \ apt-get install -y \ - git; \ - apt-get clean; \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + git; \ + apt-get clean; \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # Prepare /app/ folder # WORKDIR /app/ RUN git clone https://github.com/pdcbc/hubdb.git . -b ${RELEASE} + + +# Mongo startup +# +RUN mkdir -p /etc/service/mongod/; \ + SCRIPT=/etc/service/mongod/run; \ + ( \ + echo "#!/bin/bash"; \ + echo ""; \ + echo "set -e -o nounset"; \ + echo ""; \ + echo ""; \ + echo "# Start mongod"; \ + echo "#"; \ + echo "#exec mongod --storageEngine wiredTiger"; \ + echo "exec mongod"; \ + ) \ + >> ${SCRIPT}; \ + chmod +x ${SCRIPT} + + +# Maintenance script and cron job +# +RUN SCRIPT=/app/mongo_maint.sh; \ + ( \ + echo "# Run database dump/maintenance script (boot, daily 1:15 AM)"; \ + echo "@reboot "${SCRIPT}; \ + echo "15 1 * * * "${SCRIPT}; \ + ) \ + | crontab - From 825c09d273b1bc00d433a66557a591c1af6fc8a4 Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Wed, 16 Dec 2015 20:15:45 -0800 Subject: [PATCH 3/4] Removed filterProviders.js, hadn't been in use --- filterProviders.js | 47 ---------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 filterProviders.js diff --git a/filterProviders.js b/filterProviders.js deleted file mode 100644 index eceb427..0000000 --- a/filterProviders.js +++ /dev/null @@ -1,47 +0,0 @@ -/* -* Filters out providers based on id's and the initiative they are in. -* -* @param providerId {string} - the provider identifier to filter against. -* @param initiative {string} - the initiative identifier. One of: -* - "PPh" : polypharmacy -* -* @returns - true if the provider is part of the specified initiative -* false otherwise. -*/ -function filterProviders(providerId, initiative){ - - //check that we have valid inputs - if ( !providerId || !initiative ) { - - return false; - - } - - var inits = { - - "PPh" : [ - "cpsid", //currently contains some test values. - "PROVIDER1", - "PROVIDER2" - ] - }; - - - //check that the initiative is valid. - if ( inits[initiative] === undefined ){ - - return false; - - } - - if( inits[initiative].indexOf(providerId) > -1 ){ - - return true; - - }else{ - - return false; - - } - -} From 870b6fa74358cf870b8f578a729e85617c0cf989 Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Wed, 16 Dec 2015 20:18:57 -0800 Subject: [PATCH 4/4] Updated release number in Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b2fb941..4bf9023 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,7 @@ # FROM phusion/baseimage MAINTAINER derek.roberts@gmail.com -ENV RELEASE 0.1.5 +ENV RELEASE 0.1.6 ################################################################################