-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
197 lines (172 loc) · 7.17 KB
/
build.ps1
File metadata and controls
197 lines (172 loc) · 7.17 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# PowerShell build script for ITL Documentation Hub
# Usage: .\build.ps1 [command]
param(
[Parameter(Position=0)]
[string]$Command = "help"
)
function Show-Help {
Write-Host "ITL Documentation Hub Build Script" -ForegroundColor Green
Write-Host ""
Write-Host "Usage: .\build.ps1 [command]" -ForegroundColor Yellow
Write-Host ""
Write-Host "Available commands:" -ForegroundColor Cyan
Write-Host " help Show this help message"
Write-Host " install Install dependencies (Python + Node.js)"
Write-Host " build Build documentation and API"
Write-Host " serve Serve documentation locally"
Write-Host " api Start API server"
Write-Host " dev Start development servers (frontend + API)"
Write-Host " clean Clean build artifacts"
Write-Host " docker-build Build Docker images (frontend + API)"
Write-Host " docker-run Run Docker containers"
Write-Host " docker-stop Stop Docker containers"
Write-Host " helm-lint Lint Helm chart"
Write-Host " helm-template Generate Kubernetes manifests (without validation)"
Write-Host " helm-validate Validate Kubernetes manifests"
Write-Host " test Test documentation build and API"
Write-Host " security Run security scan on Docker images"
Write-Host " ci-test Run CI tests locally"
Write-Host " all Run all build steps"
}
function Install-Dependencies {
Write-Host "Installing dependencies..." -ForegroundColor Yellow
# Install Python dependencies
Write-Host "Installing Python dependencies..." -ForegroundColor Cyan
python -m pip install --upgrade pip
pip install -r requirements.txt
# Install Node.js dependencies for API
Write-Host "Installing Node.js dependencies..." -ForegroundColor Cyan
Set-Location api
npm install
Set-Location ..
Write-Host "Dependencies installed successfully" -ForegroundColor Green
}
function Build-Documentation {
Write-Host "Building documentation..." -ForegroundColor Yellow
mkdocs build --clean --strict
Write-Host "Documentation built successfully" -ForegroundColor Green
}
function Serve-Documentation {
Write-Host "Serving documentation locally..." -ForegroundColor Yellow
mkdocs serve
}
function Clean-Artifacts {
Write-Host "Cleaning build artifacts..." -ForegroundColor Yellow
if (Test-Path "site") { Remove-Item -Recurse -Force "site" }
if (Test-Path "manifests*.yaml") { Remove-Item "manifests*.yaml" }
}
function Build-Docker {
Write-Host "Building Docker images..." -ForegroundColor Yellow
Write-Host "Building frontend image..." -ForegroundColor Cyan
docker build -t itlusions/docs-hub-frontend:latest -f Dockerfile.frontend .
Write-Host "Building API image..." -ForegroundColor Cyan
docker build -t itlusions/docs-hub-api:latest ./api
Write-Host "Docker images built successfully" -ForegroundColor Green
}
function Run-Docker {
Write-Host "Running Docker containers..." -ForegroundColor Yellow
docker-compose up -d docs-hub-frontend docs-api
Write-Host "Frontend available at http://localhost:8080" -ForegroundColor Green
Write-Host "API available at http://localhost:3000" -ForegroundColor Green
}
function Stop-Docker {
Write-Host "Stopping Docker containers..." -ForegroundColor Yellow
docker-compose down
}
function Lint-Helm {
Write-Host "Linting Helm chart..." -ForegroundColor Yellow
helm lint charts/docs-hub --strict
}
function Template-Helm {
Write-Host "Generating Kubernetes manifests (without validation)..." -ForegroundColor Yellow
helm template docs-hub charts/docs-hub --validate=false > manifests.yaml
Write-Host "Manifests generated: manifests.yaml" -ForegroundColor Green
}
function Validate-Helm {
Write-Host "Validating Kubernetes manifests..." -ForegroundColor Yellow
helm template docs-hub charts/docs-hub --validate=false > manifests-test.yaml
# Check if kubeval is available
$kubeval = Get-Command kubeval -ErrorAction SilentlyContinue
if ($kubeval) {
kubeval manifests-test.yaml --ignore-missing-schemas --skip-kinds IngressRoute,Middleware,ServiceMonitor
} else {
Write-Host "kubeval not found. Skipping Kubernetes validation." -ForegroundColor Yellow
Write-Host "To install kubeval: https://github.com/instrumenta/kubeval" -ForegroundColor Cyan
}
}
function Test-Build {
Write-Host "Testing documentation build..." -ForegroundColor Yellow
mkdocs build --strict
Write-Host "Documentation built successfully" -ForegroundColor Green
}
function Test-Security {
Write-Host "Running security scan on local Docker image..." -ForegroundColor Yellow
# Check if trivy is available
$trivy = Get-Command trivy -ErrorAction SilentlyContinue
if ($trivy) {
# Scan the local image (if it exists)
$imageName = "ghcr.io/itlusions/identity-docs:latest"
$localImage = docker images --format "table {{.Repository}}:{{.Tag}}" | Select-String $imageName
if ($localImage) {
Write-Host "Scanning image: $imageName" -ForegroundColor Cyan
trivy image --severity HIGH,CRITICAL --ignore-unfixed $imageName
} else {
Write-Host "Local image not found. Build the image first with: .\build.ps1 docker-build" -ForegroundColor Yellow
}
} else {
Write-Host "Trivy not found. Install from: https://github.com/aquasecurity/trivy" -ForegroundColor Yellow
Write-Host "Or use the CI pipeline for security scanning." -ForegroundColor Cyan
}
}
function Run-CiTest {
Write-Host "Running CI tests locally..." -ForegroundColor Yellow
Test-Build
Lint-Helm
Validate-Helm
}
function Start-API {
Write-Host "Starting API server..." -ForegroundColor Yellow
Write-Host "API will be available at http://localhost:3000" -ForegroundColor Green
Set-Location api
node server.js
Set-Location ..
}
function Start-Development {
Write-Host "Starting development servers..." -ForegroundColor Yellow
Write-Host "Frontend: http://localhost:8000" -ForegroundColor Green
Write-Host "API: http://localhost:3000" -ForegroundColor Green
docker-compose up mkdocs-dev docs-api
}
function Run-All {
Write-Host "Running all build steps..." -ForegroundColor Yellow
Clean-Artifacts
Install-Dependencies
Build-Documentation
Lint-Helm
Template-Helm
}
# Main command dispatcher
switch ($Command.ToLower()) {
"help" { Show-Help }
"install" { Install-Dependencies }
"build" { Build-Documentation }
"serve" { Serve-Documentation }
"api" { Start-API }
"dev" { Start-Development }
"clean" { Clean-Artifacts }
"docker-build" { Build-Docker }
"docker-run" { Run-Docker }
"docker-stop" { Stop-Docker }
"helm-lint" { Lint-Helm }
"helm-template" { Template-Helm }
"helm-validate" { Validate-Helm }
"test" { Test-Build }
"security" { Test-Security }
"ci-test" { Run-CiTest }
"all" { Run-All }
default {
Write-Host "Unknown command: $Command" -ForegroundColor Red
Show-Help
exit 1
}
}