Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #2948 from gratipay/vagranting
Browse files Browse the repository at this point in the history
Rebuilding Vagrant box with newer Ubuntu (fixes #2327)
  • Loading branch information
chadwhitacre committed Nov 19, 2014
2 parents c8b28c1 + 8f74fa4 commit fefe00d
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 61 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env: requirements.txt requirements_tests.txt setup.py
--unzip-setuptools \
--prompt="[gratipay] " \
--extra-search-dir=./vendor/ \
--always-copy \
./env/
$(pip) install -r requirements.txt
$(pip) install -r requirements_tests.txt
Expand Down
61 changes: 37 additions & 24 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,48 @@
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end

# For now we have a custom built vagrant image. It was built in the following manner:
#
# - Use 'precise64' as a base.
# - perform a 'vagrant up' using this vagrantfile:
# https://github.com/gratipay/gratipay.com/blob/83312e60c6b31c298ffca61036baa9849044c75e/Vagrantfile
# - drop database gratipay
# - drop role gratipay
# We use multi-machine config here. First one to rebuild the box from scratch
# (it is normally commented) and second (faster) that download built version.

# Previous configs are:
# - https://github.com/gratipay/gratipay.com/blob/83312e60c6b31c298ffca61036baa9849044c75e/Vagrantfile
# - https://github.com/gratipay/gratipay.com/blob/fc0b4395e85259cdd17d9fe8560bf654abd756ce/Vagrantfile


# --- [ common access parameters ] ---

# Gratipay app is accessible at http://localhost:8537/ from host
#
# Here are some instructions for modifying an existing box:
config.vm.network :forwarded_port, guest: 8537, host: 8537

# Current folder is available as /vagrant from guest.
# We speed up access by installing and using NFS as described here:
# https://docs.vagrantup.com/v2/synced-folders/nfs.html
config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.network "private_network", ip: "172.27.36.119"


# --- [ boxes ] ---
#
# http://www.pvcloudsystems.com/2012/10/vagrant-modify-existing-box/
# after you bootstrap this box, saving it into a gratipay.box is as easy as
# $ vagrant package --output gratipay.box
#
# I used that successfully on https://github.com/gratipay/gratipay.com/pull/2815.

config.vm.box = "gratipay"
config.vm.box_url = File.exist?("gratipay.box") ? "file://gratipay.box" : "https://downloads.gratipay.com/gratipay.box"
config.vm.define "basebox" do |base|
# using Ubuntu 14.04, because it is what our hosting (Heroku) uses
# (search cedar-14 for details)
base.vm.box = "ubuntu/trusty64"

# Sync the project directory and expose the app
config.vm.network "private_network", ip: "172.27.36.119"
config.vm.synced_folder ".", "/vagrant", type: "nfs"
config.vm.network :forwarded_port, guest: 8537, host: 8537
# --- install prerequisites ---
# [ ] use the same package versions as Heroku
# [ ] figure out how to fetch Heroku versions
base.vm.provision :shell, :path => "scripts/vagrant-debian.sh" # install system prerequisites
base.vm.provision :shell, :path => "scripts/vagrant-setup.sh" # apply user specific settings
end

# TODO: Pin apt-get packages to the same versions Heroku uses
#config.vm.define "gratipay" do |box|
# box.vm.box = "gratipay"
# box.vm.box_url = File.exist?("gratipay.box") ? "file://gratipay.box" : "https://downloads.gratipay.com/gratipay.box"
#end

# Installed dependencies are already part of the base image now
config.vm.provision :shell,
:path => "scripts/vagrant-setup.sh"
end
4 changes: 3 additions & 1 deletion gratipay/utils/fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def fake_tip_amount():
+ MIN_TIP)

decimal_amount = decimal.Decimal(amount).quantize(decimal.Decimal('.01'))

while decimal_amount == decimal.Decimal('0.00'):
# https://github.com/gratipay/gratipay.com/issues/2950
decimal_amount = fake_tip_amount()
return decimal_amount


Expand Down
2 changes: 0 additions & 2 deletions scripts/create_db.sql

This file was deleted.

1 change: 0 additions & 1 deletion scripts/create_test_db.sql

This file was deleted.

14 changes: 0 additions & 14 deletions scripts/crlf-warning.txt

This file was deleted.

7 changes: 7 additions & 0 deletions scripts/reset-db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DROP DATABASE IF EXISTS "gratipay-test";
DROP DATABASE IF EXISTS gratipay;
DROP ROLE IF EXISTS gratipay;

CREATE ROLE gratipay LOGIN PASSWORD 'gratipay' SUPERUSER;
CREATE DATABASE gratipay WITH OWNER = gratipay;
CREATE DATABASE "gratipay-test" WITH OWNER = gratipay;
9 changes: 9 additions & 0 deletions scripts/vagrant-debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

# installs Python-independent project dependencies

apt-get -y install postgresql
apt-get -y install libpq-dev
apt-get -y install python-dev # for building psycopg2
apt-get -y install g++ # for libsass
apt-get -y install git # for gratipay.version
3 changes: 3 additions & 0 deletions scripts/vagrant-postgre.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP ROLE IF EXISTS vagrant;

CREATE ROLE vagrant LOGIN SUPERUSER;
26 changes: 7 additions & 19 deletions scripts/vagrant-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,16 @@
set -e

# Set login directory to root vagrant share
echo "cd /vagrant" > /etc/profile.d/login-directory.sh
sudo sh -c "echo 'cd /vagrant' > /etc/profile.d/login-directory.sh"

# Configure Postgres
sudo -u postgres psql -U postgres -qf /vagrant/scripts/create_db.sql
sudo -u postgres psql -U postgres -qf /vagrant/scripts/create_test_db.sql

cd /vagrant

# Warn if Windows newlines are detected and try to fix the problem
if grep --quiet --binary --binary-files=without-match $(printf '\r') README.md; then
echo
cat scripts/crlf-warning.txt
echo

echo 'Running "git config core.autocrlf false"'
git config core.autocrlf false

exit 1
fi
# Configure Postgres (using system user 'postgres' run command
# 'psql' with PostreSQL user 'postgres` to quietly execute scripts)
sudo -u postgres psql -U postgres -qf /vagrant/scripts/reset-db.sql
sudo -u postgres psql -U postgres -qf /vagrant/scripts/vagrant-postgre.sql

# Set up the environment, the database, and run Gratipay
cd /vagrant && make clean env schema data
cd /vagrant
sudo -u vagrant make clean env schema data

# Output helper text
cat <<EOF
Expand Down

0 comments on commit fefe00d

Please sign in to comment.