From 44eb15e3a51e87d7132cb53933049c1ecb55aff2 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Wed, 15 Jun 2016 13:53:06 -0700 Subject: [PATCH] Moving to MongoDB --- bitnami/express/docker-compose.yml | 6 ++--- bitnami/express/rootfs/app-entrypoint.sh | 29 +++++++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/bitnami/express/docker-compose.yml b/bitnami/express/docker-compose.yml index 5cd12cf47e22..39918b5280f8 100644 --- a/bitnami/express/docker-compose.yml +++ b/bitnami/express/docker-compose.yml @@ -1,8 +1,8 @@ version: '2' services: - mariadb: - image: bitnami/mariadb:10.1.14-r0 + mongodb: + image: bitnami/mongodb:3.2.6-r0 myapp: tty: true # Enables debugging capabilities when attached to this container. @@ -11,7 +11,7 @@ services: # environment: # - DATABASE_URL=mysql2://mariadb/my_app_development depends_on: - - mariadb + - mongodb ports: - 3000:3000 volumes: diff --git a/bitnami/express/rootfs/app-entrypoint.sh b/bitnami/express/rootfs/app-entrypoint.sh index cb87a1d270bc..189495bd3be0 100755 --- a/bitnami/express/rootfs/app-entrypoint.sh +++ b/bitnami/express/rootfs/app-entrypoint.sh @@ -18,23 +18,30 @@ dependencies_up_to_date() { [ ! $PACKAGE_FILE -nt $INIT_SEM ] } +database_tier_exists() { + [ ! -z $(getent hosts mongodb) ] +} + wait_for_db() { - mariadb_address=$(getent hosts mariadb | awk '{ print $1 }') + mongodb_address=$(getent hosts mongodb | awk '{ print $1 }') counter=0 - log "Connecting to mariadb at $mariadb_address" - while ! curl --silent mariadb:3306 >/dev/null; do + + log "Connecting to MongoDB at $mongodb_address" + + until nc -z $mongodb_address 27017; do counter=$((counter+1)) - if [ $counter == 30 ]; then - log "Error: Couldn't connect to mariadb." + if [ $counter == 10 ]; then + log "Error: Couldn't connect to MongoDB." exit 1 fi - log "Trying to connect to mariadb at $mariadb_address. Attempt $counter." + log "Trying to connect to MongoDB at $mongodb_address. Attempt $counter." sleep 5 done + log "Connected to MongoDB database" } setup_db() { - wait_for_db + npm install mongodb@2.1.18 --save # log "Configuring the database" # TODO # bundle exec rake db:create @@ -56,6 +63,10 @@ if ! dependencies_up_to_date; then log "Dependencies updated" fi +if database_tier_exists; then + wait_for_db +fi + if ! fresh_container; then echo "#########################################################################" echo " " @@ -66,7 +77,9 @@ if ! fresh_container; then echo " " echo "#########################################################################" else - setup_db + if database_tier_exists; then + setup_db + fi log "Initialization finished" fi