diff --git a/.gitignore b/.gitignore index f88ac4237..b1844090e 100644 --- a/.gitignore +++ b/.gitignore @@ -182,7 +182,6 @@ FakesAssemblies/ SampleConfig.ps1 SampleConfig/* -output-virtualbox-iso/ packer_cache/ *.box .vagrant/ diff --git a/README.md b/README.md index 7f4e01a6d..b99c18549 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,12 @@ The community has also submitted a few [other options](https://github.com/Octopu ## Development -This project is setup to use [Vagrant](vagrant.io) to provide a dev/test environment. Once you've installed Vagrant, you can use the build scripts to spin up a local virtual machine and run the test scenarios (**NOTE:** The first time you run `vagrant up` in Virtualbox or Hyper-V it has to download the `octopusdeploy/dsc-test-server` box and this can take some time depending on your Internet speed, so be patient and go grab a coffee while it downloads). +This project is setup to use [Vagrant](vagrant.io) to provide a dev/test environment. Once you've installed Vagrant, you can use the build scripts to spin up a local virtual machine and run the test scenarios There are four options provided: - [build-aws.ps1](build-aws.ps1) - [build-azure.ps1](build-azure.ps1) - - [build-hyperv-ps1](build-hyperv-ps1) - windows virtualisation - - [build-virtualbox.ps1](build-virtualbox.ps1) - cross-platform virtualisation On a build server, you most likely want to use [build-aws.ps1](build-aws.ps1) to spin up a virtual machine on AWS to run the tests. @@ -54,22 +52,8 @@ Configuration is handled by environment variables. The shell scripts will show a To run just the scenarios locally, follow these steps: 1. Install Vagrant from [vagrantup.com](https://vagrantup.com). (Note: version after 2.2.3 have altered WinRM upload behaviour which may cause issues) -2. Install VirtualBox from [virtualbox.org](https://virtualbox.org) or Hyper-V (`Install-WindowsFeature –Name Hyper-V -IncludeManagementTools -Restart` ) -3. _**If you are on a Mac or Linux**_ you need to install PowerShell, see https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md. -4. If you want to test locally using virtualbox - - Download the Octopus version of [vagrant-dsc](https://github.com/OctopusDeploy/vagrant-dsc/releases/download/v2.0.2/vagrant-dsc-2.0.2.gem) - - Run `vagrant plugin install ie vagrant plugin install c:\temp\vagrant-dsc-2.0.2.gem` - - Run `vagrant plugin install vagrant-winrm-syncedfolders` - - Run `Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))` to install Chocolatey on the Host system. - - Run `build-virtualbox.ps1`. This will run all the scenarios under the [Tests](Tests) folder. -5. If you want to test locally using Hyper-V - - Download the Octopus version of [vagrant-dsc](https://github.com/OctopusDeploy/vagrant-dsc/releases/download/v2.0.2/vagrant-dsc-2.0.2.gem) - - Run `vagrant plugin install ie vagrant plugin install c:\temp\vagrant-dsc-2.0.2.gem` - - Run `vagrant plugin install vagrant-winrm-syncedfolders` - - Run `Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))` to install Chocolatey on the Host system. - - Optionally set the environment variable `OctopusDSCVMSwitch`, to use a specific Hyper-V switch by name. For example, for older Hyper-V systems, you may wish to set this to 'External Connection' - - Run `build-hyperv.ps1`. This will run all the scenarios under the [Tests](Tests) folder. -6. If you want to test using AWS +2. _**If you are on a Mac or Linux**_ you need to install PowerShell, see https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md. +3. If you want to test using AWS - Run `vagrant plugin install vagrant-aws`. If you run into issues around libxml2, take a look at https://github.com/mitchellh/vagrant-aws/issues/539 - Run `vagrant plugin install vagrant-aws-winrm` - Set an environment variable `AWS_ACCESS_KEY_ID` to a valid value @@ -77,7 +61,7 @@ To run just the scenarios locally, follow these steps: - Set an environment variable `AWS_SUBNET_ID` to a valid subnet where you want the instance launched - Set an environment variable `AWS_SECURITY_GROUP_ID` to a valid security group you want to assign to the instance - Run `build-aws.ps1`. This will run all the scenarios under the [Tests](Tests) folder. -7. If you want to test using Azure +4. If you want to test using Azure - Run `vagrant plugin install vagrant-azure` - Set an environment variable `AZURE_VM_PASSWORD` to a valid value - Set an environment variable `AZURE_SUBSCRIPTION_ID` to a valid value @@ -85,7 +69,7 @@ To run just the scenarios locally, follow these steps: - Set an environment variable `AZURE_CLIENT_ID` to a valid value - Srt an environment variable `AZURE_CLIENT_SECRET` to a valid value - Run `build-azure.ps1`. This will run all the scenarios under the [Tests](Tests) folder. -8. Run `vagrant destroy -f` or the appropriate `cleanup-*.ps1` once you have finished to kill the virtual machine. +5. Run `vagrant destroy -f` or the appropriate `cleanup-*.ps1` once you have finished to kill the virtual machine. Each of the `build-*` scripts can take parameters at the command prompt. @@ -102,4 +86,4 @@ These are generally designed to tighten the feedback loop during development, si Tests are written in [ServerSpec](serverspec.org), which is an infrastructure oriented layer over [RSpec](rspec.info) and use our [octopus-serverspec-extensions](https://github.com/OctopusDeploy/octopus-serverspec-extensions) project for octopus-specific tests. -When creating a PR, please ensure that all existing tests run succesfully against VirtualBox, and please include a new scenario where possible. Before you start, please raise an issue to discuss your plans so we can make sure it fits with the goals of the project. +When creating a PR, please ensure that all existing tests run succesfully, and please include a new scenario where possible. Before you start, please raise an issue to discuss your plans so we can make sure it fits with the goals of the project. diff --git a/Tests/powershell-helpers.ps1 b/Tests/powershell-helpers.ps1 index a6fa2d2ae..463cc7e31 100644 --- a/Tests/powershell-helpers.ps1 +++ b/Tests/powershell-helpers.ps1 @@ -119,7 +119,7 @@ function Test-LogContainsRetriableFailure($log) { function Invoke-VagrantWithRetries { param( - [ValidateSet("aws", "azure", "hyperv", "virtualbox")] + [ValidateSet("aws", "azure")] $provider, $retries = 3, [switch]$retainondestroy, @@ -167,11 +167,6 @@ function Set-OctopusDSCEnvVars { [string]$OctopusVersion ) - if(-not $env:OctopusDSCVMSwitch) - { - $env:OctopusDSCVMSwitch = 'Default Switch' # Override this variable to use a different switch in hyper-v - } - # Clear the OctopusDSCTestMode Env Var if(Test-Path env:\OctopusDSCTestMode) { get-item env:\OctopusDSCTestMode | Remove-Item @@ -201,7 +196,7 @@ function Set-OctopusDSCEnvVars { } # offline installers - saves downloading a ton of installer data, can speed things up on slow connections - # only really useful for hyper-v and virtualbox. currently broken + # only really useful for local VM. currently broken. if($offline.IsPresent) { Set-OfflineConfig } else { diff --git a/build-aws.ps1 b/build-aws.ps1 index c991832f3..1d2cc9b51 100755 --- a/build-aws.ps1 +++ b/build-aws.ps1 @@ -1,6 +1,5 @@ #!/usr/local/bin/pwsh param( - [switch]$offline, [switch]$SkipPester, [switch]$ServerOnly, [switch]$TentacleOnly, diff --git a/build-azure.ps1 b/build-azure.ps1 index 47acddaad..b5b130ef0 100755 --- a/build-azure.ps1 +++ b/build-azure.ps1 @@ -1,6 +1,5 @@ #!/usr/local/bin/pwsh param( - [switch]$offline, [switch]$SkipPester, [switch]$ServerOnly, [switch]$TentacleOnly, diff --git a/build-hyperv.ps1 b/build-hyperv.ps1 deleted file mode 100644 index c3f43b6d8..000000000 --- a/build-hyperv.ps1 +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/local/bin/pwsh -#Requires -RunAsAdministrator -param( - [switch]$offline, - [switch]$SkipPester, - [switch]$ServerOnly, - [switch]$TentacleOnly, - [string]$OctopusVersion, - [switch]$retainondestroy, - [switch]$debug -) - -. Tests/powershell-helpers.ps1 - -Start-Transcript .\vagrant-hyperv.log - -Set-OctopusDscEnvVars @PSBoundParameters - -# remove psreadline as it interferes with the SMB password prompt -if(Get-Module PSReadLine) { - Remove-Module PSReadLine -} - -if (-not (Test-AppExists "vagrant")) { - Write-Output "Please install vagrant from vagrantup.com." - exit 1 -} -Write-Output "Vagrant installed - good." - -if ((Get-CimInstance Win32_OperatingSystem).PRODUCTTYPE -eq 1) { - # client OS detected - if ((Get-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Hyper-V').State -eq 'Disabled') { - Write-Output 'Please install Hyper-V.' - exit 1 - } -} -else { - # server OS detected - if ((Get-WindowsFeature 'Hyper-V').State -eq 'Disabled') { - Write-Output 'Please install Hyper-V.' - exit 1 - } -} -Write-Output "Hyper-V installed - good." - -if (-not (Get-VMSwitch -Name $env:OctopusDSCVMSwitch -ErrorAction SilentlyContinue)) { - Write-Output "Could not find a Hyper-V switch called $($env:OctopusDSCVMSwitch)" - exit 1 -} -Write-Output (@("Hyper-V virtual switch '", $env:OctopusDSCVMSwitch, "' detected - good.") -join "") - -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" -} - -$splat = @{ - provider="hyperv"; - retainondestroy = $retainondestroy.IsPresent; # set to $true to override in this script - debug = $debug.IsPresent; # set to $true to override in this script -} - -Invoke-VagrantWithRetries @splat - -Write-Output "Don't forget to run 'vagrant destroy -f' when you have finished" - -stop-transcript diff --git a/build-virtualbox.ps1 b/build-virtualbox.ps1 deleted file mode 100644 index 20eb5be59..000000000 --- a/build-virtualbox.ps1 +++ /dev/null @@ -1,51 +0,0 @@ -#!/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-virtualbox.log - -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 "VBoxManage")) { - Write-Output "Please install VirtualBox from virtualbox.org and ensure the installation path is added to the system environment path." - exit 1 -} -Write-Output "VirtualBox installed - good." - -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" -} - -$splat = @{ - provider = 'virtualbox'; - retainondestroy = $retainondestroy.IsPresent; - debug = $debug.IsPresent; -} - -Invoke-VagrantWithRetries @splat - -Write-Output "Don't forget to run 'vagrant destroy -f' when you have finished" - -stop-transcript diff --git a/vagrantfile b/vagrantfile index f17cb51a6..bdeacea33 100644 --- a/vagrantfile +++ b/vagrantfile @@ -99,39 +99,6 @@ Vagrant.configure(VAGRANT_FILE_API_VERSION) do |config| 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"] - v.customize ["modifyvm", :id, "--vram", "32"] - override.vm.box = "OctopusDeploy/dsc-test-server-windows-server-2019" - override.vm.box_url = "https://s3-ap-southeast-2.amazonaws.com/octopus-vagrant-boxes/vagrant/json/OctopusDeploy/virtualbox/dsc-test-server-windows-server-2019.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" - override.winrm.port = 5986 - override.winrm.ssl_peer_verification = false - end - - if Vagrant::Util::Platform.windows? then - config.vm.provider "hyperv" do |v, override| - override.vm.box = "OctopusDeploy/dsc-test-server-windows-server-1803" - override.vm.box_url = "https://s3-ap-southeast-2.amazonaws.com/octopus-vagrant-boxes/vagrant/json/OctopusDeploy/hyperv/dsc-test-server-windows-server-1803.json" - config.vm.network "public_network", bridge: ENV['OctopusDSCVMSwitch'] - v.memory = 4096 - v.maxmemory = 4096 - v.cpus = 2 - 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