-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathbuild-aws.ps1
executable file
·90 lines (71 loc) · 2.62 KB
/
build-aws.ps1
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
#!/usr/local/bin/pwsh
param(
[switch]$offline,
[switch]$SkipPester,
[switch]$ServerOnly,
[switch]$TentacleOnly,
[string]$OctopusVersion,
[switch]$retainondestroy,
[switch]$debug
)
. Tests/powershell-helpers.ps1
Start-Transcript .\vagrant-aws.log
Test-EnvVar AWS_ACCESS_KEY_ID
Test-EnvVar AWS_SECRET_ACCESS_KEY
Test-EnvVar AWS_SUBNET_ID
Test-EnvVar AWS_SECURITY_GROUP_ID
Set-OctopusDscEnvVars @PSBoundParameters
if (-not (Test-AppExists "vagrant")) {
Write-Output "Please install vagrant from vagrantup.com."
exit 1
}
Write-Output "Vagrant installed - good."
if (-not (Test-AppExists "aws")) {
Write-Output "Please install aws-cli. See https://docs.aws.amazon.com/cli/latest/userguide/installing.html."
exit 1
}
Write-Output "AWS CLI installed - good."
Test-PluginInstalled "vagrant-gecko-aws"
Test-PluginInstalled "vagrant-aws-winrm"
Test-CustomVersionOfVagrantDscPluginIsInstalled
Test-PluginInstalled "vagrant-winrm-syncedfolders"
Test-PluginInstalled "vagrant-winrm-file-download"
Remove-OldLogsBeforeNewRun
if(-not $SkipPester) {
Invoke-PesterTests
} else {
Write-Output "-SkipPester was specified, skipping pester tests"
}
$randomGuid=[guid]::NewGuid()
$keyName = "vagrant_$randomGuid"
[Environment]::SetEnvironmentVariable("KEY_NAME", $keyName)
Write-Output "Creating new key-pair $keyName"
$key = (& aws ec2 create-key-pair --key-name $keyName --query 'KeyMaterial' --output text --region ap-southeast-2)
if ($LASTEXITCODE -ne 0) {
Write-Output "Failed to create aws key-pair."
Write-Output "##teamcity[buildStatus text='{build.status.text}. AWS setup failed.']"
exit 1
}
Set-Content -Path "$keyName.pem" -Value $key
if (Test-AppExists "chmod") {
Write-Output "Setting permissions on pem file '$keyName.pem'"
& chmod 400 "./$keyName.pem"
} else {
Write-Output "chmod not found, skipping setting permissions on pem file"
}
Write-Output "Adding vagrant box"
vagrant box add OctopusDeploy/dsc-test-server-windows-server-2019 https://s3-ap-southeast-2.amazonaws.com/octopus-vagrant-boxes/vagrant/json/OctopusDeploy/amazon-ebs/dsc-test-server-windows-server-2019.json --force
Write-Output "Ensuring vagrant box is latest"
vagrant box update --box OctopusDeploy/dsc-test-server-windows-server-2019 --provider aws
$splat = @{
provider="aws";
retainondestroy = $retainondestroy.IsPresent;
debug = $debug.IsPresent;
}
Invoke-VagrantWithRetries @splat
if ($LASTEXITCODE -ne 0) {
Write-Output "Vagrant up failed with exit code $LASTEXITCODE"
Write-Output "##teamcity[buildStatus text='{build.status.text}. Vagrant failed.']"
exit $LASTEXITCODE
}
Write-Output "Don't forget to run 'cleanup-aws.ps1' when you have finished"