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

Use agent's temp dir if available #6673

Merged
merged 7 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 3 deletions Tasks/ServiceFabricDeploy/Create-DiffPackage.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Create-DiffPackage
Return
}

$diffPackagePath = Join-Path $env:Temp "DiffPackage"
$diffPackagePath = Join-Path (Get-TempDirectoryPath) "DiffPackage"
if (Test-Path -PathType Container -Path $diffPackagePath)
{
Remove-Item -Path $diffPackagePath -Recurse -Force
Expand Down Expand Up @@ -82,15 +82,15 @@ function Create-DiffPackage
$diffServicePkgPath = [System.IO.Path]::Combine($diffPackagePath, $localServiceManifestName)
$clusterServiceManifest = $clusterServiceManifestByName[$localServiceManifestName].ServiceManifest

# If there's no matching manifest from the cluster it means this is a newly added service that doesn't exist yet on the cluster.
# If there's no matching manifest from the cluster it means this is a newly added service that doesn't exist yet on the cluster.
if (!$clusterServiceManifest)
{
# Copy this service and all the children
Write-Host (Get-VstsLocString -Key DIFFPKG_ServiceDoesNotExist -ArgumentList @($localServiceManifestName, $ApplicationName, $ConnectedServiceEndpoint.Url))
Copy-Item $localServicePkgPath $diffServicePkgPath -Recurse
continue
}

# If the Version of the Service is not changed, don't include the service in the diff package
if ($clusterServiceManifest.Version -eq $localServiceManifestVersion)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
{
if((Get-Item $ApplicationPackagePath).Extension -eq ".sfpkg")
{
$AppPkgPathToUse=[io.path]::combine($env:Temp, (Get-Item $ApplicationPackagePath).BaseName)
$AppPkgPathToUse = [io.path]::combine((Get-TempDirectoryPath), (Get-Item $ApplicationPackagePath).BaseName)
Expand-ToFolder $ApplicationPackagePath $AppPkgPathToUse
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function Publish-UpgradedServiceFabricApplication
{
if((Get-Item $ApplicationPackagePath).Extension -eq ".sfpkg")
{
$AppPkgPathToUse=[io.path]::combine($env:Temp, (Get-Item $ApplicationPackagePath).BaseName)
$AppPkgPathToUse = [io.path]::combine((Get-TempDirectoryPath), (Get-Item $ApplicationPackagePath).BaseName)
Expand-ToFolder $ApplicationPackagePath $AppPkgPathToUse
}
else
Expand Down
73 changes: 46 additions & 27 deletions Tasks/ServiceFabricDeploy/ServiceFabricSDK/Utilities.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function Expand-ToFolder
{
<#
.SYNOPSIS
.SYNOPSIS
Unzips the zip file to the specified folder.

.PARAMETER From
Expand All @@ -16,16 +16,16 @@
(
[String]
$File,

[String]
$Destination
)

if (!(Test-Path $File))
{
return
}
}

if (Test-Path $Destination)
{
Remove-Item -Path $Destination -Recurse -ErrorAction Stop | Out-Null
Expand All @@ -35,25 +35,25 @@


Write-Verbose -Message (Get-VstsLocString -Key SFSDK_UnzipPackage -ArgumentList @($File, $Destination))
try
try
{
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory("$File", "$Destination")
}
catch
{
Write-Error -Message (Get-VstsLocString -Key SFSDK_UnexpectedError -ArgumentList $_.Exception.Message)
}
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory("$File", "$Destination")
}
catch
{
Write-Error -Message (Get-VstsLocString -Key SFSDK_UnexpectedError -ArgumentList $_.Exception.Message)
}
}

function Get-NamesFromApplicationManifest
{
<#
.SYNOPSIS
.SYNOPSIS
Returns an object containing common information from the application manifest.

.PARAMETER ApplicationManifestPath
Path to the application manifest file.
Path to the application manifest file.
#>

[CmdletBinding()]
Expand All @@ -68,7 +68,7 @@ function Get-NamesFromApplicationManifest
throw (Get-VstsLocString -Key PathDoesNotExist -ArgumentList $ApplicationManifestPath)
}


$appXml = [xml] (Get-Content $ApplicationManifestPath)
if (!$appXml)
{
Expand All @@ -83,15 +83,15 @@ function Get-NamesFromApplicationManifest
FabricNamespace = $FabricNamespace;
ApplicationTypeName = $appMan.ApplicationTypeName;
ApplicationTypeVersion = $appMan.ApplicationTypeVersion;
}
}

Write-Output (New-Object psobject -Property $h)
}

function Get-ImageStoreConnectionStringFromClusterManifest
{
<#
.SYNOPSIS
.SYNOPSIS
Returns the value of the image store connection string from the cluster manifest.

.PARAMETER ClusterManifest
Expand All @@ -113,7 +113,7 @@ function Get-ImageStoreConnectionStringFromClusterManifest
function Get-ApplicationNameFromApplicationParameterFile
{
<#
.SYNOPSIS
.SYNOPSIS
Returns Application Name from ApplicationParameter xml file.

.PARAMETER ApplicationParameterFilePath
Expand All @@ -126,7 +126,7 @@ function Get-ApplicationNameFromApplicationParameterFile
[String]
$ApplicationParameterFilePath
)

if (!(Test-Path $ApplicationParameterFilePath))
{
$errMsg = (Get-VstsLocString -Key PathDoesNotExist -ArgumentList $ApplicationParameterFilePath)
Expand All @@ -140,7 +140,7 @@ function Get-ApplicationNameFromApplicationParameterFile
function Get-ApplicationParametersFromApplicationParameterFile
{
<#
.SYNOPSIS
.SYNOPSIS
Reads ApplicationParameter xml file and returns HashTable containing ApplicationParameters.

.PARAMETER ApplicationParameterFilePath
Expand All @@ -153,12 +153,12 @@ function Get-ApplicationParametersFromApplicationParameterFile
[String]
$ApplicationParameterFilePath
)

if (!(Test-Path $ApplicationParameterFilePath))
{
throw (Get-VstsLocString -Key PathDoesNotExist -ArgumentList $ApplicationParameterFilePath)
}

$ParametersXml = ([xml] (Get-Content $ApplicationParameterFilePath)).Application.Parameters

$hash = @{}
Expand All @@ -174,26 +174,26 @@ function Get-ApplicationParametersFromApplicationParameterFile
function Merge-HashTables
{
<#
.SYNOPSIS
.SYNOPSIS
Merges 2 hashtables. Key, value pairs form HashTableNew are preserved if any duplciates are found between HashTableOld & HashTableNew.

.PARAMETER HashTableOld
First Hashtable.

.PARAMETER HashTableNew
Second Hashtable
Second Hashtable
#>

[CmdletBinding()]
Param
(
[HashTable]
$HashTableOld,

[HashTable]
$HashTableNew
)

$keys = $HashTableOld.getenumerator() | foreach-object {$_.key}
$keys | foreach-object {
$key = $_
Expand All @@ -204,4 +204,23 @@ function Merge-HashTables
}
$HashTableNew = $HashTableOld + $HashTableNew
return $HashTableNew
}

function Get-TempDirectoryPath {
<#
.SYNOPSIS
Returns a temp directory path. Uses Agent.TempDirectory if available
#>

Param ()

$agentVersion = Get-VstsTaskVariable -Name 'agent.version'
if (!$agentVersion -or (([version]'2.115.0').CompareTo([version]$agentVersion) -ge 1))
Copy link
Contributor

Choose a reason for hiding this comment

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

This check just make sure the agent version is greater than 2.115.0 and the variable Agent.TempDirectory is defined since then. However, don't we need to check if Agent.TempDirectory is shorter than env:Temp for real?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My assumption is that agent directory will mostly be smaller than temp directory. However, better to not make any assumption. Updated code.

{
return $env:Temp
}
else
{
return Get-VstsTaskVariable -Name 'Agent.TempDirectory'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@
"loc.messages.DIFFPKG_CopyingToDiffPackge": "Copying {0} from full application package to {1} in diff package...",
"loc.messages.DIFFPKG_CreatingDiffPackage": "Trying to create diff package...",
"loc.messages.DIFFPKG_CreatingDiffPackageForService": "Creating diff package for service: {0}, clusterServiceManifest.Version: {1}, localServiceManifest.Version: {2}",
"loc.messages.DIFFPKG_NoServicesRunning": "No services of application {0} are running in the cluster {1}. Applying full application packge to do the deployment now...",
"loc.messages.DIFFPKG_NoServicesRunning": "No services of application {0} are running in the cluster {1}. Applying full application package to do the deployment now...",
"loc.messages.DIFFPKG_PackageDoesNotExist": "The package {0} does not exist in the full application package. Skip copying it to diff package.",
"loc.messages.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...",
"loc.messages.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.",
"loc.messages.DIFFPKG_TestAppPkgFailed": "Testing application package failed before creating diff package. Skip creating diff package.",
"loc.messages.ItemSearchMoreThanOneFound": "Found more than one item with search pattern {0}. There can be only one.",
"loc.messages.ItemSearchNoFilesFound": "No items were found with search pattern {0}.",
"loc.messages.SearchingForPath": "Searching for path: {0}",
Expand Down
4 changes: 3 additions & 1 deletion Tasks/ServiceFabricDeploy/Tests/CreateDiffPkg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ param()

. $PSScriptRoot\..\..\..\Tests\lib\Initialize-Test.ps1

Register-Mock Get-TempDirectoryPath { "C:\some-path" }

$publishProfilePath = "$PSScriptRoot\data\NoAuthPublishProfile.xml"
$applicationPackagePath = "$PSScriptRoot\data\DiffPkgAssets\AppPkg"
$diffPackagePath = (Get-Item $env:TEMP).FullName + "\DiffPackage"
$diffPackagePath = (Get-TempDirectoryPath) + "\DiffPackage"
$serviceConnectionName = "random connection name"
$serviceFabricSdkModulePath = "$PSScriptRoot\data\ServiceFabricSDK.ps1"
$appName = "AppName"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/ServiceFabricDeploy/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 7,
"Patch": 2
"Patch": 3
},
"demands": [
"Cmd"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/ServiceFabricDeploy/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 7,
"Patch": 2
"Patch": 3
},
"demands": [
"Cmd"
Expand Down