fix: use blue to refer to existing version and green to refer to new version
This commit is contained in:
+44
-44
@@ -116,43 +116,11 @@ if ($LASTEXITCODE -ne 0)
|
||||
}
|
||||
|
||||
# Checkif green container is running
|
||||
$greenContainerId = docker ps --filter "name=blog.stevanfreeborn.com.green" --format "{{.ID}}"
|
||||
$blueContainerId = docker ps --filter "name=blog.stevanfreeborn.com.blue" --format "{{.ID}}"
|
||||
|
||||
if ($null -eq $greenContainerId)
|
||||
if ($null -eq $blueContainerId)
|
||||
{
|
||||
Write-Host "Green container is not running. Starting green container."
|
||||
|
||||
$greenContainerHostPort = StartContainer -containerColor "green" -dockerTag $dockerTag
|
||||
|
||||
Write-Host "Green container is running."
|
||||
|
||||
UpdateNginxConfig -filePath $NGINX_CONFIG_PATH -portNumber $greenContainerHostPort
|
||||
|
||||
Write-Host "Nginx configuration updated to point to green container on port $greenContainerHostPort."
|
||||
|
||||
nginx -t
|
||||
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
Write-Host "Nginx configuration test failed. Reverting changes."
|
||||
Set-Content -Path $filePath -Value $nginxConfig
|
||||
exit 1
|
||||
}
|
||||
|
||||
nginx -s reload
|
||||
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
Write-Host "Failed to reload Nginx."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Nginx reloaded. Successfully deployed version $version."
|
||||
exit 0
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Green container is running. Starting blue container."
|
||||
Write-Host "Blue container is not running. Starting blue container."
|
||||
|
||||
$blueContainerHostPort = StartContainer -containerColor "blue" -dockerTag $dockerTag
|
||||
|
||||
@@ -180,34 +148,66 @@ else
|
||||
}
|
||||
|
||||
Write-Host "Nginx reloaded. Successfully deployed version $version."
|
||||
exit 0
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "Blue container is running. Starting green container."
|
||||
|
||||
Write-Host "Stopping and removing green container."
|
||||
$greenContainerHostPort = StartContainer -containerColor "green" -dockerTag $dockerTag
|
||||
|
||||
docker stop $greenContainerId
|
||||
Write-Host "Green container is running."
|
||||
|
||||
UpdateNginxConfig -filePath $NGINX_CONFIG_PATH -portNumber $greenContainerHostPort
|
||||
|
||||
Write-Host "Nginx configuration updated to point to green container on port $greenContainerHostPort."
|
||||
|
||||
nginx -t
|
||||
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
Write-Host "Failed to stop green container."
|
||||
Write-Host "Nginx configuration test failed. Reverting changes."
|
||||
Set-Content -Path $filePath -Value $nginxConfig
|
||||
exit 1
|
||||
}
|
||||
|
||||
docker rm $greenContainerId
|
||||
nginx -s reload
|
||||
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
Write-Host "Failed to remove green container."
|
||||
Write-Host "Failed to reload Nginx."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Green container stopped and removed."
|
||||
Write-Host "Nginx reloaded. Successfully deployed version $version."
|
||||
|
||||
Write-Host "Switching blue container to green container."
|
||||
Write-Host "Stopping and removing blue container."
|
||||
|
||||
docker rename "blog.stevanfreeborn.com.blue" "blog.stevanfreeborn.com.green"
|
||||
docker stop $blueContainerId
|
||||
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
Write-Host "Failed to rename blue container to green container."
|
||||
Write-Host "Failed to stop blue container."
|
||||
exit 1
|
||||
}
|
||||
|
||||
docker rm $blueContainerId
|
||||
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
Write-Host "Failed to remove blue container."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Blue container stopped and removed."
|
||||
|
||||
Write-Host "Switching green container to blue container."
|
||||
|
||||
docker rename "blog.stevanfreeborn.com.green" "blog.stevanfreeborn.com.blue"
|
||||
|
||||
if ($LASTEXITCODE -ne 0)
|
||||
{
|
||||
Write-Host "Failed to rename green container to blue container."
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user