From 385c5055802c4b0c5cdc040e08668e850e26656a Mon Sep 17 00:00:00 2001 From: Max Knor Date: Wed, 2 May 2018 18:56:45 +0200 Subject: [PATCH] New scripts for mass creating / deleting instances --- CreateNewInstances.ps1 | 60 ++++++++++++++++++++++++++++++++++++++++++ DeleteInstances.ps1 | 28 ++++++++++++++++++++ UploadPackage.ps1 | 22 ++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 CreateNewInstances.ps1 create mode 100644 DeleteInstances.ps1 create mode 100644 UploadPackage.ps1 diff --git a/CreateNewInstances.ps1 b/CreateNewInstances.ps1 new file mode 100644 index 0000000..a4f6997 --- /dev/null +++ b/CreateNewInstances.ps1 @@ -0,0 +1,60 @@ +# .\CreateNewInstances.ps1 -pemFile .\mknor-vault-Test.pem ` +# -sfClusterUrl https://mk-local.westeurope.cloudapp.azure.com:19080 ` +# -sfAppServiceType TestSiteType ` +# -sfAppUrl fabric:/testweb ` +# -sfAppServiceName Web ` +# -instanceCount 2 +Param( + [Parameter(Mandatory = $true)][string]$sfClusterUrl, + [Parameter(Mandatory = $true)][string]$pemFile, + [Parameter(Mandatory = $true)][string]$sfAppUrl, + [Parameter(Mandatory = $true)][string]$sfAppServiceName, + [Parameter(Mandatory = $true)][string]$sfAppServiceType, + [string ]$sfAppVersion = "1.0.0", + [string]$pathPrefix = "/web", + [int]$instanceCount = 1, + [int]$instanceStartNumber = 0 +) + +# Connect to the cluster +Write-Host "Connecting to cluster $($sfClusterUrl)" +sfctl cluster select --endpoint $sfClusterUrl --pem $pemFile --no-verify + +$top = $instanceStartNumber + $instanceCount; + +for ($i = $instanceStartNumber; $i -lt $top; $i++) { + $instanceUrl = "$($sfAppUrl)$($i)" + + Write-Host "Deploying application $($instanceUrl) - type $sfAppServiceType ($sfAppVersion)" + + $path = $pathPrefix + "$($i)" + + sfctl application create --app-name $instanceUrl --app-type $sfAppServiceType --app-version $sfAppVersion + + $json = '{\"Kind\": \"String\",\"Data\": \"PathPrefixStrip: ' + $path + '\"}' + + $sfAppId = "$($sfAppUrl)$($i)/$($sfAppServiceName)" -replace "fabric:/", "" + + Write-Host "Setting property ""traefik.frontend.rule.rule$($i)"" on $($sfAppId)" + + sfctl property put --name-id $sfAppId ` + --property-name "traefik.frontend.rule.rule$($i)" ` + --value $json + + + $json = '{\"Kind\": \"String\",\"Data\": \"true\"}' + + $sfAppId = "$($sfAppUrl)$($i)/$($sfAppServiceName)" -replace "fabric:/", "" + + Write-Host "Setting property ""traefik.expose"" on $($sfAppId)" + + sfctl property put --name-id $sfAppId ` + --property-name "traefik.expose" ` + --value $json +} + +return; + +function replaceText($file, $find, $replace) { + (Get-Content $file).replace($find, $replace) | Set-Content $file +} \ No newline at end of file diff --git a/DeleteInstances.ps1 b/DeleteInstances.ps1 new file mode 100644 index 0000000..cfc0feb --- /dev/null +++ b/DeleteInstances.ps1 @@ -0,0 +1,28 @@ +# .\DeleteInstances.ps1 -pemFile .\mknor-vault-Test.pem ` +# -sfClusterUrl https://mk-local.westeurope.cloudapp.azure.com:19080 ` +# -sfAppServiceType TestSiteType +Param( + [Parameter(Mandatory = $true)][string]$sfClusterUrl, + [Parameter(Mandatory = $true)][string]$pemFile, + [Parameter(Mandatory = $true)][string]$sfAppServiceType +) + +# Connect to the cluster +Write-Host "Connecting to cluster $($sfClusterUrl)" +sfctl cluster select --endpoint $sfClusterUrl --pem $pemFile --no-verify + +$filter = "'" + $sfAppServiceType + "'" + +$apps = sfctl application list --query items[?typeName==$filter].name +$appsArray = (ConvertFrom-Json ([string]::Concat($apps))) + +foreach ($a in $appsArray) { + $appId = $a -replace "fabric:/","" + sfctl application delete --application-id $appId +} + +return; + +function replaceText($file, $find, $replace) { + (Get-Content $file).replace($find, $replace) | Set-Content $file +} \ No newline at end of file diff --git a/UploadPackage.ps1 b/UploadPackage.ps1 new file mode 100644 index 0000000..5187dad --- /dev/null +++ b/UploadPackage.ps1 @@ -0,0 +1,22 @@ +# .\UploadPackage.ps1 -pemFile .\mknor-vault-Test.pem ` +# -sfClusterUrl https://mk-local.westeurope.cloudapp.azure.com:19080 ` +# -applicationPackageRoot .\testsite\TestSite\pkg\Debug +Param( + [Parameter(Mandatory = $true)][string]$sfClusterUrl, + [Parameter(Mandatory = $true)][string]$pemFile, + [Parameter(Mandatory = $true)][string]$applicationPackageRoot, +) + +# Connect to the cluster +Write-Host "Connecting to cluster $($sfClusterUrl)" +sfctl cluster select --endpoint $sfClusterUrl --pem $pemFile --no-verify + +Write-Host "Upload application package from $($applicationPackageRoot)" +sfctl application upload --path $applicationPackageRoot --show-progress + +# Provision the application package +# The actual package name is the last part of the $applicationPackageRoot path +$packageName = (Convert-Path $applicationPackageRoot) | Split-Path -Leaf + +Write-Host "Provisioning package name $($packageName)" +sfctl application provision --application-type-build-path $packageName