Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

Added Powershell scripts for mass creating / deleting test instances #63

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
60 changes: 60 additions & 0 deletions CreateNewInstances.ps1
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions DeleteInstances.ps1
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 22 additions & 0 deletions UploadPackage.ps1
Original file line number Diff line number Diff line change
@@ -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