Add -PackerOnly option

Add same functionality as build.sh to PS script
This commit is contained in:
Dustin Lee
2019-05-08 16:37:08 -04:00
committed by GitHub
parent 6e1e52ba6d
commit 123e3e06fb

View File

@@ -25,6 +25,9 @@
.PARAMETER PackerPath .PARAMETER PackerPath
The full path to the packer executable. Default is C:\Hashicorp\packer.exe The full path to the packer executable. Default is C:\Hashicorp\packer.exe
.PARAMETER PackerOnly
This switch skips deploying boxes with vagrant after being built by packer
.PARAMETER VagrantOnly .PARAMETER VagrantOnly
This switch skips building packer boxes and instead downloads from Vagrant Cloud This switch skips building packer boxes and instead downloads from Vagrant Cloud
@@ -48,6 +51,7 @@ Param(
[ValidateSet('virtualbox', 'vmware_desktop')] [ValidateSet('virtualbox', 'vmware_desktop')]
[string]$ProviderName, [string]$ProviderName,
[string]$PackerPath = 'C:\Hashicorp\packer.exe', [string]$PackerPath = 'C:\Hashicorp\packer.exe',
[switch]$PackerOnly,
[switch]$VagrantOnly [switch]$VagrantOnly
) )
@@ -186,6 +190,7 @@ function preflight_checks {
break break
} }
} }
if (!($PackerOnly)) {
Write-Host '[preflight_checks] Checking if Vagrant is installed' Write-Host '[preflight_checks] Checking if Vagrant is installed'
check_vagrant check_vagrant
@@ -233,6 +238,7 @@ function preflight_checks {
break break
} }
} }
}
Write-Host '[preflight_checks] Finished.' Write-Host '[preflight_checks] Finished.'
} }
@@ -262,11 +268,11 @@ function move_boxes {
Write-Host "[move_boxes] Running.." Write-Host "[move_boxes] Running.."
Move-Item -Path $DL_DIR\Packer\*.box -Destination $DL_DIR\Boxes Move-Item -Path $DL_DIR\Packer\*.box -Destination $DL_DIR\Boxes
if (-Not (Test-Path "$DL_DIR\Boxes\windows_10_$PackerProvider.box")) { if (-Not (Test-Path "$DL_DIR\Boxes\windows_10_$PackerProvider.box")) {
Write-Error "Windows 10 box is missing from the Boxes directory. Qutting." Write-Error "Windows 10 box is missing from the Boxes directory. Quitting."
break break
} }
if (-Not (Test-Path "$DL_DIR\Boxes\windows_2016_$PackerProvider.box")) { if (-Not (Test-Path "$DL_DIR\Boxes\windows_2016_$PackerProvider.box")) {
Write-Error "Windows 2016 box is missing from the Boxes directory. Qutting." Write-Error "Windows 2016 box is missing from the Boxes directory. Quitting."
break break
} }
Write-Host "[move_boxes] Finished." Write-Host "[move_boxes] Finished."
@@ -387,8 +393,9 @@ if (!($VagrantOnly)) {
move_boxes move_boxes
} }
# Vagrant up each box and attempt to reload one time if it fails if (!($PackerOnly)) {
forEach ($VAGRANT_HOST in $LAB_HOSTS) { # Vagrant up each box and attempt to reload one time if it fails
forEach ($VAGRANT_HOST in $LAB_HOSTS) {
Write-Host "[main] Running vagrant_up_host for: $VAGRANT_HOST" Write-Host "[main] Running vagrant_up_host for: $VAGRANT_HOST"
$result = vagrant_up_host -VagrantHost $VAGRANT_HOST $result = vagrant_up_host -VagrantHost $VAGRANT_HOST
Write-Host "[main] vagrant_up_host finished. Exitcode: $result" Write-Host "[main] vagrant_up_host finished. Exitcode: $result"
@@ -406,8 +413,9 @@ forEach ($VAGRANT_HOST in $LAB_HOSTS) {
} }
} }
Write-Host "[main] Finished for: $VAGRANT_HOST" Write-Host "[main] Finished for: $VAGRANT_HOST"
} }
Write-Host "[main] Running post_build_checks" Write-Host "[main] Running post_build_checks"
post_build_checks post_build_checks
Write-Host "[main] Finished post_build_checks" Write-Host "[main] Finished post_build_checks"
}