Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't try to copy code/config/data folder if it does not exist #6380

Merged
merged 7 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Tasks/ServiceFabricDeploy/Create-DiffPackage.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ignores the scenario when package does not exist when service is non-containerized. Do we want to not throw in such case?
This should also be fine as we do a validation downstream using Test-ServiceFabricApplicationPackage - which anyways would fail
However, would it be better to move Test-ServiceFabricApplicationPackage before doing diff'ing as well. This will ensure that we do have a valid package before diffing - giving us more confidence that diffing has not invalidated the package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bishal-pdMSFT Added Test-ServiceFabricApplicationPackage before creating diff package in deploy.ps1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bishal-pdMSFT Do you have any other concern on this PR?

{
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
Expand Down
39 changes: 29 additions & 10 deletions Tasks/ServiceFabricDeploy/Tests/CreateDiffPkg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -118,20 +126,27 @@ $serviceManifest4 = '<ServiceManifest Name="Stateless4Pkg" Version="1.0.0">' +
'<ServiceTypes>' +
'<StatelessServiceType ServiceTypeName="Stateless4Type" />' +
'</ServiceTypes>' +
'<CodePackage Name="Code" Version="1.0.0">' +
'</CodePackage>' +
'<CodePackage Name="Code" Version="1.0.0" />' +
'<ConfigPackage Name="Config" Version="1.0.0" />' +
'<DataPackage Name="Data" Version="1.0.0" />' +
'</ServiceManifest>'

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"
Register-Mock Get-ServiceFabricServiceManifest {$serviceManifest3} -- -ApplicationTypeName $applicationTypeName -ApplicationTypeVersion $applicationTypeVersion -ServiceManifestName "Stateless3Pkg"
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"

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ServiceTypes>
<StatelessServiceType ServiceTypeName="Stateless4Type" />
</ServiceTypes>
<CodePackage Name="Code" Version="2.0.0">
</CodePackage>
<CodePackage Name="Code" Version="2.0.0" />
<ConfigPackage Name="Config" Version="2.0.0" />
<DataPackage Name="Data" Version="2.0.0" />
</ServiceManifest>
18 changes: 16 additions & 2 deletions Tasks/ServiceFabricDeploy/deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 3 additions & 1 deletion Tasks/ServiceFabricDeploy/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
2 changes: 2 additions & 0 deletions Tasks/ServiceFabricDeploy/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down