├── .gitignore ├── Gemfile ├── solo.rb ├── solo.json ├── deploy.sh ├── install.sh ├── Vagrantfile ├── .gitmodules ├── README.md └── cookbooks └── core └── recipes └── default.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | gem 'chef' 4 | gem 'vagrant' 5 | gem 'json' 6 | -------------------------------------------------------------------------------- /solo.rb: -------------------------------------------------------------------------------- 1 | root = File.absolute_path(File.dirname(__FILE__)) 2 | 3 | file_cache_path root 4 | cookbook_path root + '/cookbooks' 5 | -------------------------------------------------------------------------------- /solo.json: -------------------------------------------------------------------------------- 1 | { 2 | "run_list": [ 3 | "recipe[git]", 4 | "recipe[zsh]", 5 | "recipe[apt]", 6 | "recipe[core]", 7 | "recipe[ohai]", 8 | "recipe[nginx]", 9 | "recipe[mongodb]" 10 | ], 11 | "user": "ubuntu" 12 | } 13 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Usage: ./deploy.sh [host] 4 | 5 | if test -n "$1"; then 6 | HOST="$1" 7 | else 8 | echo "You must supply a deployment host." 9 | exit 1 10 | fi 11 | 12 | tar cj . | ssh -o 'StrictHostKeyChecking no' "$HOST" ' 13 | sudo rm -rf ~/chef && 14 | mkdir ~/chef && 15 | cd ~/chef && 16 | tar xj && 17 | sudo bash install.sh' 18 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This runs as root on the server 4 | 5 | chef_binary=/usr/local/bin/chef-solo 6 | 7 | # Are we on a vanilla system? 8 | if ! test -x "$chef_binary"; then 9 | export DEBIAN_FRONTEND=noninteractive 10 | # Upgrade headlessly (this is only safe-ish on vanilla systems) 11 | aptitude update && 12 | apt-get -o Dpkg::Options::="--force-confnew" \ 13 | --force-yes -fuy dist-upgrade && 14 | # Install Ruby and Chef 15 | aptitude install -y ruby1.9.1 ruby1.9.1-dev make && 16 | sudo gem1.9.1 install --no-rdoc --no-ri chef 17 | fi && 18 | 19 | "$chef_binary" -c solo.rb -j solo.json 20 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | Vagrant::Config.run do |config| 4 | config.vm.box = "precise" 5 | 6 | config.vm.customize ["modifyvm", :id, "--memory", 1024] 7 | 8 | config.vm.forward_port 22, 2222 9 | config.vm.forward_port 80, 80 10 | config.vm.forward_port 3000, 3030 11 | config.vm.forward_port 3001, 3001 12 | config.vm.forward_port 4000, 4000 13 | config.vm.forward_port 5432, 5432 14 | config.vm.forward_port 8080, 8080 15 | 16 | config.vm.network :hostonly, "22.22.22.22" 17 | 18 | json = JSON.parse(File.open('solo.json').read) 19 | 20 | config.vm.provision :chef_solo do |chef| 21 | json['run_list'].each do |recipe| 22 | chef.add_recipe recipe 23 | end 24 | chef.json = { :user => 'vagrant' } 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cookbooks/build-essential"] 2 | path = cookbooks/build-essential 3 | url = https://github.com/opscode-cookbooks/build-essential.git 4 | [submodule "cookbooks/git"] 5 | path = cookbooks/git 6 | url = https://github.com/opscode-cookbooks/git.git 7 | [submodule "cookbooks/nginx"] 8 | path = cookbooks/nginx 9 | url = https://github.com/opscode-cookbooks/nginx.git 10 | [submodule "cookbooks/zsh"] 11 | path = cookbooks/zsh 12 | url = https://github.com/opscode-cookbooks/zsh.git 13 | [submodule "cookbooks/apt"] 14 | path = cookbooks/apt 15 | url = https://github.com/opscode-cookbooks/apt.git 16 | [submodule "cookbooks/mongodb"] 17 | path = cookbooks/mongodb 18 | url = https://github.com/edelight/chef-mongodb 19 | [submodule "cookbooks/ohai"] 20 | path = cookbooks/ohai 21 | url = https://github.com/opscode-cookbooks/ohai.git 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GeoBox - A hackbox for geo stuff 2 | 3 | This is a vagrant box that includes some GIS related tools for hacking. You can use it to get 4 | started with some standard tools without worrying about messing up your local machine. 5 | 6 | # Included in VM 7 | 8 | * Ubuntu 12.04 Precise Pangolin 9 | * GEOS 3.3.3 10 | * Proj 4.7 11 | * SpatiaLite 3.1 12 | * GDAL 1.9.1 13 | * Mapnik 2.0.1 14 | * PostgreSQL 9.1 15 | * PostGIS 2.0.1 16 | * Redis 2.2.x 17 | * MongoDB 2.x 18 | * NodeJS stable (currently 0.8.x) 19 | * Ruby 1.9.3 + Bundler 20 | * CartoDB (master) 21 | * osm2pgsql 22 | * osmosis 23 | * Imposm 2.4 24 | * nginx 25 | * zsh 26 | 27 | # Requirements for host machine 28 | 29 | * Ruby 30 | * VirtualBox [Download](https://www.virtualbox.org/wiki/Downloads) 31 | * Vagrant `gem install vagrant` 32 | 33 | # Installation 34 | 35 | git clone https://github.com/zhm/geobox 36 | cd geobox 37 | git submodule init 38 | git submodule update 39 | vagrant box add precise http://files.vagrantup.com/precise64.box 40 | 41 | # Usage & Setup 42 | 43 | to build the VM from the base image and ssh into it: 44 | 45 | vagrant up 46 | vagrant ssh 47 | 48 | exiting ssh from the VM: 49 | 50 | exit 51 | 52 | or to stop it from the host: 53 | 54 | vagrant suspend 55 | 56 | to destroy the VM from the host (to either delete it completely or rebuild it): 57 | 58 | vagrant destroy 59 | 60 | then to rebuild everything: 61 | 62 | vagrant up 63 | 64 | Note: Starting the machine for the first time will take about 20-30 minutes since it builds ruby, node, and PostGIS from source. 65 | 66 | # Accessing CartoDB 67 | 68 | To access the CartoDB server, you need to add something to your host file. 69 | 70 | echo "22.22.22.22 cartodb.localhost.lan" | tee -a /etc/hosts 71 | 72 | Once you have cartodb.localhost.lan resolving, you go to `http://cartodb.localhost.lan:3000` in your browser to get to CartoDB. 73 | 74 | CartoDB is started using WEBrick in the background, but you can kill it manually and start it via ssh manually if you want: 75 | 76 | cd /usr/local/src/cartodb 77 | sudo kill `pids/cartodb.pid` 78 | bundle exec rails server 79 | 80 | # Connecting to PostgreSQL 81 | 82 | To access the postgres instance from outside the VM (e.g. psql or pgAdmin), use 22.22.22.22 and username `vagrant` and password `vagrant`. 83 | This can be convenient for loading data that's on your local machine or being able to use pgAdmin to get to the database. 84 | 85 | # Hacking 86 | 87 | If you want to add your own stuff, you will want to take a look at [default.rb](https://github.com/zhm/geobox/blob/master/cookbooks/core/recipes/default.rb). It has most of the hackish code that installs and sets up the box. Improvements are welcome since I have no idea what I'm doing. 88 | 89 | # TODO 90 | * Proper init.d scripts and helpers to start/stop CartoDB stuff, or at least some shell aliases? 91 | * nginx setup for CartoDB stuff (preferably an optional setting that "just works" for both WEBrick and nginx) 92 | * TileMill 93 | * Options to use the latest and greatest of all stuff (Mapnik HEAD, PostGIS HEAD, etc) 94 | * Separate some of the stuff from the `core` recipe into different recipes 95 | * Fix all the custom `execute` commands to be more resilient to the `vagrant reload` command so they don't rebuild every time (mostly done, albeit hacky) 96 | * Oh yeah, security, don't use this for production. 97 | * EC2 compatible deployment using chef-solo, see previos item. 98 | -------------------------------------------------------------------------------- /cookbooks/core/recipes/default.rb: -------------------------------------------------------------------------------- 1 | %w[wget curl ack python-software-properties autoconf bison flex libyaml-dev libtool make vim].each do |pkg| 2 | package pkg do 3 | action :install 4 | end 5 | end 6 | 7 | install_prefix = "/usr/local" 8 | 9 | ["add-apt-repository ppa:ubuntugis/ubuntugis-unstable -y", "apt-get update"].each do |cmd| 10 | execute cmd do 11 | user "root" 12 | end 13 | end 14 | 15 | ["sudo add-apt-repository ppa:mapnik/nightly-2.0 -y", "apt-get update"].each do |cmd| 16 | execute cmd do 17 | user "root" 18 | end 19 | end 20 | 21 | # Geo packages 22 | %w[ 23 | libsqlite3-dev 24 | libproj-dev 25 | libgeos-dev 26 | libspatialite-dev 27 | libgeotiff-dev 28 | libgdal-dev 29 | gdal-bin 30 | libmapnik-dev 31 | mapnik-utils 32 | python-dev 33 | python-setuptools 34 | python-pip 35 | python-gdal 36 | python-mapnik 37 | postgresql-9.1 38 | postgresql-server-dev-9.1 39 | postgresql-plpython-9.1 40 | libjson0-dev 41 | redis-server 42 | libxslt-dev 43 | unzip 44 | unp 45 | osm2pgsql 46 | osmosis 47 | protobuf-compiler 48 | libprotobuf-dev 49 | libtokyocabinet-dev 50 | python-psycopg2 51 | imagemagick 52 | libmagickcore-dev 53 | libmagickwand-dev 54 | ].each do |pkg| 55 | package pkg do 56 | action :install 57 | end 58 | end 59 | 60 | install_prefix = "/usr/local" 61 | 62 | 63 | execute "apt-get update" do 64 | user "root" 65 | end 66 | 67 | execute "install PostGIS 2.x" do 68 | command <<-EOS 69 | if [ ! -d /usr/local/src/postgis-2.0.1 ] 70 | then 71 | cd /usr/local/src && 72 | wget http://postgis.org/download/postgis-2.0.1.tar.gz && 73 | tar xfvz postgis-2.0.1.tar.gz && 74 | cd postgis-2.0.1 && 75 | ./configure && 76 | make && 77 | make install && 78 | ldconfig && 79 | make comments-install && 80 | ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql && 81 | ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp && 82 | ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql && 83 | curl -s https://raw.github.com/gist/c83798ee55a08b7a5de5/813a2ba7543697789d2b5af6fae2cabf547cef54/pg_hba.conf -o /etc/postgresql/9.1/main/pg_hba.conf && 84 | curl -s https://raw.github.com/gist/bdf5accb7b328f7f596a/0f3a969132150655c861e2ea22852fdd16eac02c/postgresql.conf -o /etc/postgresql/9.1/main/postgresql.conf && 85 | /etc/init.d/postgresql restart && 86 | echo "CREATE ROLE vagrant LOGIN;" | psql -U postgres && 87 | echo "CREATE DATABASE vagrant;" | psql -U postgres && 88 | echo "ALTER USER vagrant SUPERUSER;" | psql -U postgres && 89 | echo "ALTER USER vagrant WITH PASSWORD 'vagrant';" | psql -U postgres && 90 | echo "CREATE DATABASE template_postgis;" | psql -U postgres && 91 | echo "CREATE EXTENSION postgis;" | psql -U postgres -d template_postgis && 92 | echo "CREATE EXTENSION postgis_topology;" | psql -U postgres -d template_postgis && 93 | echo "GRANT ALL ON geometry_columns TO PUBLIC;" | psql -U postgres -d template_postgis && 94 | echo "GRANT ALL ON spatial_ref_sys TO PUBLIC;" | psql -U postgres -d template_postgis 95 | fi 96 | EOS 97 | action :run 98 | user 'root' 99 | end 100 | 101 | ENV['PATH'] = "/home/#{node[:user]}/local:#{ENV['PATH']}" 102 | 103 | execute "set shell to zsh" do 104 | command "usermod -s /bin/zsh #{node[:user]}" 105 | action :run 106 | user "root" 107 | end 108 | 109 | directory "/home/#{node[:user]}/local" do 110 | owner node[:user] 111 | group node[:user] 112 | mode "0755" 113 | action :create 114 | end 115 | 116 | directory "/home/#{node[:user]}/local/src" do 117 | owner node[:user] 118 | group node[:user] 119 | mode "0755" 120 | action :create 121 | end 122 | 123 | directory "#{install_prefix}/src" do 124 | owner "root" 125 | group "root" 126 | mode "0755" 127 | action :create 128 | end 129 | 130 | git "ry" do 131 | repository "git://github.com/zhm/ry.git" 132 | reference 'master' 133 | destination "#{install_prefix}/src/ry" 134 | action :checkout 135 | user "root" 136 | end 137 | 138 | ENV['RY_PREFIX'] = install_prefix 139 | 140 | execute "install ry" do 141 | cwd "#{install_prefix}/src/ry" 142 | command <<-EOS 143 | [ -x #{install_prefix}/bin/ry ] || PREFIX=#{install_prefix} make install 144 | EOS 145 | action :run 146 | user "root" 147 | end 148 | 149 | execute "install ruby 1.9.3" do 150 | command <<-EOS 151 | [ -x #{install_prefix}/lib/ry/current/bin/ruby ] || 152 | #{install_prefix}/bin/ry install https://github.com/ruby/ruby/tarball/v1_9_3_195 1.9.3 --enable-shared=yes 153 | EOS 154 | action :run 155 | user "root" 156 | end 157 | 158 | execute "setup ruby" do 159 | command <<-EOS 160 | export RY_PREFIX=#{install_prefix} && 161 | export PATH=$RY_PREFIX/lib/ry/current/bin:$PATH && 162 | #{install_prefix}/lib/ry/current/bin/gem update --system && 163 | #{install_prefix}/lib/ry/current/bin/gem install bundler 164 | EOS 165 | action :run 166 | user "root" 167 | end 168 | 169 | git "oh-my-zsh" do 170 | repository "git://github.com/robbyrussell/oh-my-zsh.git" 171 | reference 'master' 172 | destination "/home/#{node[:user]}/.oh-my-zsh" 173 | action :checkout 174 | user node[:user] 175 | end 176 | 177 | execute "install .zshrc" do 178 | command "curl -L -o /home/#{node[:user]}/.zshrc https://raw.github.com/gist/789ba55f7ab0bf895a1c/5dc934f2737f75b306637c35258b984fc0127005/.zshrc" 179 | action :run 180 | user node[:user] 181 | end 182 | 183 | execute "install zsh theme" do 184 | command "curl -L -o /home/#{node[:user]}/.oh-my-zsh/themes/hackbox.zsh-theme https://raw.github.com/gist/1e701eb696d8804fa19c/c729347309a79f6820f4ad6feb7b517242755510/hackbox.zsh-theme" 185 | action :run 186 | user node[:user] 187 | end 188 | 189 | git "n" do 190 | repository "git://github.com/zhm/n.git" 191 | reference 'master' 192 | destination "#{install_prefix}/src/n" 193 | action :checkout 194 | user "root" 195 | end 196 | 197 | execute "install n" do 198 | cwd "#{install_prefix}/src/n" 199 | command <<-EOS 200 | make install && n 0.8.9 201 | EOS 202 | action :run 203 | user 'root' 204 | end 205 | 206 | execute "install standard node modules" do 207 | modules = %w(coffee-script underscore node-gyp) 208 | command modules.map {|m| "npm install -g #{m}" }.join(' && ') 209 | action :run 210 | user 'root' 211 | end 212 | 213 | # CARTODB 214 | 215 | execute "install pip" do 216 | command "easy_install pip" 217 | action :run 218 | user 'root' 219 | end 220 | 221 | execute "install python dependencies for CartoDB" do 222 | command <<-EOS 223 | pip install 'chardet==1.0.1' && 224 | pip install 'argparse==1.2.1' && 225 | pip install 'brewery==0.6' && 226 | pip install 'redis==2.4.9' && 227 | pip install 'hiredis==0.1.0' && 228 | pip install -e 'git+https://github.com/RealGeeks/python-varnish.git@0971d6024fbb2614350853a5e0f8736ba3fb1f0d#egg=python-varnish==0.1.2' 229 | EOS 230 | action :run 231 | user 'root' 232 | end 233 | 234 | 235 | git "CartoDB-SQL-API" do 236 | repository "git://github.com/Vizzuality/CartoDB-SQL-API.git" 237 | reference 'master' 238 | destination "#{install_prefix}/src/CartoDB-SQL-API" 239 | action :checkout 240 | user "root" 241 | end 242 | 243 | execute "setup CartoDB-SQL-API" do 244 | command "cd #{install_prefix}/src/CartoDB-SQL-API && npm install" 245 | end 246 | 247 | git "Windshaft-cartodb" do 248 | repository "git://github.com/Vizzuality/Windshaft-cartodb.git" 249 | reference 'master' 250 | destination "#{install_prefix}/src/Windshaft-cartodb" 251 | action :checkout 252 | user "root" 253 | end 254 | 255 | execute "setup Windshaft-cartodb" do 256 | cwd "#{install_prefix}/src/Windshaft-cartodb" 257 | command <<-EOS 258 | sudo npm install 259 | EOS 260 | user 'root' 261 | end 262 | 263 | execute "start Windshaft-cartodb" do 264 | cwd "#{install_prefix}/src/Windshaft-cartodb" 265 | command <<-EOS 266 | mkdir -p log pids 267 | chown -R vagrant:vagrant log pids 268 | [ -f pids/windshaft.pid ] && kill `cat pids/windshaft.pid` 269 | nohup node app.js development >> #{install_prefix}/src/Windshaft-cartodb/log/development.log 2>&1 & 270 | echo $! > #{install_prefix}/src/Windshaft-cartodb/pids/windshaft.pid 271 | EOS 272 | user 'root' 273 | end 274 | 275 | 276 | git "CartoDB" do 277 | repository "git://github.com/Vizzuality/cartodb.git" 278 | reference 'master' 279 | destination "#{install_prefix}/src/cartodb" 280 | action :checkout 281 | user "root" 282 | end 283 | 284 | execute "setup cartodb" do 285 | # strip out the ruby-debug gem from the Gemfile since it consistently causes problems and 286 | # doesn't seem to install properly in all ruby environments and OS's. 287 | # also, overwrite `script/create_dev_user` with a custom one that doesn't prompt 288 | cwd "#{install_prefix}/src/cartodb" 289 | command <<-EOS 290 | if [ ! -f config/database.yml ] 291 | then 292 | chown -R vagrant:vagrant #{install_prefix}/src/cartodb 293 | 294 | sed 's/.*gem "ruby-debug.*//g' Gemfile > Gemfile.tmp && mv Gemfile.tmp Gemfile 295 | sed 's/^echo -n "Enter.*//g' script/create_dev_user > script/create_dev_user.tmp && mv script/create_dev_user.tmp script/create_dev_user 296 | 297 | export RY_PREFIX=#{install_prefix} && 298 | export PATH=$RY_PREFIX/lib/ry/current/bin:$PATH 299 | 300 | #{install_prefix}/lib/ry/current/bin/bundle install --binstubs && 301 | curl -s https://raw.github.com/gist/21c52f1eb9862a1dfffa/58cc1436d23153be0ad2502c8ed5459847c85685/app_config.yml -o config/app_config.yml && 302 | curl -s https://raw.github.com/gist/4c503e531fd54b3cbcec/0a435609a58e3f8401cfee5990e173b170e2cc82/database.yml -o config/database.yml && 303 | echo "127.0.0.1 admin.localhost.lan" | tee -a /etc/hosts && 304 | echo "127.0.0.1 admin.testhost.lan" | tee -a /etc/hosts && 305 | echo "127.0.0.1 cartodb.localhost.lan" | tee -a /etc/hosts && 306 | PASSWORD=cartodb ADMIN_PASSWORD=cartodb EMAIL=admin@cartodb sh script/create_dev_user cartodb 307 | fi 308 | EOS 309 | user "root" 310 | end 311 | 312 | execute "start cartodb" do 313 | cwd "#{install_prefix}/src/cartodb" 314 | command <<-EOS 315 | mkdir -p public log tmp pids 316 | chown -R vagrant:vagrant public log tmp pids 317 | [ -f pids/cartodb.pid ] && kill `cat pids/cartodb.pid` 318 | export RY_PREFIX=#{install_prefix} 319 | export PATH=$RY_PREFIX/lib/ry/current/bin:$PATH 320 | nohup bundle exec rails server >> #{install_prefix}/src/cartodb/log/development.log 2>&1 & 321 | echo $! > #{install_prefix}/src/cartodb/pids/cartodb.pid 322 | EOS 323 | user 'root' 324 | end 325 | 326 | execute "install imposm" do 327 | command <<-EOS 328 | pip install imposm.parser && 329 | pip install Shapely && 330 | pip install imposm 331 | EOS 332 | user 'root' 333 | end 334 | --------------------------------------------------------------------------------