@@ -76,7 +76,7 @@ $ImagesDirectory = Split-Path -Parent $PSCommandPath
7676
7777if ($List )
7878{
79- Get-Childitem - Path $ImagesDirectory - Directory | Where-Object { ! $_.Name.StartsWith (" ." ) } | Select-Object Name
79+ Get-ChildItem - Path $ImagesDirectory - Directory | Where-Object { ! $_.Name.StartsWith (" ." ) } | Select-Object Name
8080 return
8181}
8282
@@ -96,25 +96,19 @@ if (!(Get-Command "docker" -ErrorAction SilentlyContinue))
9696 throw " 'docker' command not found"
9797}
9898
99- $Dockerfile = Join-Path $ImageDirectory Dockerfile
100- if (! (Test-Path $Dockerfile ))
101- {
102- throw " No Dockerfile for $Name (expected $Dockerfile )"
103- }
104-
10599if (! $Tag )
106100{
107- if (Test-Path " $ImageDirectory / metadata" )
101+ if (Test-Path ( Join-Path $ImageDirectory " metadata" ) )
108102 {
109- $Tag = " -t $DockerOrg /$Name "
110- $Version = Get-Content " $ImageDirectory / metadata/ IMAGE_VERSION"
103+ $Tag = " $DockerOrg /$Name "
104+ $Version = Get-Content ( Join-Path $ImageDirectory " metadata" " IMAGE_VERSION" )
111105 $Tag += " :$Version "
112- $Revision = Get-Content " $ImageDirectory / metadata/ IMAGE_REVISION"
106+ $Revision = Get-Content ( Join-Path $ImageDirectory " metadata" " IMAGE_REVISION" )
113107 if ($Revision )
114108 {
115109 $Tag += " -$Revision "
116110 }
117- $Tag + = " $ ( Get-Content $ImageDirectory / metadata/ ADDITIONAL_TAGS | ForEach-Object { $_.replace (" $Name " , " $DockerOrg /$Name " ) }) "
111+ $AdditionalTags = " $ ( Get-Content ( Join-Path $ImageDirectory " metadata" " ADDITIONAL_TAGS" ) | ForEach-Object { $_.replace (" $Name " , " $DockerOrg /$Name " ) }) "
118112 }
119113 else
120114 {
@@ -124,8 +118,117 @@ if (!$Tag)
124118else
125119{
126120 Write-Host " Tag value set by script parameter:" $Tag
121+ $AdditionalTags = " "
122+ }
123+
124+ if ($Name -eq " uaa-server" )
125+ {
126+ $Dockerfile = Join-Path $ImageDirectory Dockerfile
127+ if (! (Test-Path $Dockerfile ))
128+ {
129+ throw " No Dockerfile for $Name (expected $Dockerfile )"
130+ }
131+
132+ $docker_command = " docker build -t $Tag $AdditionalTags $ImageDirectory --build-arg SERVER_VERSION=$Version "
133+ Write-Host $docker_command
134+ Invoke-Expression $docker_command
127135}
136+ else
137+ {
138+ if (! (Get-Command " patch" - ErrorAction SilentlyContinue))
139+ {
140+ if (Test-Path " C:\Program Files\Git\usr\bin\patch.exe" )
141+ {
142+ Write-Host " 'patch' command not found, but Git is installed; adding Git usr\bin to PATH"
143+ $env: Path += " ;C:\Program Files\Git\usr\bin"
144+ }
145+ else
146+ {
147+ throw " 'patch' command not found"
148+ }
149+ }
150+
151+ switch ($Name )
152+ {
153+ " config-server"
154+ {
155+ $appName = " ConfigServer"
156+ $dependencies = " cloud-config-server,actuator,cloud-eureka,security"
157+ }
158+ " eureka-server"
159+ {
160+ $appName = " EurekaServer"
161+ $dependencies = " cloud-eureka-server,actuator"
162+ }
163+ " spring-boot-admin"
164+ {
165+ $appName = " SpringBootAdmin"
166+ $dependencies = " codecentric-spring-boot-admin-server"
167+ }
168+ Default
169+ {
170+ Write-Host " $Name is not currently supported by this script"
171+ exit 2
172+ }
173+ }
174+ $serverName = $Name -replace ' -' , ' '
175+ $tempDir = " $Name -temp"
176+ $JVM = " 21"
177+ $bootVersion = Get-Content (Join-path $ImageDirectory " metadata" " SPRING_BOOT_VERSION" )
178+ $serverVersion = Get-Content (Join-Path $ImageDirectory " metadata" " IMAGE_VERSION" )
179+
180+ Write-Host " Building server: $serverName @$serverVersion on Spring Boot $bootVersion with primary tag: $Tag "
181+ Write-Host " Using source files in: $ImageDirectory | Working directory:" (Join-Path $PWD $tempDir )
182+
183+ # Ensure clean setup
184+ Remove-Item - Recurse - Force $tempDir - ErrorAction Ignore
185+ New-Item - ItemType Directory - Path $tempDir | Out-Null
186+ Set-Location $tempDir
187+
188+ Invoke-WebRequest `
189+ - Uri " https://start.spring.io/starter.zip" `
190+ - Method Post `
191+ - Body @ {
192+ type = " gradle-project"
193+ bootVersion = $bootVersion
194+ javaVersion = $JVM
195+ groupId = " io.steeltoe.docker"
196+ artifactId = $serverName
197+ applicationName = $appName
198+ language = " java"
199+ dependencies = $dependencies
200+ version = $serverVersion
201+ } `
202+ - OutFile " $serverName .zip"
203+
204+ New-Item - ItemType Directory - Path $serverName | Out-Null
205+ Expand-Archive - Path " $serverName .zip" - DestinationPath $serverName - Force
206+
207+ # Apply patches
208+ foreach ($patch in Get-ChildItem - Path (Join-Path $ImageDirectory patches) - Filter " *.patch" )
209+ {
210+ Write-Host " applying patch $ ( $patch.Name ) "
211+ Push-Location $serverName
212+ Get-Content $patch | & patch - p1
213+ Pop-Location
214+ }
215+
216+ # Build the image
217+ Push-Location $serverName
218+ $gradleArgs = @ (" bootBuildImage" , " --imageName=$Tag " )
219+
220+ if ($env: GITHUB_ACTIONS -eq " true" ) {
221+ $gradleArgs += " --no-daemon"
222+ }
223+
224+ ./ gradlew @gradleArgs
225+ Pop-Location
128226
129- $docker_command = " docker build $Tag $ImageDirectory --build-arg SERVER_VERSION=$Version "
130- Write-Host $docker_command
131- Invoke-Expression $docker_command
227+ foreach ($AdditionalTag in $AdditionalTags.Split (" " , [System.StringSplitOptions ]::RemoveEmptyEntries))
228+ {
229+ Write-Host " running 'docker tag $Tag $AdditionalTag '"
230+ docker tag $Tag $AdditionalTag
231+ }
232+
233+ Set-Location ..
234+ }
0 commit comments