forked from OctopusDeploy/OctopusDSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vagrantfile
242 lines (202 loc) · 12.7 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# -*- mode: ruby -*-
VAGRANT_FILE_API_VERSION = "2"
aws_access_key_id = ENV['AWS_ACCESS_KEY_ID'] || 'not-set'
aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] || 'not-set'
aws_subnet_id = ENV['AWS_SUBNET_ID'] || 'not-set'
aws_security_group_id = ENV['AWS_SECURITY_GROUP_ID'] || 'not-set'
aws_key_name = ENV['KEY_NAME'] || 'not-set'
azure_vm_password = ENV['AZURE_VM_PASSWORD'] || 'not-set'
$run_test_scenario_script = <<SCRIPT
write-output "##teamcity[blockOpened name='Testing Scenario {scenario_name}']"
$env:TEAMCITY_PROJECT_NAME="#{ENV['TEAMCITY_PROJECT_NAME']}"
set-location c:/temp/tests
write-host "executing bundle.bat _1.16.1_ exec rspec Spec/{scenario_name}_spec.rb --format documentation"
C:/tools/ruby25/bin/bundle.bat _1.16.1_ exec rspec Spec/{scenario_name}_spec.rb --format documentation
write-output "##teamcity[blockClosed name='Testing Scenario {scenario_name}']"
exit $LASTEXITCODE
SCRIPT
def run_octopus_scenario(config, scenario, configuration_params = nil)
config.vm.provision "shell", inline: "write-output \"##teamcity[blockOpened name='Running Scenario #{scenario}']\""
config.vm.provision "dsc" do |dsc|
dsc.configuration_file = "#{scenario}.ps1"
dsc.configuration_data_file = "Tests/Scenarios/Configuration.psd1"
dsc.manifests_path = "Tests/Scenarios"
dsc.abort_on_dsc_failure = true
dsc.configuration_params = configuration_params unless configuration_params.nil?
end
config.vm.provision "shell", inline: "write-output \"##teamcity[blockClosed name='Running Scenario #{scenario}']\""
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', scenario.downcase)
end
def run_tentacle_scenario(config, scenario, configuration_params = nil)
config.vm.provision "shell", inline: "write-output \"##teamcity[blockOpened name='Running Scenario #{scenario}']\""
config.vm.provision "dsc" do |dsc|
dsc.configuration_file = "#{scenario}.ps1"
dsc.configuration_data_file = "Tests/Scenarios/Configuration.psd1"
dsc.manifests_path = "Tests/Scenarios"
dsc.abort_on_dsc_failure = true
dsc.configuration_params = configuration_params unless configuration_params.nil?
end
config.vm.provision "shell", inline: "write-output \"##teamcity[blockClosed name='Running Scenario #{scenario}']\""
end
Vagrant.configure(VAGRANT_FILE_API_VERSION) do |config|
hostname = "vagrantdsc.local"
config.vm.guest = :windows
config.vm.communicator = "winrm"
config.vm.synced_folder ".", "/vagrant", disabled: true
if Vagrant.has_plugin?("vagrant-multi-hostsupdater")
config.multihostsupdater.aliases = {ip_address => [hostname]}
end
config.vm.provider "virtualbox" do |v, override|
v.gui = true
v.linked_clone = true
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--audio", "none"]
v.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
v.customize ["modifyvm", :id, "--usb", "off"]
override.vm.box = "OctopusDeploy/dsc-test-server-windows-2012-r2"
override.vm.box_url = "https://s3-ap-southeast-2.amazonaws.com/octopus-vagrant-boxes/vagrant/json/OctopusDeploy/virtualbox/dsc-test-server-windows-2012-r2.json"
override.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
override.vm.network :forwarded_port, guest: 80, host: 8000, id: "web"
override.vm.network :forwarded_port, guest: 443, host: 8443, id: "ssl"
override.vm.network :forwarded_port, guest: 22, host: 9222, id: "ssh"
end
if Vagrant::Util::Platform.windows? then
config.vm.provider "hyperv" do |v, override|
override.vm.box = "gusztavvargadr/w16s-sql17d" # temporary box url. We'll need to build one eventually
config.vm.network "public_network", bridge: "External Connection"
override.vm.synced_folder ".", "/vagrant", type: "smb", smb_host: "192.168.1.3" # this is required or it guesses the wrong IP
override.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct: true
override.vm.network :forwarded_port, guest: 80, host: 8000, id: "web"
override.vm.network :forwarded_port, guest: 443, host: 8443, id: "ssl"
override.vm.network :forwarded_port, guest: 22, host: 9222, id: "ssh"
end
end
# this relies on the vagrant-aws & vagrant-winrm-syncedfolders plugins
config.vm.provider :aws do |aws, override|
aws.access_key_id = aws_access_key_id
aws.secret_access_key = aws_secret_access_key
aws.region = "ap-southeast-2"
aws.instance_type = "c4.large"
aws.keypair_name = "#{aws_key_name}"
aws.tags = {
'Name' => 'Vagrant DSC testing'
}
aws.security_groups = [ aws_security_group_id ]
aws.subnet_id = aws_subnet_id
aws.associate_public_ip = true
aws.user_data = File.read("Tests/aws_user_data.ps1")
override.vm.box = "OctopusDeploy/dsc-test-server-windows-2012-r2" #box added via launcher script
override.ssh.private_key_path = "./#{aws_key_name}.pem"
override.winrm.username = "Administrator"
override.winrm.password = :aws # this uses the vagrant-aws-winrm plugin to get the password from aws
override.winrm.transport = :ssl
override.winrm.port = 5986
override.winrm.ssl_peer_verification = false
end
config.vm.provider :azure do |azure, override|
azure.resource_group_name = "OctopusDSCTesting"
azure.location = 'AustraliaEast'
azure.vm_name = "DSCTestVM"
azure.vm_size = 'Standard_DS2_v2'
azure.vm_image_urn = 'MicrosoftSQLServer:SQL2016SP1-WS2016:Express:latest'
azure.instance_ready_timeout = 600
azure.vm_password = azure_vm_password
azure.admin_username = "OctoAdmin"
azure.admin_password = azure_vm_password
override.vm.box = "dummy"
override.vm.box_url = "azure.dummy.box"
override.winrm.transport = :ssl
override.winrm.port = 5986
override.winrm.ssl_peer_verification = false
azure.winrm_install_self_signed_cert = true
azure.wait_for_destroy = true
end
# delete existing tests if they exist (for dev)
config.vm.provision "shell", inline: "if (Test-Path 'c:\\temp\\tests') {remove-item -force -recurse 'c:\\temp\\tests' }"
# upload tests
config.vm.provision "file", source: "Tests", destination: "c:\\temp\\tests"
config.vm.provision "shell", path: "Tests/install-test-dependencies.ps1"
# in theory, we shouldn't have to do this - the vagrant-dsc should upload it automatically, but cant get it to work
config.vm.provision "file", source: "OctopusDSC", destination: 'C:\Windows\System32\WindowsPowerShell\v1.0\modules\OctopusDSC'
config.vm.provision "shell", path: "Tests/configure-dsc-local-configuration-manager.ps1"
# Run DSC to install server
run_octopus_scenario(config, 'Server_Scenario_01_Install')
# Run DSC to install second HA node
run_octopus_scenario(config, 'Server_Scenario_02_Install_Second_Node')
# remove the first node
run_octopus_scenario(config, 'Server_Scenario_03_Remove')
# remove the second ode
run_octopus_scenario(config, 'Server_Scenario_04_Remove_Second_Node')
# Run DSC to install server with a custom instance name
run_octopus_scenario(config, 'Server_Scenario_05_Install_Custom_Instance')
# remove the server with a custom instance name
run_octopus_scenario(config, 'Server_Scenario_06_Remove_Custom_Instance')
# re-install old version
run_octopus_scenario(config, 'Server_Scenario_07_Reinstall')
# upgrade to the latest
run_octopus_scenario(config, 'Server_Scenario_08_Upgrade', { "-ApiKey" => "$ENV:OctopusApiKey" })
# install watchdog
run_octopus_scenario(config, 'Server_Scenario_09_Watchdog_Create')
# delete watchdog
run_octopus_scenario(config, 'Server_Scenario_10_Watchdog_Delete')
# remove again prior to installing 4
run_octopus_scenario(config, 'Server_Scenario_11_Remove')
# install v4
run_octopus_scenario(config, 'Server_Scenario_12_Built_In_Worker')
# remove again prior to testing "install only"
run_octopus_scenario(config, 'Server_Scenario_13_Remove')
# install only without configure
run_octopus_scenario(config, 'Server_Scenario_14_Install_Without_Configure')
# go from installed to configured
run_octopus_scenario(config, 'Server_Scenario_15_Configure_Preinstalled_Instance')
config.vm.provision "shell", path: "Tests/configure-octopus-for-tentacle-tests.ps1"
# initial tentacle install
run_tentacle_scenario(config, 'Tentacle_Scenario_01_Install', {"-OctopusServerUrl" => "$ENV:OctopusServerUrl",
"-ApiKey" => "$ENV:OctopusApiKey",
"-Environments" => "The-Env",
"-Roles" => "Test-Tentacle",
"-ServerThumbprint" => "$ENV:OctopusServerThumbprint" })
config.vm.provision "shell", inline: "& c:\\temp\\Tests\\register-polling-tentacle.ps1; exit $LASTEXITCODE"
config.vm.provision "shell", inline: "& c:\\temp\\Tests\\trigger-and-wait-for-healthcheck.ps1; exit $LASTEXITCODE"
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_01_install')
# uninstall tentacle
run_tentacle_scenario(config, 'Tentacle_Scenario_02_Remove', {"-OctopusServerUrl" => "$ENV:OctopusServerUrl",
"-ApiKey" => "$ENV:OctopusApiKey",
"-Environments" => "The-Env",
"-Roles" => "Test-Tentacle",
"-ServerThumbprint" => "$ENV:OctopusServerThumbprint" })
config.vm.provision "shell", inline: "& c:\\temp\\Tests\\trigger-and-wait-for-healthcheck.ps1; exit $LASTEXITCODE"
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_02_remove')
# Install old version
run_tentacle_scenario(config, 'Tentacle_Scenario_03_Reinstall', {"-OctopusServerUrl" => "$ENV:OctopusServerUrl",
"-ApiKey" => "$ENV:OctopusApiKey",
"-Environments" => "The-Env",
"-Roles" => "Test-Tentacle" })
config.vm.provision "shell", inline: "& c:\\temp\\Tests\\trigger-and-wait-for-healthcheck.ps1; exit $LASTEXITCODE"
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_03_reinstall')
# Upgrade it
run_tentacle_scenario(config, 'Tentacle_Scenario_04_Upgrade', {"-OctopusServerUrl" => "$ENV:OctopusServerUrl",
"-ApiKey" => "$ENV:OctopusApiKey",
"-Environments" => "The-Env",
"-Roles" => "Test-Tentacle" })
config.vm.provision "shell", inline: "& c:\\temp\\Tests\\trigger-and-wait-for-healthcheck.ps1; exit $LASTEXITCODE"
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_04_upgrade')
# install watchdog
run_tentacle_scenario(config, 'Tentacle_Scenario_05_Watchdog_Create')
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_05_watchdog_create')
# delete watchdog
run_tentacle_scenario(config, 'Tentacle_Scenario_06_Watchdog_Delete')
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_06_watchdog_delete')
# remove in preparation for testing comms port
run_tentacle_scenario(config, 'Tentacle_Scenario_07_Remove', {"-OctopusServerUrl" => "$ENV:OctopusServerUrl",
"-ApiKey" => "$ENV:OctopusApiKey",
"-Environments" => "The-Env",
"-Roles" => "Test-Tentacle" })
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_07_remove')
# tentacle comms port
run_tentacle_scenario(config, 'Tentacle_Scenario_08_Tentacle_Comms_Port', {"-OctopusServerUrl" => "$ENV:OctopusServerUrl",
"-ApiKey" => "$ENV:OctopusApiKey",
"-Environments" => "The-Env",
"-Roles" => "Test-Tentacle" })
config.vm.provision "shell", inline: $run_test_scenario_script.gsub('{scenario_name}', 'tentacle_scenario_08_tentacle_comms_port')
end