-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup-docker-solution.ps1
127 lines (110 loc) · 4.2 KB
/
setup-docker-solution.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
function Get-EnvValue([string]$name)
{
$envFile = Get-Content -Path ".env"
foreach ($line in $envFile)
{
if ( $line.Trim().StartsWith($name + "="))
{
return $line.Split("=")[1]
}
}
return $null
}
# Get docker image variables
$date = Get-Date
$version = $date.ToString("yyyy.MM.dd.HHmmss")
$repo = "afroze9"
$api_gateway_port = Get-EnvValue "API_GATEWAY_PORT_EXTERNAL"
$company_api_port = Get-EnvValue "COMPANY_API_PORT_EXTERNAL"
$project_api_port = Get-EnvValue "PROJECT_API_PORT_EXTERNAL"
$health_checks_dashboard_port = Get-EnvValue "HEALTH_CHECKS_DASHBOARD_PORT_EXTERNAL"
echo "Generating Dev Certs"
$CreateCert = (dotnet dev-certs https -c | Select-String -SimpleMatch "No valid certificate found.")
if ($CreateCert)
{
dotnet dev-certs https --trust
}
dotnet dev-certs https -ep ./devcerts/aspnetapp.pfx -p $devCertPassword
echo ""
echo "Increasing WSL memory for ELK"
wsl -d docker-desktop sysctl -w vm.max_map_count=262144
echo ""
echo "Building Docker Images"
.\build-docker-images.ps1 -version $version -repo $repo
echo ""
echo "Checking Docker Networks"
$networkName = "consul-external"
$networkList = docker network ls --filter name=$networkName --format "{{.Name}}"
if ($networkList -contains $networkName) {
Write-Host "The '$networkName' network already exists."
} else {
docker network create $networkName
Write-Host "The '$networkName' network has been created."
}
$networkId = docker network inspect $networkName --format='{{.Id}}'
$subnetIp = docker network inspect $networkId --format='{{(index .IPAM.Config 0).Subnet}}'
echo "The Subnet IP is $subnetIp"
echo ""
echo "Starting Consul"
Push-Location ".\discovery-server\docker\"
&".\setup-consul.ps1" "token"
Pop-Location
echo ""
echo "Setting up ACL for api-gateway"
Push-Location ".\api-gateway\src\ProjectManagement.ApiGateway\Consul"
&".\setup-consul-docker.ps1" "api_gateway_token"
Pop-Location
echo ""
echo "Setting up ACL for company-api"
Push-Location ".\company-api\src\ProjectManagement.Company.Api\Consul"
&".\setup-consul-docker.ps1" "company_api_token"
Pop-Location
echo ""
echo "Setting up ACL for project-api"
Push-Location ".\project-api\src\ProjectManagement.Project.Api\Consul"
&".\setup-consul-docker.ps1" "project_api_token"
Pop-Location
echo ""
echo "Setting up ACL for health-checks-dashboard"
Push-Location ".\health-checks-dashboard\src\ProjectManagement.HealthChecksDashboard\Consul"
&".\setup-consul-docker.ps1" "health_checks_dashboard_token"
Pop-Location
echo ""
echo "Copying tokens to .env file"
(Get-Content .env) |
ForEach-Object { $_ -replace "^API_GATEWAY_TOKEN=.*", "API_GATEWAY_TOKEN=$api_gateway_token" } |
ForEach-Object { $_ -replace "^COMPANY_API_TOKEN=.*", "COMPANY_API_TOKEN=$company_api_token" } |
ForEach-Object { $_ -replace "^PROJECT_API_TOKEN=.*", "PROJECT_API_TOKEN=$project_api_token" } |
ForEach-Object { $_ -replace "^HEALTH_CHECKS_DASHBOARD_TOKEN=.*", "HEALTH_CHECKS_DASHBOARD_TOKEN=$health_checks_dashboard_token" } |
Set-Content .env
echo ""
echo "Setting up databases, elk, and jaeger"
docker-compose -f .\docker-compose.yml up -d
$tokens = @{
"Global Token" = $token
"API Gateway Token" = $api_gateway_token
"Company API Token" = $company_api_token
"Project API Token" = $project_api_token
"Health Checks Dashboard Token" = $health_checks_dashboard_token
}
$services = @{
"API Gateway" = "https://localhost:$api_gateway_port"
"Company API" = "https://localhost:$company_api_port"
"Project API" = "https://localhost:$project_api_port"
"Health Checks Dashboard" = "https://localhost:$health_checks_dashboard_port"
"Frontend App" = "http://localhost:3000"
"Consul" = "http://localhost:8500"
"Kibana" = "http://localhost:5601"
"Jaeger" = "http://localhost:16686"
}
echo ""
echo "----------------------------------------------"
echo "Setup complete"
echo "----------------------------------------------"
echo "Tokens"
echo "----------------------------------------------"
$tokens.GetEnumerator() | Format-Table -AutoSize -Property Name, Value
echo ""
echo "`nServices"
echo "----------------------------------------------"
$services.GetEnumerator() | Format-Table -AutoSize -Property Name, Value