2018-07-03 19:07:37 +02:00
Param (
[ parameter ( Mandatory = $false ) ] [ string ] $registry ,
[ parameter ( Mandatory = $false ) ] [ string ] $dockerUser ,
[ parameter ( Mandatory = $false ) ] [ string ] $dockerPassword ,
2019-03-13 16:44:33 +01:00
[ parameter ( Mandatory = $false ) ] [ string ] $externalDns ,
2018-07-03 19:07:37 +02:00
[ parameter ( Mandatory = $false ) ] [ string ] $appName = " eshop " ,
[ parameter ( Mandatory = $false ) ] [ bool ] $deployInfrastructure = $true ,
2019-02-25 13:27:26 +01:00
[ parameter ( Mandatory = $false ) ] [ bool ] $deployCharts = $true ,
2018-07-03 19:07:37 +02:00
[ parameter ( Mandatory = $false ) ] [ bool ] $clean = $true ,
[ parameter ( Mandatory = $false ) ] [ string ] $aksName = " " ,
[ parameter ( Mandatory = $false ) ] [ string ] $aksRg = " " ,
2018-11-12 17:55:22 +01:00
[ parameter ( Mandatory = $false ) ] [ string ] $imageTag = " latest " ,
2019-09-10 19:49:50 +02:00
[ parameter ( Mandatory = $false ) ] [ bool ] $useLocalk8s = $false ,
2019-10-31 09:45:18 +01:00
[ parameter ( Mandatory = $false ) ] [ bool ] $useMesh = $false ,
2019-09-10 19:49:50 +02:00
[ parameter ( Mandatory = $false ) ] [ string ] [ ValidateSet ( 'Always' , 'IfNotPresent' , 'Never' , IgnoreCase = $false ) ] $imagePullPolicy = " Always " ,
2019-12-17 18:12:53 +01:00
[ parameter ( Mandatory = $false ) ] [ string ] [ ValidateSet ( 'prod' , 'staging' , 'none' , 'custom' , IgnoreCase = $false ) ] $sslSupport = " none " ,
[ parameter ( Mandatory = $false ) ] [ string ] $tlsSecretName = " eshop-tls-custom " ,
2019-09-30 11:36:51 +02:00
[ parameter ( Mandatory = $false ) ] [ string ] $chartsToDeploy = " * " ,
[ parameter ( Mandatory = $false ) ] [ string ] $ingressMeshAnnotationsFile = " ingress_values_linkerd.yaml "
2018-11-12 17:55:22 +01:00
)
2018-07-03 19:07:37 +02:00
2019-12-17 18:12:53 +01:00
function Install-Chart {
Param ( [ string ] $chart , [ string ] $initialOptions , [ bool ] $customRegistry )
$options = $initialOptions
if ( $sslEnabled ) {
$options = " $options --set ingress.tls[0].secretName= $tlsSecretName --set ingress.tls[0].hosts={ $dns } "
if ( $sslSupport -ne " custom " ) {
$options = " $options --set inf.tls.issuer= $sslIssuer "
}
}
if ( $customRegistry ) {
$options = " $options --set inf.registry.server= $registry --set inf.registry.login= $dockerUser --set inf.registry.pwd= $dockerPassword --set inf.registry.secretName=eshop-docker-scret "
}
if ( $chart -ne " eshop-common " -or $customRegistry ) { # eshop-common is ignored when no secret must be deployed
$command = " install $options --name= $appName - $chart $chart "
Write-Host " Helm Command: helm $command " -ForegroundColor Gray
Invoke-Expression 'cmd /c "helm $command"'
}
}
2018-07-03 19:07:37 +02:00
$dns = $externalDns
2019-12-17 18:12:53 +01:00
$sslEnabled = $false
$sslIssuer = " "
if ( $sslSupport -eq " staging " ) {
$sslEnabled = $true
$tlsSecretName = " eshop-letsencrypt-staging "
$sslIssuer = " letsencrypt-staging "
}
elseif ( $sslSupport -eq " prod " ) {
$sslEnabled = $true
$tlsSecretName = " eshop-letsencrypt-prod "
$sslIssuer = " letsencrypt-prod "
}
elseif ( $sslSupport -eq " custom " ) {
$sslEnabled = $true
}
2018-07-03 19:07:37 +02:00
2018-11-12 17:55:22 +01:00
$ingressValuesFile = " ingress_values.yaml "
2018-12-17 16:11:43 +01:00
if ( $useLocalk8s -eq $true ) {
2018-11-12 17:55:22 +01:00
$ingressValuesFile = " ingress_values_dockerk8s.yaml "
$dns = " localhost "
}
2018-07-03 19:07:37 +02:00
if ( $externalDns -eq " aks " ) {
if ( [ string ] :: IsNullOrEmpty ( $aksName ) -or [ string ] :: IsNullOrEmpty ( $aksRg ) ) {
Write-Host " Error: When using -dns aks, MUST set -aksName and -aksRg too. " -ForegroundColor Red
exit 1
}
Write-Host " Getting DNS of AKS of AKS $aksName (in resource group $aksRg )... " -ForegroundColor Green
$dns = $ ( az aks show -n $aksName -g $aksRg - -query addonProfiles . httpApplicationRouting . config . HTTPApplicationRoutingZoneName )
if ( [ string ] :: IsNullOrEmpty ( $dns ) ) {
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
exit 1
}
$dns = $dns -replace '[\"]'
Write-Host " DNS base found is $dns . Will use $appName . $dns for the app! " -ForegroundColor Green
$dns = " $appName . $dns "
}
# Initialization & check commands
if ( [ string ] :: IsNullOrEmpty ( $dns ) ) {
Write-Host " No DNS specified. Ingress resources will be bound to public ip " -ForegroundColor Yellow
2019-12-17 18:12:53 +01:00
if ( $sslEnabled ) {
Write-Host " Can't bound SSL to public IP. DNS is mandatory when using TLS " -ForegroundColor Red
exit 1
}
}
if ( $useLocalk8s -and $sslEnabled ) {
Write-Host " SSL can'be enabled on local K8s. " -ForegroundColor Red
exit 1
2018-07-03 19:07:37 +02:00
}
if ( $clean ) {
Write-Host " Cleaning previous helm releases... " -ForegroundColor Green
2019-04-03 08:23:19 +00:00
helm delete - -purge $ ( helm ls -q eshop )
2018-07-03 19:07:37 +02:00
Write-Host " Previous releases deleted " -ForegroundColor Green
}
2018-07-09 14:20:27 +02:00
$useCustomRegistry = $false
if ( -not [ string ] :: IsNullOrEmpty ( $registry ) ) {
$useCustomRegistry = $true
if ( [ string ] :: IsNullOrEmpty ( $dockerUser ) -or [ string ] :: IsNullOrEmpty ( $dockerPassword ) ) {
Write-Host " Error: Must use -dockerUser AND -dockerPassword if specifying custom registry " -ForegroundColor Red
exit 1
}
}
2018-07-03 19:07:37 +02:00
Write-Host " Begin eShopOnContainers installation using Helm " -ForegroundColor Green
$infras = ( " sql-data " , " nosql-data " , " rabbitmq " , " keystore-data " , " basket-data " )
2019-09-10 19:49:50 +02:00
$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 " )
$gateways = ( " apigwmm " , " apigwms " , " apigwwm " , " apigwws " )
2018-07-03 19:07:37 +02:00
if ( $deployInfrastructure ) {
foreach ( $infra in $infras ) {
Write-Host " Installing infrastructure: $infra " -ForegroundColor Green
2019-04-28 20:59:13 +12:00
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
2018-07-03 19:07:37 +02:00
}
}
2019-02-25 13:27:26 +01:00
else {
Write-Host " eShopOnContainers infrastructure (bbdd, redis, ...) charts aren't installed (-deployCharts is false) " -ForegroundColor Yellow
}
2018-07-03 19:07:37 +02:00
2019-02-25 13:27:26 +01:00
if ( $deployCharts ) {
foreach ( $chart in $charts ) {
2019-09-10 19:49:50 +02:00
if ( $chartsToDeploy -eq " * " -or $chartsToDeploy . Contains ( $chart ) ) {
Write-Host " Installing: $chart " -ForegroundColor Green
2019-12-17 18:12:53 +01:00
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
2018-07-09 14:20:27 +02:00
}
}
2019-09-10 19:49:50 +02:00
foreach ( $chart in $gateways ) {
if ( $chartsToDeploy -eq " * " -or $chartsToDeploy . Contains ( $chart ) ) {
Write-Host " Installing Api Gateway Chart: $chart " -ForegroundColor Green
2019-12-17 18:12:53 +01:00
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
2019-09-10 19:49:50 +02:00
}
}
2018-07-03 19:07:37 +02:00
}
2019-02-25 13:27:26 +01:00
else {
Write-Host " eShopOnContainers non-infrastructure charts aren't installed (-deployCharts is false) " -ForegroundColor Yellow
}
2018-07-03 19:07:37 +02:00
2019-04-03 08:23:19 +00:00
Write-Host " helm charts installed. " -ForegroundColor Green