-
Notifications
You must be signed in to change notification settings - Fork 117
/
Vagrantfile
70 lines (51 loc) · 2.66 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
ansible_vars = YAML.load_file('provisioning/vars.yml')
app_name = ansible_vars["nodejs_app_name"]
app_directory = ansible_vars["nodejs_app_install_dir"]
# Check for the existence of 'VM_HOST_TCP_PORT' or 'VM_GUEST_TCP_PORT'
# environment variables. Otherwise if 'nodejs_app_tcp_port' is defined
# in vars.yml then use that port. Failing that use defaults provided
# in this file.
host_tcp_port = ENV["VM_HOST_TCP_PORT"] || ansible_vars["nodejs_app_tcp_port"] || 8080
guest_tcp_port = ENV["VM_GUEST_TCP_PORT"] || ansible_vars["nodejs_app_tcp_port"] || 8080
# By default this VM will use 1 processor core and 1GB of RAM. The 'VM_CPUS' and
# "VM_RAM" environment variables can be used to change that behaviour.
cpus = ENV["VM_CPUS"] || 1
ram = ENV["VM_RAM"] || 1048
Vagrant.configure(2) do |config|
config.vm.box = "inclusivedesign/centos7"
# Your working directory will be synced to /home/vagrant/sync in the VM.
config.vm.synced_folder ".", "#{app_directory}"
# List additional directories to sync to the VM in your "Vagrantfile.local" file
# using the following format:
# config.vm.synced_folder "../path/on/your/host/os/your-project", "/home/vagrant/sync/your-project"
# Port forwarding takes place here. The 'guest' port is used inside the VM
# whereas the 'host' port is used by your host operating system.
config.vm.network "forwarded_port", guest: guest_tcp_port, host: host_tcp_port, protocol: "tcp",
auto_correct: true
# Port 19531 is needed so logs can be viewed using systemd-journal-gateway
config.vm.network "forwarded_port", guest: 19531, host: 19531, protocol: "tcp",
auto_correct: true
config.vm.hostname = app_name
config.vm.provider :virtualbox do |vm|
vm.customize ["modifyvm", :id, "--memory", ram]
vm.customize ["modifyvm", :id, "--cpus", cpus]
end
# The ansible-galaxy command assumes a git client is available in the VM, the
# inclusivedesign/centos7 Vagrant box includes one.
config.vm.provision "shell", inline: <<-SHELL
sudo ansible-galaxy install -fr #{app_directory}/provisioning/requirements.yml
sudo PYTHONUNBUFFERED=1 ansible-playbook #{app_directory}/provisioning/playbook.yml --tags="install,configure,deploy"
SHELL
# 'Vagrantfile.local' should be excluded from version control.
if File.exist? "Vagrantfile.local"
instance_eval File.read("Vagrantfile.local"), "Vagrantfile.local"
end
# http://serverfault.com/a/725051
config.vm.provision "shell", inline: "sudo systemctl restart #{app_name}.service",
run: "always"
config.vm.provision "shell", inline: "sudo systemctl restart systemd-journal-gatewayd.service",
run: "always"
end