Skip to content

Commit

Permalink
Merge 43ac3ee into 3c328cb
Browse files Browse the repository at this point in the history
  • Loading branch information
gluka-CBS committed Jun 24, 2019
2 parents 3c328cb + 43ac3ee commit 346bd2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
4 changes: 3 additions & 1 deletion Config.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ function Get-AvailableConfigOptions {
"Description" = "Select between tar, gz, zip formats or any combination between these."},
@{"Name" = "zip_password";
"Description" = "If this parameter is set, after the image is generated,
a password protected zip archive with the image will be created."},
a password protected zip archive with the image will be created.
Previous parameter, compression_format, must contain zip format
in order for this parameter to be used"},
@{"Name" = "gold_image"; "DefaultValue" = $false; "AsBoolean" = $true;
"Description" = "It will stop the image generation after the updates are installed and cleaned."},
@{"Name" = "gold_image_path";
Expand Down
35 changes: 15 additions & 20 deletions WinImageBuilder.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ function Compress-Image {
}
throw "7za.exe failed while creating tar file for image: $tmpName"
}
Remove-Item -Force $ImagePath
Remove-Item -Force $VirtualDiskPath
}
if ($compresionFormat -eq "gz") {
Write-Log "Compressing $tmpName to gzip"
Expand All @@ -869,7 +869,16 @@ function Compress-Image {
$tmpName = ($tmpName + ".gz")
}
if ($compresionFormat -eq "zip") {
Write-Log "Archiving $VirtualDiskPath to zip $tmpName"
if ($ZipPassword) {
$zipPath = $tmpName + ".zip"
$7zip = Get-7zipPath
Write-Log "Creating protected zip..."
Write-Log "The zip password is: $ZipPassword"
Start-Executable -Command @("$7zip", "a", "-tzip", "$zipPath", `
"$tmpName", "-p$ZipPassword", "-mx1")
Remove-Item -Force $tmpName
} else {
Write-Log "Archiving $VirtualDiskPath to zip $tmpName"
# Avoid storing the full path in the archive
Write-Log "Creating zip archive..."
$zipName = $tmpName + ".zip"
Expand All @@ -881,24 +890,16 @@ function Compress-Image {
throw "7za.exe failed while creating tar file for image: $tmpName"
}
Remove-Item -Force $tmpName
}
}
} finally {
Pop-Location }
} finally { Write-Log "Archiving finished."}
}
} catch {
Remove-Item -Force $tmpName -ErrorAction SilentlyContinue
Remove-Item -Force $VirtualDiskPath -ErrorAction SilentlyContinue
throw
}
if ($ZipPassword) {
$zipPath = $tmpName + ".zip"
$7zip = Get-7zipPath
Write-Log "Creating protected zip..."
Write-Log "The zip password is: $ZipPassword"
Start-Executable -Command @("$7zip", "a", "-tzip", "$zipPath", `
"$tmpName", "-p$ZipPassword", "-mx1")
Remove-Item -Force $tmpName
}
Pop-Location
if (Test-Path $ImagePath) {
throw "File $ImagePath already exists. The image has been created at $tmpName."
}
Expand Down Expand Up @@ -1284,6 +1285,7 @@ function New-WindowsOnlineImage {
-CompressQcow2 $windowsImageConfig.compress_qcow2
Remove-Item -Force $virtualDiskPath
}

if ($windowsImageConfig.compression_format) {
Compress-Image -VirtualDiskPath $uncompressedImagePath `
-ImagePath $windowsImageConfig['image_path'] `
Expand Down Expand Up @@ -1417,10 +1419,6 @@ function New-WindowsCloudImage {
Move-Item -Force $vhdPath $windowsImageConfig.image_path
}

if ($windowsImageConfig.zip_password) {
New-ProtectedZip -ZipPassword $windowsImageConfig.zip_password `
-virtualDiskPath $windowsImageConfig.image_path
}
Write-Log "Cloud image generation finished."
}

Expand Down Expand Up @@ -1552,9 +1550,6 @@ function New-WindowsFromGoldenImage {
Convert-VirtualDisk -vhdPath $windowsImageConfig.gold_image_path -outPath $uncompressedImagePath `
-format "RAW"
Remove-Item -Force $windowsImageConfig.gold_image_path
if (!($windowsImageConfig.compression_format -match ".tar.gz")) {
$windowsImageConfig.compression_format = ".tar.gz" + $windowsImageConfig.compression_format
}
}
if ($windowsImageConfig.image_type -eq "KVM") {
$uncompressedImagePath = $barePath + ".qcow2"
Expand Down

0 comments on commit 346bd2c

Please sign in to comment.