|
| 1 | +Param( |
| 2 | + [parameter(Mandatory=$true)][string]$registry, |
| 3 | + [parameter(Mandatory=$true)][string]$dockerUser, |
| 4 | + [parameter(Mandatory=$true)][string]$dockerPassword |
| 5 | +) |
| 6 | + |
| 7 | +$requiredCommands = ("docker", "docker-compose", "kubectl") |
| 8 | +foreach ($command in $requiredCommands) { |
| 9 | + if ((Get-Command $command -ErrorAction SilentlyContinue) -eq $null) { |
| 10 | + Write-Host "$command must be on path" -ForegroundColor Red |
| 11 | + exit |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +Write-Host "Logging in to $registry" -ForegroundColor Yellow |
| 16 | +docker login -u $dockerUser -p $dockerPassword $registry |
| 17 | +if (-not $LastExitCode -eq 0) { |
| 18 | + Write-Host "Login failed" -ForegroundColor Red |
| 19 | + exit |
| 20 | +} |
| 21 | + |
| 22 | +# create registry key secret |
| 23 | +kubectl create secret docker-registry registry-key ` |
| 24 | + --docker-server=$registry ` |
| 25 | + --docker-username=$dockerUser ` |
| 26 | + --docker-password=$dockerPassword ` |
| 27 | + --docker-email=not@used.com |
| 28 | + |
| 29 | +# start sql and frontend deployments |
| 30 | +kubectl create configmap config-files --from-file=nginx-conf=nginx.conf |
| 31 | +kubectl label configmap config-files app=eshop |
| 32 | +kubectl create -f sql-data.yaml -f services.yaml -f frontend.yaml |
| 33 | + |
| 34 | +Write-Host "Building solution..." -ForegroundColor Yellow |
| 35 | +../cli-windows/build-bits-simple.ps1 |
| 36 | + |
| 37 | +Write-Host "Building Docker images..." -ForegroundColor Yellow |
| 38 | +docker-compose -p .. -f ../docker-compose.yml build |
| 39 | + |
| 40 | +Write-Host "Pushing images to $registry..." -ForegroundColor Yellow |
| 41 | +$services = ("basket.api", "catalog.api", "identity.api", "ordering.api", "webmvc", "webspa") |
| 42 | +foreach ($service in $services) { |
| 43 | + docker tag eshop/$service $registry/$service |
| 44 | + docker push $registry/$service |
| 45 | +} |
| 46 | + |
| 47 | +Write-Host "Waiting for frontend's external ip..." -ForegroundColor Yellow |
| 48 | +while ($true) { |
| 49 | + $frontendUrl = kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}" 2> $_ |
| 50 | + if ([bool]($frontendUrl -as [ipaddress])) { |
| 51 | + break |
| 52 | + } |
| 53 | + Start-Sleep -s 15 |
| 54 | +} |
| 55 | + |
| 56 | +kubectl create configmap urls ` |
| 57 | + --from-literal=BasketUrl=http://$($frontendUrl)/basket-api ` |
| 58 | + --from-literal=CatalogUrl=http://$($frontendUrl)/catalog-api ` |
| 59 | + --from-literal=IdentityUrl=http://$($frontendUrl)/identity ` |
| 60 | + --from-literal=OrderingUrl=http://$($frontendUrl)/ordering-api ` |
| 61 | + --from-literal=MvcClient=http://$($frontendUrl)/webmvc ` |
| 62 | + --from-literal=SpaClient=http://$($frontendUrl) |
| 63 | +kubectl label configmap urls app=eshop |
| 64 | + |
| 65 | +# TODO verify database readiness? |
| 66 | +Write-Host "Creating deployments..." |
| 67 | +kubectl apply -f deployments.yaml |
| 68 | + |
| 69 | +# update deployments with the private registry |
| 70 | +# (deployment templating, or Helm, would obviate this) |
| 71 | +kubectl set image -f deployments.yaml ` |
| 72 | + basket=$registry/basket.api ` |
| 73 | + catalog=$registry/catalog.api ` |
| 74 | + identity=$registry/identity.api ` |
| 75 | + ordering=$registry/ordering.api ` |
| 76 | + webmvc=$registry/webmvc ` |
| 77 | + webspa=$registry/webspa |
| 78 | +kubectl rollout resume -f deployments.yaml |
| 79 | + |
| 80 | +Write-Host "WebSPA is exposed at http://$frontendUrl, WebMVC at http://$frontendUrl/webmvc" -ForegroundColor Yellow |
0 commit comments