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.

94 lines
4.6 KiB

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. )
  15. $dns = $externalDns
  16. $ingressValuesFile="ingress_values.yaml"
  17. if ($useLocalk8s -eq $true) {
  18. $ingressValuesFile="ingress_values_dockerk8s.yaml"
  19. $dns="localhost"
  20. }
  21. if ($externalDns -eq "aks") {
  22. if ([string]::IsNullOrEmpty($aksName) -or [string]::IsNullOrEmpty($aksRg)) {
  23. Write-Host "Error: When using -dns aks, MUST set -aksName and -aksRg too." -ForegroundColor Red
  24. exit 1
  25. }
  26. Write-Host "Getting DNS of AKS of AKS $aksName (in resource group $aksRg)..." -ForegroundColor Green
  27. $dns = $(az aks show -n $aksName -g $aksRg --query addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName)
  28. if ([string]::IsNullOrEmpty($dns)) {
  29. 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
  30. exit 1
  31. }
  32. $dns = $dns -replace '[\"]'
  33. Write-Host "DNS base found is $dns. Will use $appName.$dns for the app!" -ForegroundColor Green
  34. $dns = "$appName.$dns"
  35. }
  36. # Initialization & check commands
  37. if ([string]::IsNullOrEmpty($dns)) {
  38. Write-Host "No DNS specified. Ingress resources will be bound to public ip" -ForegroundColor Yellow
  39. }
  40. if ($clean) {
  41. Write-Host "Cleaning previous helm releases..." -ForegroundColor Green
  42. helm delete --purge $(helm ls -q eshop)
  43. Write-Host "Previous releases deleted" -ForegroundColor Green
  44. }
  45. $useCustomRegistry=$false
  46. if (-not [string]::IsNullOrEmpty($registry)) {
  47. $useCustomRegistry=$true
  48. if ([string]::IsNullOrEmpty($dockerUser) -or [string]::IsNullOrEmpty($dockerPassword)) {
  49. Write-Host "Error: Must use -dockerUser AND -dockerPassword if specifying custom registry" -ForegroundColor Red
  50. exit 1
  51. }
  52. }
  53. Write-Host "Begin eShopOnContainers installation using Helm" -ForegroundColor Green
  54. $infras = ("sql-data", "nosql-data", "rabbitmq", "keystore-data", "basket-data")
  55. $charts = ("eshop-common", "apigwmm", "apigwms", "apigwwm", "apigwws", "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")
  56. if ($deployInfrastructure) {
  57. foreach ($infra in $infras) {
  58. Write-Host "Installing infrastructure: $infra" -ForegroundColor Green
  59. 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
  60. }
  61. }
  62. else {
  63. Write-Host "eShopOnContainers infrastructure (bbdd, redis, ...) charts aren't installed (-deployCharts is false)" -ForegroundColor Yellow
  64. }
  65. if ($deployCharts) {
  66. foreach ($chart in $charts) {
  67. Write-Host "Installing: $chart" -ForegroundColor Green
  68. if ($useCustomRegistry) {
  69. 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=Always --name="$appName-$chart" $chart
  70. }
  71. else {
  72. if ($chart -ne "eshop-common") { # eshop-common is ignored when no secret must be deployed
  73. 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=Always --name="$appName-$chart" $chart
  74. }
  75. }
  76. }
  77. }
  78. else {
  79. Write-Host "eShopOnContainers non-infrastructure charts aren't installed (-deployCharts is false)" -ForegroundColor Yellow
  80. }
  81. Write-Host "helm charts installed." -ForegroundColor Green