Powershell Deploy Service Fabric Application To Local Cluster

以前写过一篇用 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.'

相关文章
相关标签/搜索