RGeo postgis and rubber

210 views
Skip to first unread message

stub

unread,
May 8, 2012, 12:36:54 PM5/8/12
to RGeo-Users
Hello there,

Has anyone used RGeo with rubber? I was wondering where and how I can
hook in in the rubber configuration to get the whole thing to work,
since one has to install postgis and additional packages and RGeo
(activerecord-postgis-adapter) handles the creation of the database
with the template script.

Has anyone some experience with it or is it better to setup the
environment by my own?

Thx for any suggestions or links

Andrew Libby

unread,
May 8, 2012, 1:11:32 PM5/8/12
to rgeo-...@googlegroups.com, stub


I've used both, but not together. I imagine you'd be able
to get the prerequisite packages on to the servers in
question pretty easily - if nominally by adding them to the
global packages list for rubber.

From there would not the rgeo gems install and build when
bundled?

I forget exactly where in the setup process you'd want to
hook in the postgis.sql and spatial_ref_sys.sql - but I
imagine that during the bootstrap process this would be a
pretty easy thing to come by.

IMO worth your time to work through it so you can make it
wash/ rinse/ repeat.

Andy
--


xforty technologies
Andrew Libby
http://xforty.com
484-887-7505 x 1115

stub

unread,
May 21, 2012, 12:03:37 PM5/21/12
to RGeo-Users
Hello evryone

It finally works, using rubber, postgis and rgeo. Here is what I had
to do:

1. Add the postgresql-postgis package to the rubber-postgresql.yml
file:
roles:
postgresql_master:
db_server_id: 1
postgresql_slave:
db_server_id: 2
db:
packages: ["postgresql-#{postgresql_ver}", "postgresql-
#{postgresql_ver}-postgis"]

2. Extend the postgresql:bootstrap task in deploy-postgresql.rb to set
up the database with the postgis table and functions:
...
script_dir = "/usr/share/postgresql/
#{rubber_env.postgresql_ver}/contrib"

rubber.sudo_script "create_master_db", <<-ENDSCRIPT

sudo -u postgres psql -c "#{create_user_cmd}"
sudo -u postgres psql -c
"#{create_replication_user_cmd}"
sudo -u postgres psql -c "CREATE DATABASE #{env.db_name}
WITH OWNER #{env.db_user}"

#Initialize db with postgis data
sudo -u postgres psql -d #{env.db_name} -f #{script_dir}/
postgis-1.5/postgis.sql
sudo -u postgres psql -d #{env.db_name} -f #{script_dir}/
postgis-1.5/spatial_ref_sys.sql
sudo -u postgres psql -d #{env.db_name} -c "GRANT ALL
PRIVILEGES ON ALL TABLES IN SCHEMA public TO #{env.db_user}"
sudo -u postgres psql -d #{env.db_name} -c "GRANT ALL
PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO #{env.db_user}"
ENDSCRIPT
...

3. Create new rubber deploy task file named deploy-rgeo.rb and its
config file rubber-rgeo.yml to install the needed packages and the
rgeo gem:

deploy-rgeo.yml:
#RGeo requires the packages libgeos and proj for internal calculations
packages: [libgeos-3.2.2, proj]

deploy-rgeo.rb:

namespace :rubber do
namespace :rgeo do

after "rubber:install_gems", "rubber:rgeo:install_rgeo"
task :install_rgeo do
#Install the rgeo gem with the path to the required libraries
rubber.sudo_script "install_rgeo", <<-SCRIPT
gem install rgeo -- --with-geos-dir=/usr/lib/
SCRIPT
end

end
end


With this rgeo works using rubber to deploy the whole server. What
I've not tested yet is the use of slave instances, but i think that
should work also.

Thiago Christof

unread,
Jun 27, 2013, 2:34:57 PM6/27/13
to rgeo-...@googlegroups.com

Hello stub and everyone,

I'm at the same situation: need to deploy postgis and rgeo using rubber (to an EC2 instance). The only close reference I found out there is your post, and I'll try it.

If you found issues later or changed it please let me know, thank you very much!

Thiago Christof

Thiago Christof

unread,
Jul 8, 2013, 11:14:16 AM7/8/13
to rgeo-...@googlegroups.com

Hi everyone,

I got a successfully PostGIS 2.0 + RGeo deployment to EC2 instance using rubber. I'm not sure if it's the most elegant solution, but it definitely worked for me:

deploy-postgresql.rb
task :setup_apt_sources do
      rubber.sudo_script 'configure_postgresql_repository', <<-ENDSCRIPT
        # ##################
        # Custom
        # ##################
        # PostGIS 2.0
        sudo apt-get -y install python-software-properties
        sudo apt-add-repository -y ppa:sharpie/for-science
        sudo apt-add-repository -y ppa:sharpie/postgis-stable
        sudo apt-add-repository -y ppa:ubuntugis/ubuntugis-unstable
        sudo apt-get -y update
        sudo apt-get -y install postgresql-9.1-postgis2
        # #### End #########
        # PostgreSQL 9.1 is the default starting in Ubuntu 11.10.
        release=`lsb_release -sr`
        needs_repo=`echo "$release < 11.10" | bc`
        if [[ $needs_repo == 1 ]]; then
          add-apt-repository ppa:pitti/postgresql
        fi
      ENDSCRIPT
    end


  rubber.sudo_script "create_master_db", <<-ENDSCRIPT
    sudo -i -u postgres psql -c "#{create_user_cmd}"
    sudo -i -u postgres psql -c "#{create_replication_user_cmd}"
    sudo -i -u postgres psql -c "CREATE DATABASE #{env.db_name} WITH OWNER #{env.db_user}"
    # ##################
    # Custom 
    # ##################
    sudo -u postgres psql -d #{env.db_name} -c "CREATE SCHEMA postgis;"
    sudo -u postgres psql -d #{env.db_name} -c "CREATE EXTENSION postgis WITH SCHEMA postgis;"
    sudo -u postgres psql -d #{env.db_name} -c "ALTER DATABASE #{env.db_name} SET search_path=public,postgis;"
    sudo -u postgres psql -d #{env.db_name} -c "GRANT ALL ON SCHEMA postgis TO public;"
    sudo -u postgres psql -d #{env.db_name} -c "GRANT ALL ON geometry_columns TO PUBLIC;"
    sudo -u postgres psql -d #{env.db_name} -c "GRANT ALL ON geography_columns TO PUBLIC;"
    sudo -u postgres psql -d #{env.db_name} -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
    # #### End #########              
  ENDSCRIPT
end


Gemfile
...
gem 'activerecord-postgis-adapter'
gem 'rgeo'

rubber-postgresql.yml
No changes at all.

Hope this helps someone.
Thanks!

Thiago
Reply all
Reply to author
Forward
0 new messages