From 80f42dc4b98f3938bd3a07192207dc7201d0b018 Mon Sep 17 00:00:00 2001 From: Igor Rzegocki Date: Fri, 22 Jun 2018 14:23:30 +0200 Subject: [PATCH] feat(db): added postgis driver Resolves #165 --- docs/source/attributes.rst | 2 +- libraries/drivers_db_postgis.rb | 11 +++++++++++ spec/unit/recipes/configure_spec.rb | 22 +++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 libraries/drivers_db_postgis.rb diff --git a/docs/source/attributes.rst b/docs/source/attributes.rst index b2a6a84a..6867e4a9 100644 --- a/docs/source/attributes.rst +++ b/docs/source/attributes.rst @@ -168,7 +168,7 @@ database - ``app['database']['adapter']`` - - **Supported values:** ``mariadb``, ``mysql``, ``postgresql``, ``sqlite3``, ``null`` + - **Supported values:** ``mariadb``, ``mysql``, ``postgis``, ``postgresql``, ``sqlite3``, ``null`` - **Default:** ``sqlite3`` - ActiveRecord adapter which will be used for database connection. ``null`` means that no database will be configured, and is currently only tested with the ``rails`` diff --git a/libraries/drivers_db_postgis.rb b/libraries/drivers_db_postgis.rb new file mode 100644 index 00000000..aeb92c88 --- /dev/null +++ b/libraries/drivers_db_postgis.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Drivers + module Db + class Postgis < Base + adapter :postgis + allowed_engines :postgis + packages debian: %w[libpq-dev libgeos-dev], rhel: %w[postgresql96-devel libgeos-devel] + end + end +end diff --git a/spec/unit/recipes/configure_spec.rb b/spec/unit/recipes/configure_spec.rb index 13e8e5bb..5d461fac 100644 --- a/spec/unit/recipes/configure_spec.rb +++ b/spec/unit/recipes/configure_spec.rb @@ -827,10 +827,17 @@ end end - context 'Postgres + Passenger + Apache2' do + context 'Postgres (postgis) + Passenger + Apache2' do let(:chef_runner) do ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node| deploy = node['deploy'] + deploy['dummy_project']['database'] = { + 'adapter' => 'postgis', + 'username' => 'dbuser', + 'password' => '03c1bc98cdd5eb2f9c75', + 'host' => 'dummy-project.c298jfowejf.us-west-2.rds.amazon.com', + 'port' => 3265 + } deploy['dummy_project']['appserver']['adapter'] = 'passenger' deploy['dummy_project']['appserver']['max_pool_size'] = 10 deploy['dummy_project']['appserver']['min_instances'] = 5 @@ -842,6 +849,19 @@ end let(:chef_run) { chef_runner.converge(described_recipe) } + before do + stub_search(:aws_opsworks_rds_db_instance, '*:*').and_return([]) + end + + it 'creates proper database.yml template' do + db_config = Drivers::Db::Postgis.new(chef_run, aws_opsworks_app).out + expect(db_config[:adapter]).to eq 'postgis' + expect(chef_run) + .to render_file("/srv/www/#{aws_opsworks_app['shortname']}/shared/config/database.yml").with_content( + JSON.parse({ development: db_config, production: db_config }.to_json).to_yaml + ) + end + it 'creates apache2 passenger config' do expect(chef_run) .to render_file("/etc/apache2/sites-available/#{aws_opsworks_app['shortname']}.conf")