You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
5.6 KiB

5 years ago
  1. Param(
  2. [parameter(Mandatory=$false)][string]$registry,
  3. [parameter(Mandatory=$false)][string]$dockerUser,
  4. [parameter(Mandatory=$false)][string]$dockerPassword,
  5. [parameter(Mandatory=$false)][string]$externalDns,
  6. [parameter(Mandatory=$false)][string]$appName="eshop",
  7. [parameter(Mandatory=$false)][bool]$deployInfrastructure=$true,
  8. [parameter(Mandatory=$false)][bool]$deployCharts=$true,
  9. [parameter(Mandatory=$false)][bool]$clean=$true,
  10. [parameter(Mandatory=$false)][string]$aksName="",
  11. [parameter(Mandatory=$false)][string]$aksRg="",
  12. [parameter(Mandatory=$false)][string]$imageTag="latest",
  13. [parameter(Mandatory=$false)][bool]$useLocalk8s=$false,
  14. [parameter(Mandatory=$false)][bool]$useMesh=$true,
  15. [parameter(Mandatory=$false)][string][ValidateSet('Always','IfNotPresent','Never', IgnoreCase=$false)]$imagePullPolicy="Always",
  16. [parameter(Mandatory=$false)][string]$chartsToDeploy="*"
  17. )
  18. $dns = $externalDns
  19. $ingressValuesFile="ingress_values.yaml"
  20. if ($useLocalk8s -eq $true) {
  21. $ingressValuesFile="ingress_values_dockerk8s.yaml"
  22. $dns="localhost"
  23. }
  24. if ($externalDns -eq "aks") {
  25. if ([string]::IsNullOrEmpty($aksName) -or [string]::IsNullOrEmpty($aksRg)) {
  26. Write-Host "Error: When using -dns aks, MUST set -aksName and -aksRg too." -ForegroundColor Red
  27. exit 1
  28. }
  29. Write-Host "Getting DNS of AKS of AKS $aksName (in resource group $aksRg)..." -ForegroundColor Green
  30. $dns = $(az aks show -n $aksName -g $aksRg --query addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName)
  31. if ([string]::IsNullOrEmpty($dns)) {
  32. Write-Host "Error getting DNS of AKS $aksName (in resource group $aksRg). Please ensure AKS has httpRouting enabled AND Azure CLI is logged & in version 2.0.37 or higher" -ForegroundColor Red
  33. exit 1
  34. }
  35. $dns = $dns -replace '[\"]'
  36. Write-Host "DNS base found is $dns. Will use $appName.$dns for the app!" -ForegroundColor Green
  37. $dns = "$appName.$dns"
  38. }
  39. # Initialization & check commands
  40. if ([string]::IsNullOrEmpty($dns)) {
  41. Write-Host "No DNS specified. Ingress resources will be bound to public ip" -ForegroundColor Yellow
  42. }
  43. if ($clean) {
  44. Write-Host "Cleaning previous helm releases..." -ForegroundColor Green
  45. helm delete --purge $(helm ls -q eshop)
  46. Write-Host "Previous releases deleted" -ForegroundColor Green
  47. }
  48. $useCustomRegistry=$false
  49. if (-not [string]::IsNullOrEmpty($registry)) {
  50. $useCustomRegistry=$true
  51. if ([string]::IsNullOrEmpty($dockerUser) -or [string]::IsNullOrEmpty($dockerPassword)) {
  52. Write-Host "Error: Must use -dockerUser AND -dockerPassword if specifying custom registry" -ForegroundColor Red
  53. exit 1
  54. }
  55. }
  56. Write-Host "Begin eShopOnContainers installation using Helm" -ForegroundColor Green
  57. $infras = ("sql-data", "nosql-data", "rabbitmq", "keystore-data", "basket-data")
  58. $charts = ("eshop-common", "basket-api","catalog-api", "identity-api", "locations-api", "marketing-api", "mobileshoppingagg","ordering-api","ordering-backgroundtasks","ordering-signalrhub", "payment-api", "webmvc", "webshoppingagg", "webspa", "webstatus", "webhooks-api", "webhooks-web")
  59. $gateways = ("apigwmm", "apigwms", "apigwwm", "apigwws")
  60. if ($deployInfrastructure) {
  61. foreach ($infra in $infras) {
  62. Write-Host "Installing infrastructure: $infra" -ForegroundColor Green
  63. helm install --values app.yaml --values inf.yaml --values $ingressValuesFile --set app.name=$appName --set inf.k8s.dns=$dns --set "ingress.hosts={$dns}" --name="$appName-$infra" $infra
  64. }
  65. }
  66. else {
  67. Write-Host "eShopOnContainers infrastructure (bbdd, redis, ...) charts aren't installed (-deployCharts is false)" -ForegroundColor Yellow
  68. }
  69. if ($deployCharts) {
  70. foreach ($chart in $charts) {
  71. if ($chartsToDeploy -eq "*" -or $chartsToDeploy.Contains($chart)) {
  72. Write-Host "Installing: $chart" -ForegroundColor Green
  73. if ($useCustomRegistry) {
  74. helm install --set inf.registry.server=$registry --set inf.registry.login=$dockerUser --set inf.registry.pwd=$dockerPassword --set inf.registry.secretName=eshop-docker-scret --values app.yaml --values inf.yaml --values $ingressValuesFile --set app.name=$appName --set inf.k8s.dns=$dns --set "ingress.hosts={$dns}" --set image.tag=$imageTag --set image.pullPolicy=$imagePullPolicy --set inf.mesh.enabled=$useMesh --set inf.k8s.local=$useLocalk8s --name="$appName-$chart" $chart
  75. }
  76. else {
  77. if ($chart -ne "eshop-common") { # eshop-common is ignored when no secret must be deployed
  78. helm install --values app.yaml --values inf.yaml --values $ingressValuesFile --set app.name=$appName --set inf.k8s.dns=$dns --set "ingress.hosts={$dns}" --set image.tag=$imageTag --set image.pullPolicy=$imagePullPolicy --set inf.mesh.enabled=$useMesh --set inf.k8s.local=$useLocalk8s --name="$appName-$chart" $chart
  79. }
  80. }
  81. }
  82. }
  83. foreach ($chart in $gateways) {
  84. if ($chartsToDeploy -eq "*" -or $chartsToDeploy.Contains($chart)) {
  85. Write-Host "Installing Api Gateway Chart: $chart" -ForegroundColor Green
  86. helm install --values app.yaml --values inf.yaml --values $ingressValuesFile --set app.name=$appName --set inf.k8s.dns=$dns --set "ingress.hosts={$dns}" --set image.pullPolicy=$imagePullPolicy --set inf.mesh.enabled=$useMesh --name="$appName-$chart" $chart
  87. }
  88. }
  89. }
  90. else {
  91. Write-Host "eShopOnContainers non-infrastructure charts aren't installed (-deployCharts is false)" -ForegroundColor Yellow
  92. }
  93. Write-Host "helm charts installed." -ForegroundColor Green