Modify kubernetes deploy script to support CI vsts
This commit is contained in:
parent
2af88e74c8
commit
f724c6b91b
@ -1,9 +1,17 @@
|
|||||||
Param(
|
Param(
|
||||||
[parameter(Mandatory=$true)][string]$registry,
|
[parameter(Mandatory=$false)][string]$registry,
|
||||||
[parameter(Mandatory=$true)][string]$dockerUser,
|
[parameter(Mandatory=$false)][string]$dockerUser,
|
||||||
[parameter(Mandatory=$true)][string]$dockerPassword
|
[parameter(Mandatory=$false)][string]$dockerPassword,
|
||||||
|
[parameter(Mandatory=$false)][bool]$deployCI,
|
||||||
|
[parameter(Mandatory=$false)][string]$execPath
|
||||||
)
|
)
|
||||||
|
|
||||||
|
$kubectl_exec = 'kubectl';
|
||||||
|
|
||||||
|
if(-not [string]::IsNullOrEmpty($execPath)) {
|
||||||
|
$kubectl_exec = $execPath + '/' + 'kubectl';
|
||||||
|
}
|
||||||
|
|
||||||
$requiredCommands = ("docker", "docker-compose", "kubectl")
|
$requiredCommands = ("docker", "docker-compose", "kubectl")
|
||||||
foreach ($command in $requiredCommands) {
|
foreach ($command in $requiredCommands) {
|
||||||
if ((Get-Command $command -ErrorAction SilentlyContinue) -eq $null) {
|
if ((Get-Command $command -ErrorAction SilentlyContinue) -eq $null) {
|
||||||
@ -12,69 +20,79 @@ foreach ($command in $requiredCommands) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Logging in to $registry" -ForegroundColor Yellow
|
# Not using ACR when deploying through CI VSTS
|
||||||
docker login -u $dockerUser -p $dockerPassword $registry
|
if(-not $deployCI) {
|
||||||
if (-not $LastExitCode -eq 0) {
|
Write-Host "Logging in to $registry" -ForegroundColor Yellow
|
||||||
Write-Host "Login failed" -ForegroundColor Red
|
docker login -u $dockerUser -p $dockerPassword $registry
|
||||||
exit
|
if (-not $LastExitCode -eq 0) {
|
||||||
}
|
Write-Host "Login failed" -ForegroundColor Red
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
# create registry key secret
|
# create registry key secret
|
||||||
kubectl create secret docker-registry registry-key `
|
& $kubectl_exec create secret docker-registry registry-key `
|
||||||
--docker-server=$registry `
|
--docker-server=$registry `
|
||||||
--docker-username=$dockerUser `
|
--docker-username=$dockerUser `
|
||||||
--docker-password=$dockerPassword `
|
--docker-password=$dockerPassword `
|
||||||
--docker-email=not@used.com
|
--docker-email=not@used.com
|
||||||
|
}
|
||||||
|
|
||||||
# start sql, rabbitmq, frontend deployments
|
# start sql, rabbitmq, frontend deployments
|
||||||
kubectl create configmap config-files --from-file=nginx-conf=nginx.conf
|
& $kubectl_exec create configmap config-files --from-file=nginx-conf=nginx.conf
|
||||||
kubectl label configmap config-files app=eshop
|
& $kubectl_exec label configmap config-files app=eshop
|
||||||
kubectl create -f sql-data.yaml -f rabbitmq.yaml -f services.yaml -f frontend.yaml
|
& $kubectl_exec create -f sql-data.yaml -f rabbitmq.yaml -f services.yaml -f frontend.yaml
|
||||||
|
|
||||||
Write-Host "Building and publishing eShopOnContainers..." -ForegroundColor Yellow
|
# building and publishing docker images not necessary when deploying through CI VSTS
|
||||||
dotnet restore ../eShopOnContainers-ServicesAndWebApps.sln
|
if(-not $deployCI) {
|
||||||
dotnet publish -c Release -o obj/Docker/publish ../eShopOnContainers-ServicesAndWebApps.sln
|
Write-Host "Building and publishing eShopOnContainers..." -ForegroundColor Yellow
|
||||||
|
dotnet restore ../eShopOnContainers-ServicesAndWebApps.sln
|
||||||
|
dotnet publish -c Release -o obj/Docker/publish ../eShopOnContainers-ServicesAndWebApps.sln
|
||||||
|
|
||||||
Write-Host "Building Docker images..." -ForegroundColor Yellow
|
Write-Host "Building Docker images..." -ForegroundColor Yellow
|
||||||
docker-compose -p .. -f ../docker-compose.yml build
|
docker-compose -p .. -f ../docker-compose.yml build
|
||||||
|
|
||||||
Write-Host "Pushing images to $registry..." -ForegroundColor Yellow
|
Write-Host "Pushing images to $registry..." -ForegroundColor Yellow
|
||||||
$services = ("basket.api", "catalog.api", "identity.api", "ordering.api", "webmvc", "webspa")
|
$services = ("basket.api", "catalog.api", "identity.api", "ordering.api", "webmvc", "webspa")
|
||||||
foreach ($service in $services) {
|
foreach ($service in $services) {
|
||||||
docker tag eshop/$service $registry/eshop/$service
|
docker tag eshop/$service $registry/eshop/$service
|
||||||
docker push $registry/eshop/$service
|
docker push $registry/eshop/$service
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Waiting for frontend's external ip..." -ForegroundColor Yellow
|
Write-Host "Waiting for frontend's external ip..." -ForegroundColor Yellow
|
||||||
while ($true) {
|
while ($true) {
|
||||||
$frontendUrl = kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"
|
$frontendUrl = & $kubectl_exec get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"
|
||||||
if ([bool]($frontendUrl -as [ipaddress])) {
|
if ([bool]($frontendUrl -as [ipaddress])) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
Start-Sleep -s 15
|
Start-Sleep -s 15
|
||||||
}
|
}
|
||||||
|
|
||||||
kubectl create configmap urls `
|
& $kubectl_exec create configmap urls `
|
||||||
--from-literal=BasketUrl=http://$($frontendUrl)/basket-api `
|
--from-literal=BasketUrl=http://$($frontendUrl)/basket-api `
|
||||||
--from-literal=CatalogUrl=http://$($frontendUrl)/catalog-api `
|
--from-literal=CatalogUrl=http://$($frontendUrl)/catalog-api `
|
||||||
--from-literal=IdentityUrl=http://$($frontendUrl)/identity `
|
--from-literal=IdentityUrl=http://$($frontendUrl)/identity `
|
||||||
--from-literal=OrderingUrl=http://$($frontendUrl)/ordering-api `
|
--from-literal=OrderingUrl=http://$($frontendUrl)/ordering-api `
|
||||||
--from-literal=MvcClient=http://$($frontendUrl)/webmvc `
|
--from-literal=MvcClient=http://$($frontendUrl)/webmvc `
|
||||||
--from-literal=SpaClient=http://$($frontendUrl)
|
--from-literal=SpaClient=http://$($frontendUrl)
|
||||||
kubectl label configmap urls app=eshop
|
& $kubectl_exec label configmap urls app=eshop
|
||||||
|
|
||||||
Write-Host "Creating deployments..."
|
Write-Host "Creating deployments..."
|
||||||
kubectl apply -f deployments.yaml
|
& $kubectl_exec apply -f deployments.yaml
|
||||||
|
|
||||||
# update deployments with the private registry before k8s tries to pull images
|
# not using ACR for pulling images when deploying through CI VSTS
|
||||||
# (deployment templating, or Helm, would obviate this)
|
if(-not $deployCI) {
|
||||||
kubectl set image -f deployments.yaml `
|
# update deployments with the private registry before k8s tries to pull images
|
||||||
basket=$registry/eshop/basket.api `
|
# (deployment templating, or Helm, would obviate this)
|
||||||
catalog=$registry/eshop/catalog.api `
|
& $kubectl_exec set image -f deployments.yaml `
|
||||||
identity=$registry/eshop/identity.api `
|
basket=$registry/eshop/basket.api `
|
||||||
ordering=$registry/eshop/ordering.api `
|
catalog=$registry/eshop/catalog.api `
|
||||||
webmvc=$registry/eshop/webmvc `
|
identity=$registry/eshop/identity.api `
|
||||||
webspa=$registry/eshop/webspa
|
ordering=$registry/eshop/ordering.api `
|
||||||
kubectl rollout resume -f deployments.yaml
|
webmvc=$registry/eshop/webmvc `
|
||||||
|
webspa=$registry/eshop/webspa
|
||||||
|
}
|
||||||
|
|
||||||
|
& $kubectl_exec rollout resume -f deployments.yaml
|
||||||
|
|
||||||
Write-Host "WebSPA is exposed at http://$frontendUrl, WebMVC at http://$frontendUrl/webmvc" -ForegroundColor Yellow
|
Write-Host "WebSPA is exposed at http://$frontendUrl, WebMVC at http://$frontendUrl/webmvc" -ForegroundColor Yellow
|
||||||
|
Loading…
x
Reference in New Issue
Block a user