-
Notifications
You must be signed in to change notification settings - Fork 1
/
winRun.ps1
92 lines (75 loc) · 3.27 KB
/
winRun.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
## This script is used to run the deployment process on a Windows machine.
## It will build the base image, deploy the core resources, build the containers and push them to ACR, and finally deploy the containers.
Write-Host "######################################## EXECUTION STARTING ########################################"
$env = "dev"
Remove-Item -Recurse -Force "output" -ErrorAction SilentlyContinue
########################## BASE DEPLOY IMAGE
Write-Host "################# Building base image"
Set-Location "base-deploy-image"
docker build . -t deploy-image
Set-Location ..
########################## REMOVE ANY OLD CONTAINERS
Write-Host "################# Removing old deployment-container and live-deploy image"
$containerId = docker ps -a | Where-Object { $_ -match 'deploy-container' } | ForEach-Object { ($_ -split '\s+')[0] }
Write-Output $containerId
if (-not [string]::IsNullOrEmpty($containerId)) {
docker rm $containerId
} else {
Write-Output "No 'deploy-container' found to remove."
}
Start-Sleep -Seconds 10
$imageId = docker images | Where-Object { $_ -match 'live-deploy' } | ForEach-Object { ($_ -split '\s+')[2] }
Write-Output $imageId
if (-not [string]::IsNullOrEmpty($imageId)) {
docker rmi $imageId
} else {
Write-Output "No 'live-deploy' image found to remove."
}
Start-Sleep -Seconds 10
########################## DEPLOY CORE RESOURCES
Write-Host "################# Building deployment image"
docker build . -t live-deploy
Start-Sleep -Seconds 10
Write-Host "################# Deploying core"
docker run --name deploy-container -v "$(Get-Location)/output:/output" -e "PHASE=core" -e "TF_VAR_env=$env" live-deploy
Start-Sleep -Seconds 10
Write-Host "################# Removing deploy-container"
$containerId = docker ps -a | Where-Object { $_ -match 'deploy-container' } | ForEach-Object { ($_ -split '\s+')[0] }
Write-Output $containerId
if (-not [string]::IsNullOrEmpty($containerId)) {
docker rm $containerId
} else {
Write-Output "No 'deploy-container' found to remove."
}
Start-Sleep -Seconds 10
########################## BUILD DOCKER IMAGES AND PUSH TO ACR
Write-Host "################# Building and pushing containers to ACR"
# Save current location
Push-Location
# Change the location to 'containers' directory
Set-Location "containers"
# Print the current location
Write-Host $(Get-Location)
# Run the other PowerShell script
Invoke-Expression -Command .\winPushContAcr.ps1
Start-Sleep -Seconds 10
Write-Host "################# Deploying containers"
# Go back to original directory
Pop-Location
Write-Host $(Get-Location)
Start-Sleep -Seconds 10
########################## DEPLOY CONTAINERS RESOURCES
$currentPath = (Get-Location).Path
Write-Host "## Mounting volume : "
Write-Host "${currentPath}\output"
docker run --name deploy-container -v "${currentPath}\output:/output" -e "PHASE=containers" -e "TF_VAR_env=$env" live-deploy
Write-Host "################# Removing deploy-container"
Start-Sleep -Seconds 5
$containerId = docker ps -a | Where-Object { $_ -match 'deploy-container' } | ForEach-Object { ($_ -split '\s+')[0] }
Write-Output $containerId
if (-not [string]::IsNullOrEmpty($containerId)) {
docker rm $containerId
} else {
Write-Output "No 'deploy-container' found to remove."
}
Write-Host "################# DEPLOYMENT COMPLETED #################"