Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ruby on Vagrant VM and related document #135

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ to get and install the virtual machine - this will also install the libraries an
After that runs, type vagrant ssh to login and then you can

cd /srv/mapwarper
rails c
bundle exec rails c

Create a user in the console, as shown above and then exit

rails s -b 0.0.0.0 -p 3000
bundle exec rails s -b 0.0.0.0 -p 3000

to start the server, running on port 3000

Expand Down
61 changes: 41 additions & 20 deletions lib/vagrant/provision.sh
Original file line number Diff line number Diff line change
@@ -1,62 +1,83 @@
#!/usr/bin/env bash
set -eu

# constants
VAGRANT_HOME=/home/vagrant
RUBY_VERSION=2.2.1

# make sure we have up-to-date packages
apt-get update

## vagrant grub-pc fix from: https://gist.github.com/jrnickell/6289943
# parameters
echo "grub-pc grub-pc/kopt_extracted boolean true" | debconf-set-selections
echo "grub-pc grub2/linux_cmdline string" | debconf-set-selections
echo "grub-pc grub-pc/install_devices multiselect /dev/sda" | debconf-set-selections
echo "grub-pc grub-pc/install_devices_failed_upgrade boolean true" | debconf-set-selections
echo "grub-pc grub-pc/install_devices_disks_changed multiselect /dev/sda" | debconf-set-selections
echo "grub-pc grub-pc/kopt_extracted boolean true" | sudo debconf-set-selections
echo "grub-pc grub2/linux_cmdline string" | sudo debconf-set-selections
echo "grub-pc grub-pc/install_devices multiselect /dev/sda" | sudo debconf-set-selections
echo "grub-pc grub-pc/install_devices_failed_upgrade boolean true" | sudo debconf-set-selections
echo "grub-pc grub-pc/install_devices_disks_changed multiselect /dev/sda" | sudo debconf-set-selections
# vagrant grub fix
dpkg-reconfigure -f noninteractive grub-pc
sudo dpkg-reconfigure -f noninteractive grub-pc

# upgrade all packages
#apt-get upgrade -y

# install packages as explained in INSTALL.md
apt-get install -y ruby1.9.1 libruby1.9.1 ruby1.9.1-dev ri1.9.1 \
postgresql-9.3-postgis-2.1 postgresql-server-dev-all postgresql-contrib \
sudo apt-get install -y postgresql-9.3-postgis-2.1 postgresql-server-dev-all postgresql-contrib \
build-essential git-core \
libxml2-dev libxslt-dev imagemagick libmapserver1 gdal-bin libgdal-dev ruby-mapscript nodejs


#ruby gdal needs the build Werror=format-security removed currently
sed -i 's/-Werror=format-security//g' /usr/lib/ruby/1.9.1/x86_64-linux/rbconfig.rb

gem1.9.1 install bundle
sudo sed -i 's/-Werror=format-security//g' /usr/lib/ruby/1.9.1/x86_64-linux/rbconfig.rb


# install RVM https://rvm.io/integration/vagrant
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
rvm install $RUBY_VERSION
rvm use $RUBY_VERSION
rvm --default use $RUBY_VERSION # これが聞かない

which ruby
which gem

# link depended modules from global into local
ln -s \
"/usr/lib/x86_64-linux-gnu/ruby/vendor_ruby/2.0.0/mapscript.so" \
"/usr/local/rvm/rubies/ruby-$RUBY_VERSION/lib/ruby/vendor_ruby/2.2.0/x86_64-linux/mapscript.so"

# install module management package
gem install bundler

## install the bundle necessary for mapwarper
pushd /srv/mapwarper

# do bundle install as a convenience
sudo -u vagrant -H bundle install
# do bundle install as a convenience and put the dependencies outside to accelerate `bundle exec` command
bundle install --path $VAGRANT_HOME/mapwarper_dependencies

# create user and database for openstreetmap-website
db_user_exists=`sudo -u postgres psql postgres -tAc "select 1 from pg_roles where rolname='vagrant'"`
if [ "$db_user_exists" != "1" ]; then
sudo -u postgres createuser -s vagrant
sudo -u vagrant -H createdb -E UTF-8 -O vagrant mapwarper_development
createdb -E UTF-8 -O vagrant mapwarper_development
fi

# build and set up postgres extensions

sudo -u vagrant psql mapwarper_development -c "create extension postgis;"
psql mapwarper_development -c "create extension postgis;"


# set up sample configs
if [ ! -f config/database.yml ]; then
sudo -u vagrant cp config/database.example.yml config/database.yml
cp config/database.example.yml config/database.yml
fi
if [ ! -f config/application.yml ]; then
sudo -u vagrant cp config/application.example.yml config/application.yml
cp config/application.example.yml config/application.yml
fi
if [ ! -f config/secrets.yml ]; then
sudo -u vagrant cp config/secrets.yml.example config/secrets.yml
cp config/secrets.yml.example config/secrets.yml
fi

echo "now migrating database. This may take a few minutes"
# migrate the database to the latest version
sudo -u vagrant -H bundle exec rake db:migrate
bundle exec rake db:migrate
popd