Pārlūkot izejas kodu

Do not create the database in docker container when DO_NOT_CREATE_DATABASE is set

Dominik Sander 8 gadi atpakaļ
vecāks
revīzija
b61c6c63ea

+ 2 - 0
docker/multi-process/README.md

@@ -33,6 +33,8 @@ Additionally, the database variables may be overridden from the above as per the
     DATABASE_HOST
     DATABASE_PORT
 
+When connecting to an external database and your user does not have the permission to create the Huginn database please make sure it exists and set the `DO_NOT_CREATE_DATABASE` environment variable.
+
 This script will run database migrations (rake db:migrate) which should be idempotent.
 
 It will also seed the database (rake db:seed) unless this is defined:

+ 3 - 1
docker/multi-process/scripts/init

@@ -198,7 +198,9 @@ if [ -n "\${DATABASE_INITIAL_CONNECT_MAX_RETRIES}" ]; then
 fi
 
 # We may need to try and create a database
-sudo -u huginn -EH bundle exec rake db:create
+if [ -z "\${DO_NOT_CREATE_DATABASE}" ]; then
+  sudo -u huginn -EH bundle exec rake db:create
+fi
 
 # Assuming we have a created database, run the migrations and seed it idempotently.
 if [ -z "\${DO_NOT_MIGRATE}" ]; then

+ 2 - 0
docker/single-process/README.md

@@ -26,6 +26,8 @@ Additionally, the database variables may be overridden from the above as per the
     DATABASE_HOST
     DATABASE_PORT
 
+If your database user does not have the permission to create the Huginn database please make sure it exists and set the `DO_NOT_CREATE_DATABASE` environment variable.
+
 This script will run database migrations (rake db:migrate) which should be idempotent.
 
 It will also seed the database (rake db:seed) unless this is defined:

+ 5 - 1
docker/single-process/scripts/init

@@ -44,8 +44,12 @@ esac
 
 sudo -u huginn -H -E bundle install --without test development --path vendor/bundle
 
+if [[ -z "${DO_NOT_CREATE_DATABASE}" && -z $1 ]]; then
+  sudo -u huginn -H -E bundle exec rake db:create RAILS_ENV=${RAILS_ENV}
+fi
+
 if [ -z $1 ]; then
-  sudo -u huginn -H -E bundle exec rake db:create db:migrate RAILS_ENV=${RAILS_ENV}
+  sudo -u huginn -H -E bundle exec rake db:migrate RAILS_ENV=${RAILS_ENV}
 fi
 
 if [[ -z "${DO_NOT_SEED}" && -z $1 ]]; then