以前寫過一篇用 Powershell 部署 Service Fabric Application 到本地集羣的隨筆,感受過程有點複雜,此次將流程簡化,只須要將應用程序打包,加上配置文件就能夠了。shell
# 該腳本用於部署到本機集羣,如有錯誤,歡迎指正。app
# Variables
# 自行修改下面參數xml
## 應用打包後的文件夾路徑
$PackagePath="C:\pkg\Release"部署
## 應用配置文件路徑,對應 Service Fabric App/ApplicationParameters/*.xml
$ApplicationParameterFilePath = "C:\ApplicationParameters\Local.1Node.xml"it
######################### 如下內容請不要輕易修改 #########################io
$Endpoint = 'localhost:19000'
$CopyPackageTimeoutSec = 6000
$CompressPackage = $false集羣
#references
try
{
## 該腳本是安裝 Service Fabric SDK 後生成的,如下是默認路徑,如安裝時修改了安裝路徑,請自行修改。
. "C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\Utilities.ps1"
}
catch
{
Write-Warning 'Can not reference files.'
throw
}cli
# Connect to the cluster using a client certificate.
Connect-ServiceFabricCluster -ConnectionEndpoint $Endpoint打包
# Get Application Type Name, Application Name and Application Parameters.
try
{
$Names = Get-NamesFromApplicationManifest -ApplicationManifestPath "$PackagePath\ApplicationManifest.xml"
$ApplicationTypeName = $Names.ApplicationTypeName
$ApplicationTypeVersion = $Names.ApplicationTypeVersion配置
$ApplicationName = ([xml] (Get-Content $ApplicationParameterFilePath)).Application.Name
$ApplicationParameter = Get-ApplicationParametersFromApplicationParameterFile $ApplicationParameterFilePath
}
catch
{
Write-Warning 'Unable to read Application Type Name, Application Name and Application Parameters.'
throw
}
try
{
# Copy the application package to the cluster image store.
Write-Host 'Copying application to image store...'
Copy-ServiceFabricApplicationPackage -ApplicationPackagePath $PackagePath -ApplicationPackagePathInImageStore $ApplicationTypeName -TimeOutSec $CopyPackageTimeoutSec -CompressPackage:$CompressPackage
}
catch
{
Write-Error 'Copying application to image store failed.'
throw
}
try
{
# Register the application type.
Write-Host 'Registering application type...'
Register-ServiceFabricApplicationType -ApplicationPathInImageStore $ApplicationTypeName -TimeoutSec 6000
}
catch
{
Write-Error 'Registering application type failed.'
throw
}
try
{
# Remove the application package to free system resources.
Write-Host 'Removing application package from image store...'
Remove-ServiceFabricApplicationPackage -ApplicationPackagePathInImageStore $ApplicationTypeName -TimeoutSec 6000
}
catch
{
Write-Error 'Removing application package from image store failed.'
throw
}
# Create the application instance.
Write-Host 'Creating application...'
New-ServiceFabricApplication -ApplicationName $ApplicationName -ApplicationTypeName $ApplicationTypeName -ApplicationTypeVersion $ApplicationTypeVersion -ApplicationParameter $ApplicationParameter -TimeoutSec 6000
if(!$?)
{
throw "Creation of application failed."
}
Write-Host 'Create application succeeded.'