Parallelize Docker image builds and optimize disk space usage

Split build workflow into separate jobs: base images build first, then
infrastructure and GeoServer images build in parallel. Each job packages
only its required modules. Signing moved to dedicated job that runs once
after all builds complete. Sign all builds including SNAPSHOTs to catch
issues early.
This commit is contained in:
Gabriel Roldan 2025-10-01 12:47:20 -03:00
parent 736bc5eaed
commit efbe292174
No known key found for this signature in database
GPG Key ID: 697E8F9DF72128E1
2 changed files with 129 additions and 33 deletions

View File

@ -15,16 +15,16 @@ on:
- "src/**"
tags:
- '*'
# cancel in-progress jobs or runs for the current workflow
# cancel in-progress jobs or runs for the current workflow
# see https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/control-the-concurrency-of-workflows-and-jobs#example-only-cancel-in-progress-jobs-or-runs-for-the-current-workflow
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
base-images:
if: github.repository == 'geoserver/geoserver-cloud'
name: Build and Push
name: Build and Push Base Images
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
@ -34,17 +34,13 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# Add support for more platforms with QEMU
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# https://github.com/docker/setup-buildx-action
with:
platforms: linux/amd64,linux/arm64
# Sets up docker build command as an alias to docker buildx
install: true
- name: Checkout
@ -59,47 +55,148 @@ jobs:
java-version: '21'
cache: 'maven'
- name: Build application packages
- name: Package base images
run: |
make package
- name: Clean up Maven project artifacts
run: |
rm -rf ~/.m2/repository/org/geoserver
find ~/.m2/repository -name "*SNAPSHOT*" -type d -exec rm -rf {} + 2>/dev/null || true
echo "Disk space after Maven cleanup:"
df -h
make package-base-images
- name: Build and push base images
run: |
REPACKAGE=false make build-base-images-multiplatform
- name: Clean up Docker build cache after base images
- name: Clean up Maven project artifacts
run: |
docker buildx prune --force
echo "Disk space after base images:"
df -h
rm -rf ~/.m2/repository/org/geoserver
find ~/.m2/repository -name "*SNAPSHOT*" -type d -exec rm -rf {} + 2>/dev/null || true
- name: Build and push images for infra services
infrastructure-images:
needs: base-images
if: github.repository == 'geoserver/geoserver-cloud'
name: Build and Push Infrastructure Images
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
install: true
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- name: Package infrastructure apps
run: |
make package-infrastructure-images
- name: Build and push infrastructure images
run: |
REPACKAGE=false make build-image-infrastructure-multiplatform
- name: Clean up Docker build cache after infra images
- name: Clean up Maven project artifacts
run: |
docker buildx prune --force
echo "Disk space after infra images:"
df -h
rm -rf ~/.m2/repository/org/geoserver
find ~/.m2/repository -name "*SNAPSHOT*" -type d -exec rm -rf {} + 2>/dev/null || true
- name: Build and push images for GeoServer services
geoserver-images:
needs: base-images
if: github.repository == 'geoserver/geoserver-cloud'
name: Build and Push GeoServer Images
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
install: true
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- name: Package GeoServer apps
run: |
REPACKAGE=false make build-image-geoserver-multiplatform
make package-geoserver-images
- name: Build and push GeoServer images
run: |
make build-image-geoserver-multiplatform
- name: Clean up Maven project artifacts
run: |
rm -rf ~/.m2/repository/org/geoserver
find ~/.m2/repository -name "*SNAPSHOT*" -type d -exec rm -rf {} + 2>/dev/null || true
sign-images:
needs: [base-images, infrastructure-images, geoserver-images]
if: github.repository == 'geoserver/geoserver-cloud'
name: Sign and Verify Images
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Pull all images
run: |
TAG=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
for image in config discovery gateway gwc rest wcs webui wfs wms wps; do
docker pull geoservercloud/geoserver-cloud-$image:$TAG
done
- name: Install Cosign
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: sigstore/cosign-installer@v3.5.0
- name: Sign images
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
@ -107,7 +204,6 @@ jobs:
make sign-image
- name: Verify image signatures
if: ${{ startsWith(github.ref, 'refs/tags/') }}
env:
COSIGN_PUB_KEY: ${{ secrets.COSIGN_PUB_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}

View File

@ -105,7 +105,7 @@ build-image-geoserver-multiplatform: package-geoserver-images
.PHONY: package-base-images
package-base-images:
ifeq ($(REPACKAGE), true)
./mvnw clean package -f src/apps/base-images -DskipTests -T4
./mvnw clean package -DskipTests -T1C -nsu -am -pl src/apps/base-images/jre,src/apps/base-images/spring-boot,src/apps/base-images/spring-boot3,src/apps/base-images/geoserver
else
@echo "Not re-packaging base images, assuming the target/*-bin.jar files exist"
endif
@ -113,7 +113,7 @@ endif
.PHONY: package-infrastructure-images
package-infrastructure-images:
ifeq ($(REPACKAGE), true)
./mvnw clean package -f src/apps/infrastructure -DskipTests -T4
./mvnw clean package -DskipTests -T1C -nsu -am -pl src/apps/infrastructure/config,src/apps/infrastructure/discovery,src/apps/infrastructure/gateway
else
@echo "Not re-packaging infra images, assuming the target/*-bin.jar files exist"
endif
@ -121,7 +121,7 @@ endif
.PHONY: package-geoserver-images
package-geoserver-images:
ifeq ($(REPACKAGE), true)
./mvnw clean package -f src/apps/geoserver -DskipTests -T4
./mvnw clean package -DskipTests -T1C -nsu -am -pl src/apps/geoserver/gwc,src/apps/geoserver/restconfig,src/apps/geoserver/wcs,src/apps/geoserver/webui,src/apps/geoserver/wfs,src/apps/geoserver/wms,src/apps/geoserver/wcs,src/apps/geoserver/wps
else
@echo "Not re-packaging geoserver images, assuming the target/*-bin.jar files exist"
endif