Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi-process image when not specifying POSTGRES_PORT_5432_TCP_ADDR #1922

Merged
merged 2 commits into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker/multi-process/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions docker/multi-process/scripts/init
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ fi
# is a mysql or postgresql database linked?
# requires that the mysql or postgresql containers have exposed
# port 3306 and 5432 respectively.
if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ]; then
if [[ -n "${MYSQL_PORT_3306_TCP_ADDR}" || ("${DATABASE_ADAPTER}" == "mysql2" && -n "${DATABASE_HOST}") ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought you couldn't use || and had to use -o, but I think that's with [, not [[. Bash scripting is insane.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is kind of weird, as far as I know [[ supports more expressions but is not POSIX compatible, but since we only use bash anyways we can use it everywhere.

DATABASE_ADAPTER=${DATABASE_ADAPTER:-mysql2}
DATABASE_HOST=${DATABASE_HOST:-${MYSQL_PORT_3306_TCP_ADDR}}
DATABASE_PORT=${DATABASE_PORT:-${MYSQL_PORT_3306_TCP_PORT}}
DATABASE_ENCODING=${DATABASE_ENCODING:-utf8mb4}
elif [ -n "${POSTGRES_PORT_5432_TCP_ADDR}" ]; then
elif [[ -n "${POSTGRES_PORT_5432_TCP_ADDR}" || "${DATABASE_ADAPTER}" == "postgresql" ]]; then
DATABASE_ADAPTER=${DATABASE_ADAPTER:-postgresql}
DATABASE_HOST=${DATABASE_HOST:-${POSTGRES_PORT_5432_TCP_ADDR}}
DATABASE_PORT=${DATABASE_PORT:-${POSTGRES_PORT_5432_TCP_PORT}}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docker/single-process/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion docker/single-process/scripts/init
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down