Moving to MongoDB

This commit is contained in:
Miguel Martinez
2016-06-15 13:53:06 -07:00
parent 35a5e39b39
commit 44eb15e3a5
2 changed files with 24 additions and 11 deletions

View File

@@ -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:

View File

@@ -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