Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
fix(db): Respect database port provided by RDS (#124)
Browse files Browse the repository at this point in the history
Fixes #123
  • Loading branch information
nickmarden authored and ajgon committed Oct 8, 2017
1 parent de153bf commit 7aeb78e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
8 changes: 5 additions & 3 deletions libraries/drivers_db_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def out

out_defaults.merge(
adapter: adapter, username: options[:rds]['db_user'], password: options[:rds]['db_password'],
host: options[:rds]['address'], database: app['data_sources'].first.try(:[], 'database_name')
)
host: options[:rds]['address'], port: options[:rds]['port'],
database: app['data_sources'].first.try(:[], 'database_name')
).reject { |_k, v| v.blank? }
end
# rubocop:enable Metrics/AbcSize

Expand All @@ -47,7 +48,8 @@ def can_migrate?
end

def url(_deploy_dir)
"#{out[:adapter]}://#{out[:username]}:#{out[:password]}@#{out[:host]}/#{out[:database]}"
show_port = ":#{out[:port]}" unless out[:port].blank?
"#{out[:adapter]}://#{out[:username]}:#{out[:password]}@#{out[:host]}#{show_port}/#{out[:database]}"
end

protected
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/aws_opsworks_rds_db_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def aws_opsworks_rds_db_instance(override = {})
db_password: '03c1bc98cdd5eb2f9c75',
region: 'us-west-2',
address: 'dummy-project.c298jfowejf.us-west-2.rds.amazon.com',
port: 3265,
engine: 'postgres',
missing_on_rds: false,
id: 'arn_aws_rds_us-west-2_850906259207_db_dummy-project'
Expand Down
1 change: 1 addition & 0 deletions spec/unit/examples/db_parameters_and_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
username: 'dbuser',
password: '03c1bc98cdd5eb2f9c75',
host: 'dummy-project.c298jfowejf.us-west-2.rds.amazon.com',
port: 3265,
database: 'dummydb'
)
end
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/recipes/configure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@
.to render_file("/srv/www/#{aws_opsworks_app['shortname']}/shared/config/.env.staging")
.with_content(
"DATABASE_URL=\"mysql2://dbuser:#{db_config[:password]}@" \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com/dummydb"'
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com:3265/dummydb"'
)
end

Expand Down Expand Up @@ -552,7 +552,7 @@
.to render_file("/srv/www/#{aws_opsworks_app['shortname']}/shared/scripts/puma.service")
.with_content(
'ENV[\'DATABASE_URL\'] = "mysql2://dbuser:03c1bc98cdd5eb2f9c75@' \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com/dummydb"'
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com:3265/dummydb"'
)
expect(chef_run)
.to render_file("/srv/www/#{aws_opsworks_app['shortname']}/shared/scripts/puma.service")
Expand Down Expand Up @@ -694,7 +694,7 @@
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" HANAMI_ENV="staging" DATABASE_URL="mysql2://dbuser:03c1bc98cdd5eb2f9c75@' \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com/dummydb" HOME="/home/deploy" USER="deploy" ' \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com:3265/dummydb" HOME="/home/deploy" USER="deploy" ' \
'QUEUE=test_queue VERBOSE=1 PIDFILE=/run/lock/dummy_project/resque_dummy_project-1.pid COUNT=2 ' \
'bundle exec rake environment resque:work 2>&1 | logger -t resque-dummy_project-1\'" ' \
'with timeout 90 seconds'
Expand All @@ -717,7 +717,7 @@
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" HANAMI_ENV="staging" DATABASE_URL="mysql2://dbuser:03c1bc98cdd5eb2f9c75@' \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com/dummydb" HOME="/home/deploy" USER="deploy" ' \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com:3265/dummydb" HOME="/home/deploy" USER="deploy" ' \
'QUEUE=test_queue VERBOSE=1 PIDFILE=/run/lock/dummy_project/resque_dummy_project-2.pid COUNT=2 ' \
'bundle exec rake environment resque:work 2>&1 | logger -t resque-dummy_project-2\'" ' \
'with timeout 90 seconds'
Expand Down Expand Up @@ -761,7 +761,7 @@
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" HANAMI_ENV="staging" DATABASE_URL="mysql2://dbuser:03c1bc98cdd5eb2f9c75@' \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com/dummydb" HOME="/home/deploy" USER="deploy" ' \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com:3265/dummydb" HOME="/home/deploy" USER="deploy" ' \
'QUEUE=test_queue VERBOSE=1 PIDFILE=/run/lock/dummy_project/resque_dummy_project-1.pid ' \
'COUNT=2 bundle exec rake environment resque:work 2>&1 | logger -t resque-dummy_project-1\'" ' \
'with timeout 90 seconds'
Expand All @@ -784,7 +784,7 @@
.with_content(
'start program = "/bin/su - deploy -c \'cd /srv/www/dummy_project/current && ENV_VAR1="test" ' \
'ENV_VAR2="some data" HANAMI_ENV="staging" DATABASE_URL="mysql2://dbuser:03c1bc98cdd5eb2f9c75@' \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com/dummydb" HOME="/home/deploy" USER="deploy" ' \
'dummy-project.c298jfowejf.us-west-2.rds.amazon.com:3265/dummydb" HOME="/home/deploy" USER="deploy" ' \
'QUEUE=test_queue VERBOSE=1 PIDFILE=/run/lock/dummy_project/resque_dummy_project-2.pid ' \
'COUNT=2 bundle exec rake environment resque:work 2>&1 | logger -t resque-dummy_project-2\'" ' \
'with timeout 90 seconds'
Expand Down

0 comments on commit 7aeb78e

Please sign in to comment.