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.

167 lines
7.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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=$false,
  15. [parameter(Mandatory=$false)][bool]$enableTrace=$false,
  16. [parameter(Mandatory=$false)][string][ValidateSet('Always','IfNotPresent','Never', IgnoreCase=$false)]$imagePullPolicy="Always",
  17. [parameter(Mandatory=$false)][string][ValidateSet('prod','staging','none','custom', IgnoreCase=$false)]$sslSupport = "none",
  18. [parameter(Mandatory=$false)][string]$tlsSecretName = "eshop-tls-custom",
  19. [parameter(Mandatory=$false)][string]$chartsToDeploy="*",
  20. [parameter(Mandatory=$false)][string]$ingressMeshAnnotationsFile="ingress_values_linkerd.yaml"
  21. )
  22. function Install-Chart {
  23. Param([string]$chart,[string]$initialOptions, [bool]$customRegistry)
  24. $options=$initialOptions
  25. if ($sslEnabled) {
  26. $options = "$options --set ingress.tls[0].secretName=$tlsSecretName --set ingress.tls[0].hosts={$dns}"
  27. if ($sslSupport -ne "custom") {
  28. $options = "$options --set inf.tls.issuer=$sslIssuer"
  29. }
  30. }
  31. if ($customRegistry) {
  32. $options = "$options --set inf.registry.server=$registry --set inf.registry.login=$dockerUser --set inf.registry.pwd=$dockerPassword --set inf.registry.secretName=eshop-docker-scret"
  33. }
  34. if ($chart -ne "eshop-common" -or $customRegistry) { # eshop-common is ignored when no secret must be deployed
  35. $command = "install $appName-$chart $options $chart"
  36. Write-Host "Helm Command: helm $command" -ForegroundColor Gray
  37. Invoke-Expression 'cmd /c "helm $command"'
  38. }
  39. }
  40. $dns = $externalDns
  41. $sslEnabled=$false
  42. $sslIssuer=""
  43. if ($sslSupport -eq "staging") {
  44. $sslEnabled=$true
  45. $tlsSecretName="eshop-letsencrypt-staging"
  46. $sslIssuer="letsencrypt-staging"
  47. }
  48. elseif ($sslSupport -eq "prod") {
  49. $sslEnabled=$true
  50. $tlsSecretName="eshop-letsencrypt-prod"
  51. $sslIssuer="letsencrypt-prod"
  52. }
  53. elseif ($sslSupport -eq "custom") {
  54. $sslEnabled=$true
  55. }
  56. $ingressValuesFile="ingress_values.yaml"
  57. if ($useLocalk8s -eq $true) {
  58. $ingressValuesFile="ingress_values_dockerk8s.yaml"
  59. $dns="localhost"
  60. }
  61. if ($externalDns -eq "aks") {
  62. if ([string]::IsNullOrEmpty($aksName) -or [string]::IsNullOrEmpty($aksRg)) {
  63. Write-Host "Error: When using -dns aks, MUST set -aksName and -aksRg too." -ForegroundColor Red
  64. exit 1
  65. }
  66. Write-Host "Getting DNS of AKS of AKS $aksName (in resource group $aksRg)..." -ForegroundColor Green
  67. $dns = $(az aks show -n $aksName -g $aksRg --query addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName)
  68. if ([string]::IsNullOrEmpty($dns)) {
  69. 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
  70. exit 1
  71. }
  72. $dns = $dns -replace '[\"]'
  73. Write-Host "DNS base found is $dns. Will use $appName.$dns for the app!" -ForegroundColor Green
  74. $dns = "$appName.$dns"
  75. }
  76. # Initialization & check commands
  77. if ([string]::IsNullOrEmpty($dns)) {
  78. Write-Host "No DNS specified. Ingress resources will be bound to public ip" -ForegroundColor Yellow
  79. if ($sslEnabled) {
  80. Write-Host "Can't bound SSL to public IP. DNS is mandatory when using TLS" -ForegroundColor Red
  81. exit 1
  82. }
  83. }
  84. if ($useLocalk8s -and $sslEnabled) {
  85. Write-Host "SSL can'be enabled on local K8s." -ForegroundColor Red
  86. exit 1
  87. }
  88. if ($clean) {
  89. $listOfReleases=$(helm ls --filter eshop -q)
  90. if ([string]::IsNullOrEmpty($listOfReleases)) {
  91. Write-Host "No previous releases found!" -ForegroundColor Green
  92. }else{
  93. Write-Host "Previous releases found" -ForegroundColor Green
  94. Write-Host "Cleaning previous helm releases..." -ForegroundColor Green
  95. helm uninstall $listOfReleases
  96. Write-Host "Previous releases deleted" -ForegroundColor Green
  97. }
  98. }
  99. $useCustomRegistry=$false
  100. if (-not [string]::IsNullOrEmpty($registry)) {
  101. $useCustomRegistry=$true
  102. if ([string]::IsNullOrEmpty($dockerUser) -or [string]::IsNullOrEmpty($dockerPassword)) {
  103. Write-Host "Error: Must use -dockerUser AND -dockerPassword if specifying custom registry" -ForegroundColor Red
  104. exit 1
  105. }
  106. }
  107. Write-Host "Begin eShopOnContainers installation using Helm" -ForegroundColor Green
  108. $infras = ("sql-data", "nosql-data", "rabbitmq", "keystore-data", "basket-data")
  109. $traceTools = ("zipkin")
  110. $charts = ("eshop-common", "basket-api","catalog-api", "identity-api", "mobileshoppingagg","ordering-api","ordering-backgroundtasks","ordering-signalrhub", "payment-api", "webmvc", "webshoppingagg", "webspa", "webstatus", "webhooks-api", "webhooks-web")
  111. $gateways = ("apigwms", "apigwws")
  112. if ($deployInfrastructure) {
  113. foreach ($infra in $infras) {
  114. Write-Host "Installing infrastructure: $infra" -ForegroundColor Green
  115. helm install "$appName-$infra" --values app.yaml --values inf.yaml --values $ingressValuesFile --set app.name=$appName --set inf.k8s.dns=$dns --set "ingress.hosts={$dns}" $infra
  116. }
  117. }
  118. else {
  119. Write-Host "eShopOnContainers infrastructure (bbdd, redis, ...) charts aren't installed (-deployCharts is false)" -ForegroundColor Yellow
  120. }
  121. if ($enableTrace) {
  122. Write-Host "Enabling traces : $traceTools" -ForegroundColor Green
  123. #helm install "$appName-$traceTools" --values app.yaml --values inf.yaml --values $ingressValuesFile --set app.name=$appName --set inf.k8s.dns=$dns --set "ingress.hosts={$dns}" $traceTools
  124. Install-Chart $traceTools "-f app.yaml --values inf.yaml -f $ingressValuesFile -f $ingressMeshAnnotationsFile --set app.name=$appName --set inf.k8s.dns=$dns --set ingress.hosts={$dns} --set image.tag=latest --set image.pullPolicy=$imagePullPolicy --set inf.tls.enabled=$sslEnabled --set inf.mesh.enabled=$false --set inf.k8s.local=$useLocalk8s" $false
  125. }
  126. else {
  127. Write-Host "OpenTelemetry Trace is not enabled. Charts isn't installed (-enableTrace is false)" -ForegroundColor Yellow
  128. }
  129. if ($deployCharts) {
  130. foreach ($chart in $charts) {
  131. if ($chartsToDeploy -eq "*" -or $chartsToDeploy.Contains($chart)) {
  132. Write-Host "Installing: $chart" -ForegroundColor Green
  133. Install-Chart $chart "-f app.yaml --values inf.yaml -f $ingressValuesFile -f $ingressMeshAnnotationsFile --set app.name=$appName --set inf.k8s.dns=$dns --set ingress.hosts={$dns} --set image.tag=$imageTag --set image.pullPolicy=$imagePullPolicy --set inf.tls.enabled=$sslEnabled --set inf.mesh.enabled=$useMesh --set inf.k8s.local=$useLocalk8s" $useCustomRegistry
  134. }
  135. }
  136. foreach ($chart in $gateways) {
  137. if ($chartsToDeploy -eq "*" -or $chartsToDeploy.Contains($chart)) {
  138. Write-Host "Installing Api Gateway Chart: $chart" -ForegroundColor Green
  139. Install-Chart $chart "-f app.yaml -f inf.yaml -f $ingressValuesFile --set app.name=$appName --set inf.k8s.dns=$dns --set image.pullPolicy=$imagePullPolicy --set inf.mesh.enabled=$useMesh --set ingress.hosts={$dns} --set inf.tls.enabled=$sslEnabled" $false
  140. }
  141. }
  142. }
  143. else {
  144. Write-Host "eShopOnContainers non-infrastructure charts aren't installed (-deployCharts is false)" -ForegroundColor Yellow
  145. }
  146. Write-Host "helm charts installed." -ForegroundColor Green