Skip to content

Commit bb8b4aa

Browse files
committed
Build most images with Gradle instead of dockerfiles, move Spring Boot version to metadata
- add build.ps1 to workflow triggers - remove bash script
1 parent 8751fcd commit bb8b4aa

File tree

15 files changed

+136
-222
lines changed

15 files changed

+136
-222
lines changed

.github/workflows/build_config_server.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ on:
77
paths:
88
- '.github/workflows/build_config_server.yaml'
99
- 'config-server/**'
10+
- 'build.ps1'
1011
push:
1112
branches:
1213
- main
1314
paths:
1415
- '.github/workflows/build_config_server.yaml'
1516
- 'config-server/**'
17+
- 'build.ps1'
1618

1719
concurrency:
1820
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -37,7 +39,7 @@ jobs:
3739
run: ./build.ps1 -Name '${{ env.IMAGE_NAME }}' -Registry '${{ env.REGISTRY }}' -Tag '${{ env.TAG }}'
3840
shell: pwsh
3941
env:
40-
TAG: ${{ github.event_name == 'pull_request' && format('-t {0}/{1}:pr-{2}', env.REGISTRY, env.IMAGE_NAME, github.event.number) || '' }}
42+
TAG: ${{ github.event_name == 'pull_request' && format('{0}/{1}:pr-{2}', env.REGISTRY, env.IMAGE_NAME, github.event.number) || '' }}
4143

4244
- name: Login to container registry
4345
uses: docker/login-action@v3

.github/workflows/build_eureka_server.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ on:
77
paths:
88
- '.github/workflows/build_eureka_server.yaml'
99
- 'eureka-server/**'
10+
- 'build.ps1'
1011
push:
1112
branches:
1213
- main
1314
paths:
1415
- '.github/workflows/build_eureka_server.yaml'
1516
- 'eureka-server/**'
17+
- 'build.ps1'
1618

1719
concurrency:
1820
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -37,7 +39,7 @@ jobs:
3739
run: ./build.ps1 -Name '${{ env.IMAGE_NAME }}' -Registry '${{ env.REGISTRY }}' -Tag '${{ env.TAG }}'
3840
shell: pwsh
3941
env:
40-
TAG: ${{ github.event_name == 'pull_request' && format('-t {0}/{1}:pr-{2}', env.REGISTRY, env.IMAGE_NAME, github.event.number) || '' }}
42+
TAG: ${{ github.event_name == 'pull_request' && format('{0}/{1}:pr-{2}', env.REGISTRY, env.IMAGE_NAME, github.event.number) || '' }}
4143

4244
- name: Login to container registry
4345
uses: docker/login-action@v3

.github/workflows/build_springboot_admin_server.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ on:
77
paths:
88
- '.github/workflows/build_springboot_admin_server.yaml'
99
- 'spring-boot-admin/**'
10+
- 'build.ps1'
1011
push:
1112
branches:
1213
- main
1314
paths:
1415
- '.github/workflows/build_springboot_admin_server.yaml'
1516
- 'spring-boot-admin/**'
17+
- 'build.ps1'
1618

1719
concurrency:
1820
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -37,7 +39,7 @@ jobs:
3739
run: ./build.ps1 -Name '${{ env.IMAGE_NAME }}' -Registry '${{ env.REGISTRY }}' -Tag '${{ env.TAG }}'
3840
shell: pwsh
3941
env:
40-
TAG: ${{ github.event_name == 'pull_request' && format('-t {0}/{1}:pr-{2}', env.REGISTRY, env.IMAGE_NAME, github.event.number) || '' }}
42+
TAG: ${{ github.event_name == 'pull_request' && format('{0}/{1}:pr-{2}', env.REGISTRY, env.IMAGE_NAME, github.event.number) || '' }}
4143

4244
- name: Login to container registry
4345
uses: docker/login-action@v3

.github/workflows/build_uaa_server.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ on:
77
paths:
88
- '.github/workflows/build_uaa_server.yaml'
99
- 'uaa-server/**'
10+
- 'build.ps1'
1011
push:
1112
branches:
1213
- main
1314
paths:
1415
- '.github/workflows/build_uaa_server.yaml'
1516
- 'uaa-server/**'
17+
- 'build.ps1'
1618

1719
concurrency:
1820
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -37,7 +39,7 @@ jobs:
3739
run: ./build.ps1 -Name '${{ env.IMAGE_NAME }}' -Registry '${{ env.REGISTRY }}' -Tag '${{ env.TAG }}'
3840
shell: pwsh
3941
env:
40-
TAG: ${{ github.event_name == 'pull_request' && format('-t {0}/{1}:pr-{2}', env.REGISTRY, env.IMAGE_NAME, github.event.number) || '' }}
42+
TAG: ${{ github.event_name == 'pull_request' && format('{0}/{1}:pr-{2}', env.REGISTRY, env.IMAGE_NAME, github.event.number) || '' }}
4143

4244
- name: Login to container registry
4345
uses: docker/login-action@v3

build-with-gradle.sh

Lines changed: 0 additions & 67 deletions
This file was deleted.

build.ps1

Lines changed: 118 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ $ImagesDirectory = Split-Path -Parent $PSCommandPath
7676

7777
if ($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-
10599
if (!$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)
124118
else
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+
}

config-server/Dockerfile

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-t config-server:4.3 -t config-server:4 -t config-server:latest
1+
config-server:4.3 config-server:4 config-server:latest
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.5.6

0 commit comments

Comments
 (0)