-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Vagrantfile
202 lines (180 loc) · 8.22 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'getoptlong'
# Parse CLI arguments.
opts = GetoptLong.new(
[ '--ami', GetoptLong::OPTIONAL_ARGUMENT ], # AMI to use.
[ '--asset', GetoptLong::OPTIONAL_ARGUMENT ], # Asset to download (see: get_gh_asset.sh).
[ '--clone-repo', GetoptLong::OPTIONAL_ARGUMENT ], # Clone git repository.
[ '--cpus', GetoptLong::OPTIONAL_ARGUMENT ], # Number of CPUs.
[ '--ec2-region', GetoptLong::OPTIONAL_ARGUMENT ], # EC2 region.
[ '--git-args', GetoptLong::OPTIONAL_ARGUMENT ], # Git arguments for commit (e.g. author).
[ '--github-token', GetoptLong::OPTIONAL_ARGUMENT ], # GitHub API access token.
[ '--instance-type', GetoptLong::OPTIONAL_ARGUMENT ], # EC2 instance type.
[ '--keypair-name', GetoptLong::OPTIONAL_ARGUMENT ], # SSH access keypair name (EC2).
[ '--memory', GetoptLong::OPTIONAL_ARGUMENT ], # Size of memory.
[ '--no-setup', GetoptLong::OPTIONAL_ARGUMENT ], # No setup when set.
[ '--power-off', GetoptLong::OPTIONAL_ARGUMENT ], # Power off when set.
[ '--private-key', GetoptLong::OPTIONAL_ARGUMENT ], # Path to private key.
[ '--provider', GetoptLong::OPTIONAL_ARGUMENT ], # Name of provider (e.g. aws).
[ '--push-repo', GetoptLong::OPTIONAL_ARGUMENT ], # Push changes when set.
[ '--run-test', GetoptLong::OPTIONAL_ARGUMENT ], # Arguments for run_backtest.sh.
[ '--security-group', GetoptLong::OPTIONAL_ARGUMENT ], # Name of EC2 security group.
[ '--subnet-id', GetoptLong::OPTIONAL_ARGUMENT ], # Name of subnet ID (EC2).
[ '--terminate', GetoptLong::OPTIONAL_ARGUMENT ], # Terminate instance when set.
[ '--volume-size', GetoptLong::OPTIONAL_ARGUMENT ], # Volume size (in GB).
[ '--vm-name', GetoptLong::OPTIONAL_ARGUMENT ], # Name of the VM.
)
ami = ENV['AMI'] || "ami-fce3c696"
asset = ENV['ASSET']
clone_repo = ENV['CLONE_REPO']
cpus = ENV['CPUS'] || 2
ec2_region = ENV['EC2_REGION'] || 'us-east-1'
git_args = ENV['GIT_ARGS']
github_token = ENV['GITHUB_API_TOKEN']
instance_type = ENV['INSTANCE_TYPE'] || 't2.small'
keypair_name = ENV['KEYPAIR_NAME']
memory = ENV['MEMORY'] || 2048
no_setup = ENV['NO_SETUP']
power_off = ENV['POWER_OFF']
private_key = ENV['PRIVATE_KEY']
provider = ENV['PROVIDER'] || 'virtualbox'
push_repo = ENV['PUSH_REPO']
run_test = ENV['RUN_TEST']
security_group = ENV['SECURITY_GROUP']
subnet_id = ENV['SUBNET_ID']
terminate = ENV['TERMINATE']
volume_size = ENV['VOLUME_SIZE'] || 16
vm_name = ENV['VM_NAME'] || 'default'
begin
opts.each do |opt, arg|
case opt
when '--asset'; asset = arg.to_s
when '--clone-repo'; clone_repo = arg.to_s
when '--cpus'; cpus = arg.to_i
when '--ec2-region'; ec2_region = arg.to_s
when '--git-args'; git_args = arg.to_s
when '--github-token'; github_token = arg.to_s
when '--instance-type'; instance_type = arg.to_s
when '--keypair-name'; keypair_name = arg
when '--memory'; memory = arg.to_i
when '--no-setup'; no_setup = !arg.to_i.zero?
when '--power-off'; power_off = arg.to_i
when '--private-key'; private_key = arg
when '--provider'; provider = arg
when '--push-repo'; push_repo = !arg.to_i.zero?
when '--run-test'; run_test = arg
when '--security-group'; security_group = arg
when '--subnet-id'; subnet_id = arg
when '--terminate'; terminate = !arg.to_i.zero?
when '--volume-size'; volume_size = arg.to_i
when '--vm-name'; vm_name = arg
end # case
end # each
rescue
# @todo: Correct an invalid option error.
end
script = "set -x;"
# Vagrantfile API/syntax version.
Vagrant.configure(2) do |config|
config.ssh.forward_agent = true # Enables agent forwarding over SSH connections.
config.ssh.forward_x11 = true # Enables X11 forwarding over SSH connections.
config.ssh.keep_alive = true # Sends keep-alive packets to keep connections alive.
config.ssh.pty = false # Use pty for provisioning. Bug: mitchellh/vagrant/8118.
config.vm.define "MT-#{provider}-#{vm_name}"
config.vm.hostname = "vagrant"
# config.vm.synced_folder ".", "/vagrant", id: "core", nfs: true
if not no_setup
config.vm.provision "shell", path: "scripts/provision.sh"
end
if asset
script << %Q[/usr/bin/env \
CLEAN=1 \
OVERRIDE=1 \
GITHUB_API_TOKEN=#{github_token} \
ASSET_OVERRIDE=#{ENV['ASSET_OVERRIDE']} \
/vagrant/scripts/get_gh_asset.sh #{asset} &&]
end
if clone_repo
script << %Q[/vagrant/scripts/clone_repo.sh "#{clone_repo}" &&]
end
if run_test
script << %Q[/usr/bin/env \
RUN_ON_START=#{ENV['RUN_ON_START']} \
GIF_ENHANCE=#{ENV['GIF_ENHANCE']} \
GIF_TEXT_COLOR=#{ENV['GIF_TEXT_COLOR']} \
/vagrant/scripts/run_backtest.sh #{run_test} &&]
end
if push_repo
# The clone_repo parameter is required for push to work correctly.
script << %Q[/usr/bin/env \
OPT_TRACE=1 \
GIT_ARGS='#{git_args}' \
/vagrant/scripts/push_repo.sh '#{clone_repo}' '#{vm_name}' '#{vm_name}' &&]
end
if power_off
script << "echo Stopping the VM...; sudo poweroff --verbose &&"
end
config.vm.provision "shell" do |s|
s.binary = true # Replace Windows line endings with Unix line endings.
s.privileged = false # Run as a non privileged user.
s.inline = script << "echo done"
end
config.vm.provider "virtualbox" do |vbox, override|
vbox.customize [ "modifyvm", :id, "--natdnshostresolver1", "on"]
vbox.customize [ "modifyvm", :id, "--memory", memory ]
vbox.customize [ "modifyvm", :id, "--cpus", cpus ]
vbox.name = "mt-tester.local"
override.cache.auto_detect = true # Enable cachier for local vbox VMS.
override.vm.box = "ubuntu/wily64"
override.vm.network :private_network, ip: "192.168.22.22"
override.vm.synced_folder ".", "/vagrant", id: "core", nfs: true
# Configure VirtualBox environment
if Vagrant.has_plugin?("vagrant-cachier")
# Configure cached packages to be shared between instances of the same base box.
# More info on http://fgrehm.viewdocs.io/vagrant-cachier/usage
override.cache.scope = :box
end
end
# AWS EC2 provider
config.vm.provider :aws do |aws, override|
aws.ami = ami
aws.block_device_mapping = [{ 'DeviceName' => '/dev/sda1', 'Ebs.VolumeSize' => volume_size }]
aws.instance_type = instance_type
aws.keypair_name = keypair_name
aws.region = ec2_region
aws.tags = { 'Name' => 'MT4-' + vm_name }
aws.terminate_on_shutdown = terminate
aws.user_data = 'sed -i\'.bak\' -e \'s/^\(Defaults\s\+requiretty\)/# \1/\' /etc/sudoers'
if private_key then override.ssh.private_key_path = private_key end
if security_group then aws.security_groups = [ security_group ] end
if subnet_id then aws.subnet_id = subnet_id end
override.nfs.functional = false # # @see: https://github.com/mitchellh/vagrant/issues/1437
override.ssh.username = "ubuntu"
override.vm.box = "mt4-backtest"
override.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
# aws.instance_type = "m3.medium" # 7747d01e
end
config.vm.provider :managed do |managed, override|
override.vm.box = "managed_dummy_box"
override.vm.box_url = "https://github.com/tknerr/vagrant-managed-servers/raw/master/dummy.box"
# managed.server = server # link with this server
end
# Parameters for specific providers.
case provider
when "virtualbox"
when "aws"
end
# Extra plugin settings.
if Vagrant.has_plugin?("vagrant-timezone")
config.timezone.value = :host
end
if Vagrant.has_plugin?("vagrant-vbguest")
# Set auto_update to false, if you do NOT want to check the correct
# additions version when booting this machine.
config.vbguest.auto_update = true
# Do NOT download the iso file from a webserver.
config.vbguest.no_remote = false
config.vbguest.installer_arguments = ['--nox11']
end
end