This repository has been archived by the owner on Feb 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
80 lines (64 loc) · 3.3 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
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "groupeat.dev" do |machine|
machine.vm.box = "ubuntu/trusty64"
machine.vm.hostname = "PizzeriaDev"
# Configuring the Virtualbox provider for development
machine.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--ostype", "Ubuntu_64"]
# Giving the VM 1/4 system memory & access to all cpu cores on the host
host = RbConfig::CONFIG["host_os"]
if host =~ /darwin/
cpus = `sysctl -n hw.ncpu`.to_i
# sysctl returns Bytes and we need to convert to MB
memory = `sysctl -n hw.memsize`.to_i / 1024 / 1024 / 4
elsif host =~ /linux/
cpus = `nproc`.to_i
# meminfo shows KB and we need to convert to MB
memory = `grep "MemTotal" /proc/meminfo | sed -e "s/MemTotal://" -e "s/ kB//"`.to_i / 1024 / 4
else # sorry Windows folks
cpus = 2
memory = 2048
end
vb.customize ["modifyvm", :id, "--memory", memory]
vb.customize ["modifyvm", :id, "--cpus", cpus]
end
# Configuring the shared folders
machine.vm.synced_folder Dir.pwd + "/../groupeat-api", "/home/vagrant/api/current", nfs: true
machine.vm.synced_folder Dir.pwd + "/../groupeat-web-app", "/home/vagrant/app/current", nfs: true
machine.vm.synced_folder Dir.pwd + "/../groupeat-showcase", "/home/vagrant/showcase/current", nfs: true
# Configuring the VM IP on the local private network
machine.vm.network "private_network", ip: "192.168.10.10"
# Forward Livereload
machine.vm.network :forwarded_port, guest: 35729, host: 35729
# Copying the SSH private key to the box
machine.vm.provision "shell" do |s|
s.privileged = false
s.inline = "echo \"$1\" > /home/vagrant/.ssh/id_rsa && chmod 600 /home/vagrant/.ssh/id_rsa"
s.args = [File.read(File.expand_path("~/.ssh/id_rsa"))]
end
# Copying the Git config into the VM
machine.vm.provision :file, source: "~/.gitconfig", destination: "/home/vagrant/.gitconfig" if File.exist?(ENV["HOME"] + "/.gitconfig")
# Copying the vagrant authorized keys to the root user
machine.vm.provision "shell", inline: "cp ~vagrant/.ssh/authorized_keys ~root/.ssh/authorized_keys"
# Running ansible to install all the needed software
machine.vm.provision "ansible" do |ansible|
ansible.playbook = "dev.yml"
end
# Adding Composer token for GitHub if existing
if File.exist?('.composer')
command = "composer config -g github-oauth.github.com " + File.read('.composer').tr("\n", "")
machine.vm.provision "shell", inline: command, privileged: false
end
# Updating composer
machine.vm.provision "shell", inline: "cd ~vagrant/api/current; composer self-update"
# Installing the API dependencies
machine.vm.provision "shell", inline: "cd ~vagrant/api/current; composer install", privileged: false
# Running the migrations
machine.vm.provision "shell", inline: "cd ~vagrant/api/current; php artisan migrate --seed", privileged: false
# Pulling the Adminer files
machine.vm.provision "shell", inline: "cd ~vagrant/api/current; php artisan adminer", privileged: false
end
end