This repository has been archived by the owner on Aug 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
143 lines (121 loc) · 4.35 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- mode: ruby -*-
# vi: set ft=ruby :
# First some installation scripts, vagrant conf itself is lower down
# The base box only has the C locale installed, these should cover most uses
$generate_locales = <<SCRIPT
locale-gen fi_FI.UTF-8
locale-gen en_US.UTF-8
SCRIPT
# Installs absolute minimun for building/running
$install_packages = <<SCRIPT
curl --silent --location https://deb.nodesource.com/setup_4.x | sudo bash -
apt-get install -y --no-install-recommends build-essential git postgresql nodejs xvfb firefox=28.0+build2-0ubuntu2 openjdk-7-jre-headless
SCRIPT
# Some configuration changes need to be made to postgres to allow local
# logins with passwords.
$configure_postgres = <<SCRIPT
cp /vagrant/vagrant/pg_hba.conf /etc/postgresql/9.3/main/
service postgresql reload
SCRIPT
# Configure xvfb to start at boot
$configure_xvfb = <<SCRIPT
echo "Copying xvfb service script"
cp /vagrant/vagrant/xvfb /etc/init.d/
chmod a+x /etc/init.d/xvfb
echo "Setting xvfb to startup"
update-rc.d xvfb defaults
echo "Starting xvfb"
service xvfb start
SCRIPT
# Download selenium and configure it to start at boot
$configure_selenium = <<SCRIPT
selenium_dir=/selenium
selenium_version_minor="2.53"
selenium_version_patch="0"
echo "Removing old selenium directory and creating new"
rm -rf "$selenium_dir"
mkdir "$selenium_dir"
cd "$selenium_dir"
echo "Downloading selenium server"
wget --no-verbose -O "selenium-server-standalone.jar" "http://selenium-release.storage.googleapis.com/$selenium_version_minor/selenium-server-standalone-$selenium_version_minor.$selenium_version_patch.jar"
echo "Download complete"
echo "Copying selenium service script"
cp /vagrant/vagrant/selenium /etc/init.d/
chmod a+x /etc/init.d/selenium
echo "Set selenium to startup"
update-rc.d selenium defaults
echo "Starting selenium"
service selenium start
SCRIPT
# To enable global installations with npm without using sudo, change
# ownership of some directories to the vagrant default user.
$ensure_permissions = <<SCRIPT
vagrant_user="vagrant"
bin="/usr/bin"
node_modules="/usr/lib/node_modules"
mkdir -p "$bin"
mkdir -p "$node_modules"
chown "$vagrant_user" "$bin"
chown -R "$vagrant_user" "$node_modules"
SCRIPT
# Set the NODE_ENV environment variable, and the default login location
# This script will be run as the unprivileged development user.
$configure_dotprofile = <<SCRIPT
profile_dir=~/.profile
locale="en_US.UTF-8"
export_env_if_unset() {
if [ -z "${!1}" ]; then
echo "export $1=$2" >> "$profile_dir"
fi
}
source "$profile_dir"
export_env_if_unset "NODE_ENV" "dev"
export_env_if_unset "LANG" "$locale"
export_env_if_unset "LANGUAGE" "$locale"
export_env_if_unset "LC_ALL" "$locale"
export_env_if_unset "DISPLAY" ":1"
if [ $(pwd) != "/vagrant" ]; then
echo "cd /vagrant" >> "$profile_dir"
fi
SCRIPT
# Finally install npm dependencies and setup development database.
# Vagrant mounts the project directory at /vagrant.
# This script will be run as the unprivileged development user.
$install_project = <<SCRIPT
cd /vagrant
npm install -g strongloop || exit 1
npm install || exit 1
sudo -u postgres npm run dev-teardown || exit 1
sudo -u postgres npm run dev-setup || exit 1
exit 0
SCRIPT
Vagrant.configure(2) do |config|
# The development virtual machine will run Ubuntu 14.04 Trusty Tahr
config.vm.box = "ubuntu/trusty64"
# Forward port 3000 into the virtual machine to be able to access
# the software from the host
config.vm.network "forwarded_port", guest: 3000, host: 3000
# By default 512MB of memory is reserved for the machine, but npm requires
# more for some operations. This proved to be enough, though it might be
# able to survive with less.
config.vm.provider "virtualbox" do |v|
v.memory = 1536
end
# Run provisioning scripts in this order.
config.vm.provision "shell", inline: $generate_locales
config.vm.provision "shell", inline: $install_packages
config.vm.provision "shell", inline: $configure_postgres
config.vm.provision "shell", inline: $configure_xvfb
config.vm.provision "shell", inline: $configure_selenium
config.vm.provision "shell", inline: $ensure_permissions
# environment setup, npm installations and project setup need to be run
# as the development user
config.vm.provision "shell" do |s|
s.privileged = false
s.inline = $configure_dotprofile
end
config.vm.provision "shell" do |s|
s.privileged = false
s.inline = $install_project
end
end