-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-base-images.ps1
More file actions
executable file
·228 lines (183 loc) · 6.95 KB
/
build-base-images.ps1
File metadata and controls
executable file
·228 lines (183 loc) · 6.95 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Build Red Hat UBI base Docker images for Artemis API.
.DESCRIPTION
Builds the Red Hat Universal Base Image (UBI) Docker images required for the Artemis API:
1. artemis/ubi8-dotnet-sdk:9.0 - SDK image for building .NET applications
2. artemis/ubi8-aspnet-runtime:9.0 - Runtime image with ASP.NET Core and PowerShell
Corporate requirement: Use Red Hat UBI instead of Microsoft official images.
.PARAMETER BuildSdkOnly
Build only the SDK base image.
.PARAMETER BuildRuntimeOnly
Build only the runtime base image.
.PARAMETER NoBuildCache
Build images without using Docker cache (clean build).
.EXAMPLE
.\build-base-images.ps1
Builds both SDK and runtime base images.
.EXAMPLE
.\build-base-images.ps1 -NoBuildCache
Builds both images without using Docker cache.
.EXAMPLE
.\build-base-images.ps1 -BuildSdkOnly
Builds only the SDK base image.
.NOTES
These base images must be built before running docker-compose build.
Author: Artemis Development Team
#>
[CmdletBinding()]
param(
[Parameter(HelpMessage = "Build only the SDK base image")]
[switch]$BuildSdkOnly,
[Parameter(HelpMessage = "Build only the runtime base image")]
[switch]$BuildRuntimeOnly,
[Parameter(HelpMessage = "Build without using Docker cache")]
[switch]$NoBuildCache
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# Color output functions
function Write-Info {
param([string]$Message)
Write-Host "[INFO] $Message" -ForegroundColor Cyan
}
function Write-Success {
param([string]$Message)
Write-Host "[SUCCESS] $Message" -ForegroundColor Green
}
function Write-Error {
param([string]$Message)
Write-Host "[ERROR] $Message" -ForegroundColor Red
}
function Write-Warning {
param([string]$Message)
Write-Host "[WARNING] $Message" -ForegroundColor Yellow
}
# Main script
try {
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Push-Location $scriptDir
Write-Info "Starting Red Hat UBI base image build process..."
Write-Info "Script directory: $scriptDir"
Write-Info "Docker version: $(docker --version)"
Write-Info ""
# Determine build cache flag
$cacheFlag = if ($NoBuildCache) { "--no-cache" } else { "" }
if ($NoBuildCache) {
Write-Warning "Building without Docker cache (clean build)..."
}
# Build SDK image
if (-not $BuildRuntimeOnly) {
Write-Info "========================================="
Write-Info "Building artemis/ubi8-dotnet-sdk:9.0"
Write-Info "========================================="
$sdkDockerfile = Join-Path $scriptDir "Dockerfile.ubi8-dotnet-sdk"
if (-not (Test-Path $sdkDockerfile)) {
throw "SDK Dockerfile not found: $sdkDockerfile"
}
Write-Info "Dockerfile: $sdkDockerfile"
Write-Info "Starting build..."
$buildArgs = @(
"build",
"-f", $sdkDockerfile,
"-t", "artemis/ubi8-dotnet-sdk:9.0",
"."
)
if ($cacheFlag) {
$buildArgs += $cacheFlag
}
$sdkBuildStart = Get-Date
& docker @buildArgs
if ($LASTEXITCODE -ne 0) {
throw "Failed to build SDK image. Exit code: $LASTEXITCODE"
}
$sdkBuildDuration = (Get-Date) - $sdkBuildStart
Write-Success "SDK image built successfully in $($sdkBuildDuration.TotalSeconds.ToString('F2')) seconds"
Write-Info ""
}
# Build runtime image
if (-not $BuildSdkOnly) {
Write-Info "========================================="
Write-Info "Building artemis/ubi8-aspnet-runtime:9.0"
Write-Info "========================================="
$runtimeDockerfile = Join-Path $scriptDir "Dockerfile.ubi8-aspnet-runtime"
if (-not (Test-Path $runtimeDockerfile)) {
throw "Runtime Dockerfile not found: $runtimeDockerfile"
}
Write-Info "Dockerfile: $runtimeDockerfile"
Write-Info "Starting build..."
$buildArgs = @(
"build",
"-f", $runtimeDockerfile,
"-t", "artemis/ubi8-aspnet-runtime:9.0",
"."
)
if ($cacheFlag) {
$buildArgs += $cacheFlag
}
$runtimeBuildStart = Get-Date
& docker @buildArgs
if ($LASTEXITCODE -ne 0) {
throw "Failed to build runtime image. Exit code: $LASTEXITCODE"
}
$runtimeBuildDuration = (Get-Date) - $runtimeBuildStart
Write-Success "Runtime image built successfully in $($runtimeBuildDuration.TotalSeconds.ToString('F2')) seconds"
Write-Info ""
}
# Display image information
Write-Info "========================================="
Write-Info "Image Build Summary"
Write-Info "========================================="
$images = docker images --filter "reference=artemis/ubi8-*" --format "table {{.Repository}}:{{.Tag}}\t{{.Size}}\t{{.CreatedAt}}"
if ($LASTEXITCODE -eq 0 -and $images) {
Write-Info "Built images:"
Write-Host $images
Write-Info ""
}
# Verify .NET and PowerShell versions
Write-Info "========================================="
Write-Info "Verification"
Write-Info "========================================="
if (-not $BuildRuntimeOnly) {
Write-Info "Verifying SDK image..."
$sdkVersion = docker run --rm artemis/ubi8-dotnet-sdk:9.0 dotnet --version
if ($LASTEXITCODE -eq 0) {
Write-Success "SDK .NET version: $sdkVersion"
} else {
Write-Warning "Could not verify SDK .NET version"
}
}
if (-not $BuildSdkOnly) {
Write-Info "Verifying runtime image..."
# Note: Runtime images don't have SDK, so we use --list-runtimes instead of --version
$runtimeDotnetVersion = docker run --rm artemis/ubi8-aspnet-runtime:9.0 dotnet --list-runtimes
if ($LASTEXITCODE -eq 0) {
Write-Success "Runtime .NET runtimes installed:"
Write-Host $runtimeDotnetVersion
} else {
Write-Warning "Could not verify runtime .NET version"
}
$pwshVersion = docker run --rm artemis/ubi8-aspnet-runtime:9.0 pwsh -Command '$PSVersionTable.PSVersion.ToString()'
if ($LASTEXITCODE -eq 0) {
Write-Success "Runtime PowerShell version: $pwshVersion"
} else {
Write-Warning "Could not verify runtime PowerShell version"
}
}
Write-Info ""
Write-Success "========================================="
Write-Success "Base image build process completed!"
Write-Success "========================================="
Write-Info ""
Write-Info "Next steps:"
Write-Info "1. Run 'docker-compose build' to build the main Artemis API image"
Write-Info "2. Run 'docker-compose up' to start the application"
Write-Info ""
} catch {
Write-Error "Build process failed: $_"
Write-Error $_.ScriptStackTrace
exit 1
} finally {
Pop-Location
}