diff --git a/libraries/drivers_db_base.rb b/libraries/drivers_db_base.rb index 84bea8cd..1f65ad3f 100644 --- a/libraries/drivers_db_base.rb +++ b/libraries/drivers_db_base.rb @@ -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 @@ -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 diff --git a/spec/fixtures/aws_opsworks_rds_db_instance.rb b/spec/fixtures/aws_opsworks_rds_db_instance.rb index 45f1f904..0fe24b23 100644 --- a/spec/fixtures/aws_opsworks_rds_db_instance.rb +++ b/spec/fixtures/aws_opsworks_rds_db_instance.rb @@ -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' diff --git a/spec/unit/examples/db_parameters_and_connection.rb b/spec/unit/examples/db_parameters_and_connection.rb index ed2d0fe7..4909cd71 100644 --- a/spec/unit/examples/db_parameters_and_connection.rb +++ b/spec/unit/examples/db_parameters_and_connection.rb @@ -25,6 +25,7 @@ username: 'dbuser', password: '03c1bc98cdd5eb2f9c75', host: 'dummy-project.c298jfowejf.us-west-2.rds.amazon.com', + port: 3265, database: 'dummydb' ) end diff --git a/spec/unit/recipes/configure_spec.rb b/spec/unit/recipes/configure_spec.rb index 8ddee4ac..bc700137 100644 --- a/spec/unit/recipes/configure_spec.rb +++ b/spec/unit/recipes/configure_spec.rb @@ -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 @@ -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") @@ -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' @@ -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' @@ -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' @@ -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'