forked from crosscite/doi-metadata-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
137 lines (116 loc) · 5.08 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
def installed_plugins(required_plugins)
required_plugins.reduce([]) do |missing, plugin|
if Vagrant.has_plugin?(plugin)
missing
else
puts "#{plugin} plugin is missing. Installing..."
%x(set -x; vagrant plugin install #{plugin})
missing << plugin
end
end
end
def load_env
# requires dotenv plugin/gem
require "dotenv"
# make sure DOTENV is set, defaults to "default"
ENV["DOTENV"] ||= "default"
# load ENV variables from file specified by DOTENV
# use .env with DOTENV=default
filename = ENV["DOTENV"] == "default" ? ".env" : ".env.#{ENV['DOTENV']}"
Dotenv.load! File.expand_path("../#{filename}", __FILE__)
rescue LoadError
$stderr.puts "Please install dotenv plugin with \"vagrant plugin install dotenv\""
exit
rescue Errno::ENOENT
$stderr.puts "Please create #{filename} file, or use DOTENV=example for example configuration"
exit
end
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here.
# Check if required plugins are installed.
required_plugins = %w{ vagrant-omnibus vagrant-bindfs dotenv }
unless installed_plugins(required_plugins).empty?
puts "Plugins have been installed, please rerun vagrant."
exit
end
# load ENV variables
load_env
# Install latest version of Chef
config.omnibus.chef_version = "12.4.1"
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "chef/ubuntu-14.04"
# Enable provisioning with chef solo
config.vm.provision :chef_solo do |chef|
chef.json = { "dotenv" => ENV["DOTENV"], "application" => ENV["APPLICATION"] }
chef.custom_config_path = "Vagrantfile.chef"
chef.cookbooks_path = "vendor/cookbooks"
dna = JSON.parse(File.read(File.expand_path("../node.json", __FILE__)))
dna.delete("run_list").each do |recipe|
chef.add_recipe(recipe)
end
chef.json.merge!(dna)
chef.log_level = ENV["LOG_LEVEL"].to_sym
end
# allow multiple machines, specified by DOTENV
config.vm.define ENV["DOTENV"] do |machine|
# Override settings for specific providers
machine.vm.provider :virtualbox do |vb, override|
vb.name = "#{ENV["APPLICATION"]}.virtualbox"
vb.customize ["modifyvm", :id, "--memory", "2048"]
unless Vagrant::Util::Platform.windows?
# Disable default synced folder before bindfs tries to bind to it
override.vm.synced_folder ".", "/var/www/#{ENV['APPLICATION']}/shared", disabled: true
override.vm.synced_folder ".", "/vagrant", id: "vagrant-root", nfs: true
override.bindfs.bind_folder "/vagrant", "/var/www/#{ENV['APPLICATION']}/shared",
:owner => "900",
:group => "900",
:"create-as-user" => true,
:perms => "u=rwx:g=rwx:o=rwx",
:"create-with-perms" => "u=rwx:g=rwx:o=rwx",
:"chown-ignore" => true,
:"chgrp-ignore" => true,
:"chmod-ignore" => true
end
end
machine.vm.provider :vmware_fusion do |fusion|
fusion.vmx["memsize"] = "2048"
fusion.vmx["numvcpus"] = "2"
end
machine.vm.provider :aws do |aws, override|
# please configure in .env
aws.access_key_id = ENV.fetch('AWS_KEY', nil)
aws.secret_access_key = ENV.fetch('AWS_SECRET', nil)
aws.keypair_name = ENV.fetch('AWS_KEYNAME', nil)
override.ssh.username = "ubuntu"
override.ssh.private_key_path = ENV.fetch('SSH_PRIVATE_KEY', nil)
aws.security_groups = ENV.fetch('AWS_SECURITY_GROUP', "default")
aws.instance_type = ENV.fetch('AWS_INSTANCE_TYPE', nil)
aws.ami = ENV.fetch('AWS_AMI', nil)
aws.region = ENV.fetch('AWS_REGION', "us-east-1")
aws.tags = { Name: ENV["APPLICATION"] }
override.nfs.functional = false
override.vm.synced_folder ".", "/var/www/#{ENV['APPLICATION']}/shared", type: "rsync", rsync__exclude: [".git/", ".bundle/", "vendor/bundle/ruby"]
override.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
end
machine.vm.provider :digital_ocean do |digital_ocean, override|
# please configure in .env
override.ssh.private_key_path = ENV.fetch('SSH_PRIVATE_KEY', nil)
digital_ocean.token = ENV.fetch('DO_PROVIDER_TOKEN', nil)
digital_ocean.size = ENV.fetch('DO_SIZE', nil)
override.vm.box = 'digital_ocean'
override.vm.box_url = "https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box"
override.ssh.username = "ubuntu"
digital_ocean.region = 'nyc2'
digital_ocean.image = 'ubuntu-14-04-x64'
end
machine.vm.hostname = ENV.fetch('HOSTNAME')
machine.vm.network :private_network, ip: ENV.fetch('PRIVATE_IP', nil)
machine.vm.network :public_network
machine.vm.synced_folder ".", "/var/www/#{ENV['APPLICATION']}/shared", id: "vagrant-root"
end
# config.push.define "capistrano" do |push|
# push.stage = ENV.fetch("STAGE", "production")
# end
end