diff --git a/Tasks/ServiceFabricDeploy/Create-DiffPackage.psm1 b/Tasks/ServiceFabricDeploy/Create-DiffPackage.psm1 index 9cced8dcf8ac..7dbb5a6e8b18 100644 --- a/Tasks/ServiceFabricDeploy/Create-DiffPackage.psm1 +++ b/Tasks/ServiceFabricDeploy/Create-DiffPackage.psm1 @@ -148,6 +148,12 @@ function Copy-DiffPackage $localPkgPath += ".zip" $diffPkgPath += ".zip" } + # The Code package for containerized service does not exist, but we want to continue the deployment + elseif (!(Test-Path -Path $localPkgPath)) + { + Write-Host (Get-VstsLocString -Key DIFFPKG_PackageDoesNotExist -ArgumentList @($localPkgPath)) + continue + } Write-Host (Get-VstsLocString -Key DIFFPKG_CopyingToDiffPackge -ArgumentList @($localPkgPath, $diffPkgPath)) # Copy the package on this level to diff package which is considered to be Leaf diff --git a/Tasks/ServiceFabricDeploy/Tests/CreateDiffPkg.ps1 b/Tasks/ServiceFabricDeploy/Tests/CreateDiffPkg.ps1 index 9d5cffab6562..1b30a70275ee 100644 --- a/Tasks/ServiceFabricDeploy/Tests/CreateDiffPkg.ps1 +++ b/Tasks/ServiceFabricDeploy/Tests/CreateDiffPkg.ps1 @@ -24,12 +24,20 @@ $codePkg2 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless2Pkg\Code" $codeDiffPkg2 = $diffPackagePath + "\Stateless2Pkg\Code" $serviceManifestPath3 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless3Pkg\ServiceManifest.xml" $serviceManifestDiffPath3 = $diffPackagePath + "\Stateless3Pkg\ServiceManifest.xml" -$codePkg3 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless3Pkg\Code.zip" -$codeDiffPkg3 = $diffPackagePath + "\Stateless3Pkg\Code.zip" +$codeZippedPkg3 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless3Pkg\Code.zip" +$codeZippedDiffPkg3 = $diffPackagePath + "\Stateless3Pkg\Code.zip" $serviceManifestPath4 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless4Pkg\ServiceManifest.xml" $serviceManifestDiffPath4 = $diffPackagePath + "\Stateless4Pkg\ServiceManifest.xml" -$codePkg4 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless4Pkg\Code.zip" -$codeDiffPkg4 = $diffPackagePath + "\Stateless4Pkg\Code.zip" +$codeZippedPkg4 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless4Pkg\Code.zip" +$codeZippedDiffPkg4 = $diffPackagePath + "\Stateless4Pkg\Code.zip" +$configPkg4 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless4Pkg\Config" +$configZippedPkg4 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless4Pkg\Config.zip" +$configDiffPkg4 = $diffPackagePath + "\Stateless4Pkg\Config" +$configZippedDiffPkg4 = $diffPackagePath + "\Stateless4Pkg\Config.zip" +$dataPkg4 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless4Pkg\Data" +$dataZippedPkg4 = "$PSScriptRoot\data\DiffPkgAssets\AppPkg\Stateless4Pkg\Data.zip" +$dataDiffPkg4 = $diffPackagePath + "\Stateless4Pkg\Data" +$dataZippedDiffPkg4 = $diffPackagePath + "\Stateless4Pkg\Data.zip" # Setup input arguments Register-Mock Get-VstsInput { $publishProfilePath } -- -Name publishProfilePath @@ -118,11 +126,12 @@ $serviceManifest4 = '' + '' + '' + '' + - '' + - '' + + '' + '' + + '' + '' +Register-Mock Test-ServiceFabricApplicationPackage {$true} -- -ApplicationPackagePath $applicationPackagePath Register-Mock Get-ServiceFabricServiceType {$serviceTypes} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion Register-Mock Get-ServiceFabricServiceManifest {$serviceManifest1} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion -ServiceManifestName "Stateless1Pkg" Register-Mock Get-ServiceFabricServiceManifest {$serviceManifest2} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion -ServiceManifestName "Stateless2Pkg" @@ -130,8 +139,14 @@ Register-Mock Get-ServiceFabricServiceManifest {$serviceManifest3} -- -Applicati Register-Mock Get-ServiceFabricServiceManifest {$serviceManifest4} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion -ServiceManifestName "Stateless4Pkg" Register-Mock Copy-Item {} $appManifestPath $appManifestDiffPath -Force -Register-Mock Test-Path { $true } -Path $codePkg3 -Register-Mock Test-Path { $true } -Path $codePkg4 +Register-Mock Test-Path { $true } -Path $codePkg1 +Register-Mock Test-Path { $true } -Path $codePkg2 +Register-Mock Test-Path { $true } -Path $codeZippedPkg3 +Register-Mock Test-Path { $true } -Path $codeZippedPkg4 +Register-Mock Test-Path { $false } -Path $configZippedPkg4 +Register-Mock Test-Path { $true } -Path $configPkg4 +Register-Mock Test-Path { $false } -Path $dataZippedPkg4 +Register-Mock Test-Path { $false } -Path $dataPkg4 Microsoft.PowerShell.Core\Import-Module "$PSScriptRoot\..\Create-DiffPackage.psm1" @@ -147,6 +162,10 @@ Assert-WasCalled Copy-Item $serviceManifestPath3 $serviceManifestDiffPath3 -Forc Assert-WasCalled Copy-Item $serviceManifestPath4 $serviceManifestDiffPath4 -Force Assert-WasCalled Copy-Item $codePkg1 $codeDiffPkg1 -Recurse -Times 0 Assert-WasCalled Copy-Item $codePkg2 $codeDiffPkg2 -Recurse -Assert-WasCalled Copy-Item $codePkg3 $codeDiffPkg3 -Recurse -Times 0 -Assert-WasCalled Copy-Item $codePkg4 $codeDiffPkg4 -Recurse +Assert-WasCalled Copy-Item $codeZippedPkg3 $codeZippedDiffPkg3 -Recurse -Times 0 +Assert-WasCalled Copy-Item $codeZippedPkg4 $codeZippedDiffPkg4 -Recurse +Assert-WasCalled Copy-Item $configZippedPkg4 $configZippedDiffPkg4 -Recurse -Times 0 +Assert-WasCalled Copy-Item $configPkg4 $configDiffPkg4 -Recurse +Assert-WasCalled Copy-Item $dataZippedPkg4 $dataZippedDiffPkg4 -Recurse -Times 0 +Assert-WasCalled Copy-Item $dataPkg4 $dataDiffPkg4 -Recurse -Times 0 Assert-WasCalled Publish-NewServiceFabricApplication -Arguments $publishArgs \ No newline at end of file diff --git a/Tasks/ServiceFabricDeploy/Tests/data/DiffPkgAssets/AppPkg/Stateless4Pkg/ServiceManifest.xml b/Tasks/ServiceFabricDeploy/Tests/data/DiffPkgAssets/AppPkg/Stateless4Pkg/ServiceManifest.xml index 3c184bf21bed..52bea6d72cb3 100644 --- a/Tasks/ServiceFabricDeploy/Tests/data/DiffPkgAssets/AppPkg/Stateless4Pkg/ServiceManifest.xml +++ b/Tasks/ServiceFabricDeploy/Tests/data/DiffPkgAssets/AppPkg/Stateless4Pkg/ServiceManifest.xml @@ -2,7 +2,7 @@ - - + + \ No newline at end of file diff --git a/Tasks/ServiceFabricDeploy/deploy.ps1 b/Tasks/ServiceFabricDeploy/deploy.ps1 index 32d805f2e75f..c57339597584 100644 --- a/Tasks/ServiceFabricDeploy/deploy.ps1 +++ b/Tasks/ServiceFabricDeploy/deploy.ps1 @@ -102,8 +102,22 @@ try { $useDiffPackage = [System.Boolean]::Parse((Get-VstsInput -Name useDiffPackage)) if ($useDiffPackage) { - Import-Module "$PSScriptRoot\Create-DiffPackage.psm1" - $diffPackagePath = Create-DiffPackage -ApplicationName $applicationName -ApplicationPackagePath $applicationPackagePath -ConnectedServiceEndpoint $connectedServiceEndpoint -ClusterConnectionParameters $clusterConnectionParameters + $isPackageValid = $true + + if (!$skipValidation) + { + $isPackageValid = Test-ServiceFabricApplicationPackage -ApplicationPackagePath $applicationPackagePath + } + + if ($isPackageValid) + { + Import-Module "$PSScriptRoot\Create-DiffPackage.psm1" + $diffPackagePath = Create-DiffPackage -ApplicationName $applicationName -ApplicationPackagePath $applicationPackagePath -ConnectedServiceEndpoint $connectedServiceEndpoint -ClusterConnectionParameters $clusterConnectionParameters + } + else + { + Write-Warning (Get-VstsLocString -Key DIFFPKG_TestAppPkgFailed) + } } $publishParameters = @{ 'ApplicationPackagePath' = if (!$diffPackagePath) {$applicationPackagePath} else {[string]$diffPackagePath} diff --git a/Tasks/ServiceFabricDeploy/task.json b/Tasks/ServiceFabricDeploy/task.json index b891ec2c5c3b..a86a0b77383a 100644 --- a/Tasks/ServiceFabricDeploy/task.json +++ b/Tasks/ServiceFabricDeploy/task.json @@ -398,9 +398,11 @@ "DIFFPKG_CopyingToDiffPackge": "Copying {0} from full application package to {1} in diff package...", "DIFFPKG_CreatingDiffPackage": "Trying to create diff package...", "DIFFPKG_CreatingDiffPackageForService": "Creating diff package for service: {0}, clusterServiceManifest.Version: {1}, localServiceManifest.Version: {2}", - "DIFFPKG_NoServicesRunning": "No services of application {0} are running in the cluster {1}. Applying full application packge to do the deployment now...", + "DIFFPKG_NoServicesRunning": "No services of application {0} are running in the cluster {1}. Applying full application package to do the deployment now...", + "DIFFPKG_PackageDoesNotExist": "The package {0} does not exist in the full application package. Skip copying it to diff package.", "DIFFPKG_ServiceDoesNotExist": "The service {0} of application {1} to be upgraded by using diff package does not exist in the cluster {2}. Copying it to diff package now...", "DIFFPKG_ServiceIsNotChanged": "The service {0} of application {1} to be upgraded by using diff package has the same version {2} running in the cluster {3}. Skip upgrading it.", + "DIFFPKG_TestAppPkgFailed": "Testing application package failed before creating diff package. Skip creating diff package.", "ItemSearchMoreThanOneFound": "Found more than one item with search pattern {0}. There can be only one.", "ItemSearchNoFilesFound": "No items were found with search pattern {0}.", "SearchingForPath": "Searching for path: {0}", diff --git a/Tasks/ServiceFabricDeploy/task.loc.json b/Tasks/ServiceFabricDeploy/task.loc.json index cf7a0a834291..525ef7dfd1de 100644 --- a/Tasks/ServiceFabricDeploy/task.loc.json +++ b/Tasks/ServiceFabricDeploy/task.loc.json @@ -403,8 +403,10 @@ "DIFFPKG_CreatingDiffPackage": "ms-resource:loc.messages.DIFFPKG_CreatingDiffPackage", "DIFFPKG_CreatingDiffPackageForService": "ms-resource:loc.messages.DIFFPKG_CreatingDiffPackageForService", "DIFFPKG_NoServicesRunning": "ms-resource:loc.messages.DIFFPKG_NoServicesRunning", + "DIFFPKG_PackageDoesNotExist": "ms-resource:loc.messages.DIFFPKG_PackageDoesNotExist", "DIFFPKG_ServiceDoesNotExist": "ms-resource:loc.messages.DIFFPKG_ServiceDoesNotExist", "DIFFPKG_ServiceIsNotChanged": "ms-resource:loc.messages.DIFFPKG_ServiceIsNotChanged", + "DIFFPKG_TestAppPkgFailed": "ms-resource:loc.messages.DIFFPKG_TestAppPkgFailed", "ItemSearchMoreThanOneFound": "ms-resource:loc.messages.ItemSearchMoreThanOneFound", "ItemSearchNoFilesFound": "ms-resource:loc.messages.ItemSearchNoFilesFound", "SearchingForPath": "ms-resource:loc.messages.SearchingForPath",