From c813d4a92203dd8071e8f8dbeb874c68840f0417 Mon Sep 17 00:00:00 2001 From: Gabriel Roldan Date: Wed, 9 Oct 2024 10:27:57 -0300 Subject: [PATCH] Build the GDAL base image and the geoserver images on top of it --- .github/workflows/build-and-push.yaml | 3 +- docker-build/base-images-multiplatform.yml | 45 ++++++++++++++++---- docker-build/base-images.yml | 45 ++++++++++++++++---- docker-build/templates.yml | 4 +- src/apps/base-images/gdal/Dockerfile | 28 +++++++++--- src/apps/base-images/geoserver/Dockerfile | 5 ++- src/apps/base-images/jre/Dockerfile | 3 +- src/apps/base-images/spring-boot/Dockerfile | 19 ++------- src/apps/geoserver/gwc/Dockerfile | 4 +- src/apps/geoserver/restconfig/Dockerfile | 4 +- src/apps/geoserver/wcs/Dockerfile | 4 +- src/apps/geoserver/webui/Dockerfile | 4 +- src/apps/geoserver/wfs/Dockerfile | 4 +- src/apps/geoserver/wms/Dockerfile | 4 +- src/apps/geoserver/wps/Dockerfile | 4 +- src/apps/infrastructure/admin/Dockerfile | 5 ++- src/apps/infrastructure/config/Dockerfile | 5 ++- src/apps/infrastructure/discovery/Dockerfile | 5 ++- src/apps/infrastructure/gateway/Dockerfile | 5 ++- 19 files changed, 136 insertions(+), 64 deletions(-) diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml index f29b3d025..694266024 100644 --- a/.github/workflows/build-and-push.yaml +++ b/.github/workflows/build-and-push.yaml @@ -6,12 +6,14 @@ on: branches: - main - "release/**" + - "docker-gdal" paths: - "Makefile" - "pom.xml" - ".github/workflows/build-and-push.yaml" - "config" - "src/**" + - "docker-build/**" tags: - '*' @@ -35,7 +37,6 @@ jobs: - 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 diff --git a/docker-build/base-images-multiplatform.yml b/docker-build/base-images-multiplatform.yml index 58d728caa..65314e160 100644 --- a/docker-build/base-images-multiplatform.yml +++ b/docker-build/base-images-multiplatform.yml @@ -1,26 +1,55 @@ services: - base-image-jre: + # Base JRE image, ubuntu 24.04, jre 21 temurin + jre: extends: file: templates.yml service: multi-platform - image: ${REPOSITORY}/gs-cloud-base-jre:${TAG} + image: ${REPOSITORY}/jre:21-tem build: context: ../src/apps/base-images/jre/ - base-image-spring-boot: + # Base JRE image with libgdal-java + jre-gdal: extends: file: templates.yml service: multi-platform - image: ${REPOSITORY}/gs-cloud-base-spring-boot:${TAG} - depends_on: [base-image-jre] + image: ${REPOSITORY}/jre-gdal:21-3.8.4 + depends_on: [jre] + build: + context: ../src/apps/base-images/gdal/ + args: + JRE_BASE_IMAGE_NAME: jre:21-tem + + # Base JRE + Spring Boot common layer for infra services + spring-boot-common: + extends: + file: templates.yml + service: multi-platform + image: ${REPOSITORY}/spring-boot-common:${TAG} + depends_on: [jre] + build: + context: ../src/apps/base-images/spring-boot/ + args: + JRE_BASE_IMAGE_NAME: jre:21-tem + + # Base JRE + GDAL + Spring Boot common layer for GeoServer services + spring-boot-common-gdal: + extends: + file: templates.yml + service: multi-platform + image: ${REPOSITORY}/spring-boot-common-gdal:${TAG} + depends_on: [jre-gdal] build: context: ../src/apps/base-images/spring-boot/ + args: + JRE_BASE_IMAGE_NAME: jre-gdal:21-3.8.4 - base-image-geoserver: + # Base JRE + GDAL + Spring Boot + shared GeoServer dependencies layer for GeoServer services + geoserver-common: extends: file: templates.yml service: multi-platform - image: ${REPOSITORY}/gs-cloud-base-geoserver-image:${TAG} - depends_on: [base-image-spring-boot] + image: ${REPOSITORY}/geoserver-common:${TAG} + depends_on: [spring-boot-common-gdal] build: context: ../src/apps/base-images/geoserver/ diff --git a/docker-build/base-images.yml b/docker-build/base-images.yml index bf51d8a90..37a0d43cb 100644 --- a/docker-build/base-images.yml +++ b/docker-build/base-images.yml @@ -1,26 +1,55 @@ services: - base-image-jre: + # Base JRE image, ubuntu 24.04, jre 21 temurin + jre: extends: file: templates.yml service: current-platform - image: ${REPOSITORY}/gs-cloud-base-jre:${TAG} + image: ${REPOSITORY}/jre:21-tem build: context: ../src/apps/base-images/jre/ - base-image-spring-boot: + # Base JRE image with libgdal-java + jre-gdal: extends: file: templates.yml service: current-platform - image: ${REPOSITORY}/gs-cloud-base-spring-boot:${TAG} - depends_on: [base-image-jre] + image: ${REPOSITORY}/jre-gdal:21-3.8.4 + depends_on: [jre] + build: + context: ../src/apps/base-images/gdal/ + args: + JRE_BASE_IMAGE_NAME: jre:21-tem + + # Base JRE + Spring Boot common layer for infra services + spring-boot-common: + extends: + file: templates.yml + service: current-platform + image: ${REPOSITORY}/spring-boot-common:${TAG} + depends_on: [jre] + build: + context: ../src/apps/base-images/spring-boot/ + args: + JRE_BASE_IMAGE_NAME: jre:21-tem + + # Base JRE + GDAL + Spring Boot common layer for GeoServer services + spring-boot-common-gdal: + extends: + file: templates.yml + service: current-platform + image: ${REPOSITORY}/spring-boot-common-gdal:${TAG} + depends_on: [jre-gdal] build: context: ../src/apps/base-images/spring-boot/ + args: + JRE_BASE_IMAGE_NAME: jre-gdal:21-3.8.4 - base-image-geoserver: + # Base JRE + GDAL + Spring Boot + shared GeoServer dependencies layer for GeoServer services + geoserver-common: extends: file: templates.yml service: current-platform - image: ${REPOSITORY}/gs-cloud-base-geoserver-image:${TAG} - depends_on: [base-image-spring-boot] + image: ${REPOSITORY}/geoserver-common:${TAG} + depends_on: [spring-boot-common-gdal] build: context: ../src/apps/base-images/geoserver/ diff --git a/docker-build/templates.yml b/docker-build/templates.yml index f3a42495a..9ab57d6ce 100644 --- a/docker-build/templates.yml +++ b/docker-build/templates.yml @@ -2,7 +2,7 @@ services: current-platform: build: no_cache: true - pull: true + #pull: true context: override-me args: TAG: ${TAG} @@ -11,7 +11,7 @@ services: multi-platform: build: no_cache: true - pull: true + #pull: true context: override-me platforms: - linux/amd64 diff --git a/src/apps/base-images/gdal/Dockerfile b/src/apps/base-images/gdal/Dockerfile index c423e5bdd..85e38db46 100644 --- a/src/apps/base-images/gdal/Dockerfile +++ b/src/apps/base-images/gdal/Dockerfile @@ -1,7 +1,9 @@ -#FROM geoservercloud/gs-cloud-base-jre:$TAG as builder -FROM eclipse-temurin:11-jdk as builder +ARG REPOSITORY=geoservercloud +ARG JRE_BASE_IMAGE_NAME=jre:21-tem +ARG TAG=latest -LABEL maintainer="GeoServer PSC " +# Build with java 11 +FROM eclipse-temurin:11-jdk as builder ENV GDAL_VERSION 3.8.4 ENV GDAL_PATH /usr/share/gdal @@ -24,5 +26,21 @@ RUN wget https://download.osgeo.org/gdal/${GDAL_VERSION}/gdal-${GDAL_VERSION}.ta sed -i 's/target="7"/target="8"/' /tmp/gdal-${GDAL_VERSION}/swig/java/build.xml RUN cd /tmp/gdal-${GDAL_VERSION} && mkdir build && cd build && cmake .. && cmake --build . && cmake --build . --target install -RUN cp /tmp/gdal-3.8.4/build/swig/java/gdal.jar /tmp/gdal.jar -RUN cp /tmp/gdal-3.8.4/build/swig/java/libgdalalljni.so /tmp/libgdalalljni.so +RUN mkdir /tmp/gdal-java +RUN cp /tmp/gdal-3.8.4/build/swig/java/gdal.jar /tmp/gdal-java/gdal.jar +RUN cp /tmp/gdal-3.8.4/build/swig/java/libgdalalljni.so /tmp/gdal-java/libgdalalljni.so + +########## +FROM $REPOSITORY/$JRE_BASE_IMAGE_NAME + +ENV GDAL_PATH /usr/share/gdal +ENV GDAL_DATA $GDAL_PATH +ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:$GDAL_PATH/lib:/usr/local/lib/:/usr/lib/ + +# see https://docs.docker.com/build/cache/optimize/#use-cache-mounts +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt update && apt-get --no-install-recommends install -y gdal-bin \ + && mkdir $GDAL_PATH/lib + +COPY --from=builder /tmp/gdal-java/* $GDAL_PATH/lib/ diff --git a/src/apps/base-images/geoserver/Dockerfile b/src/apps/base-images/geoserver/Dockerfile index be7c14730..3b463bf3f 100644 --- a/src/apps/base-images/geoserver/Dockerfile +++ b/src/apps/base-images/geoserver/Dockerfile @@ -1,7 +1,8 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG AS builder +FROM eclipse-temurin:21-jre-noble AS builder + ARG JAR_FILE=target/gs-cloud-*-bin.jar RUN apt update && apt install -y --no-install-recommends unzip @@ -15,7 +16,7 @@ RUN java -Djarmode=layertools -jar application.jar extract # rm /tmp/YourKit-JavaProfiler-2023.9-docker.zip ########## -FROM $REPOSITORY/gs-cloud-base-spring-boot:$TAG +FROM $REPOSITORY/spring-boot-common-gdal:$TAG # init RUN apt update \ diff --git a/src/apps/base-images/jre/Dockerfile b/src/apps/base-images/jre/Dockerfile index 8eeedd1d1..870d00c6b 100644 --- a/src/apps/base-images/jre/Dockerfile +++ b/src/apps/base-images/jre/Dockerfile @@ -1,4 +1,5 @@ -FROM eclipse-temurin:21-jre +# JRE 21 on Ubuntu 24.04 +FROM eclipse-temurin:21-jre-noble LABEL maintainer="GeoServer PSC " diff --git a/src/apps/base-images/spring-boot/Dockerfile b/src/apps/base-images/spring-boot/Dockerfile index dba590c12..2b76dd784 100644 --- a/src/apps/base-images/spring-boot/Dockerfile +++ b/src/apps/base-images/spring-boot/Dockerfile @@ -1,7 +1,8 @@ ARG REPOSITORY=geoservercloud +ARG JRE_BASE_IMAGE_NAME=jre:21-tem ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG AS builder +FROM eclipse-temurin:21-jre-noble AS builder ARG JAR_FILE=target/gs-cloud-*-bin.jar @@ -10,7 +11,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-jre:$TAG +FROM $REPOSITORY/$JRE_BASE_IMAGE_NAME COPY target/config/ /etc/geoserver/ @@ -18,18 +19,6 @@ RUN mkdir -p /opt/app/bin WORKDIR /opt/app/bin -ENV JAVA_TOOL_OPTS="\ ---add-exports=java.desktop/sun.awt.image=ALL-UNNAMED \ ---add-opens=java.base/java.lang=ALL-UNNAMED \ ---add-opens=java.base/java.util=ALL-UNNAMED \ ---add-opens=java.base/java.lang.reflect=ALL-UNNAMED \ ---add-opens=java.base/java.text=ALL-UNNAMED \ ---add-opens=java.desktop/java.awt.font=ALL-UNNAMED \ ---add-opens=java.desktop/sun.awt.image=ALL-UNNAMED \ ---add-opens=java.naming/com.sun.jndi.ldap=ALL-UNNAMED \ --Djava.awt.headless=true" - -ENV JAVA_OPTS= EXPOSE 8080 EXPOSE 8081 @@ -44,4 +33,4 @@ HEALTHCHECK \ --retries=5 \ CMD curl -f -s -o /dev/null localhost:8081/actuator/health || exit 1 -CMD exec env USER_ID="$(id -u)" USER_GID="$(id -g)" java $JAVA_OPTS $JAVA_TOOL_OPTS org.springframework.boot.loader.JarLauncher +CMD exec env USER_ID="$(id -u)" USER_GID="$(id -g)" java $JAVA_OPTS org.springframework.boot.loader.JarLauncher diff --git a/src/apps/geoserver/gwc/Dockerfile b/src/apps/geoserver/gwc/Dockerfile index 851d7cbb6..cd8027887 100644 --- a/src/apps/geoserver/gwc/Dockerfile +++ b/src/apps/geoserver/gwc/Dockerfile @@ -1,7 +1,7 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG as builder +FROM eclipse-temurin:21-jre-noble AS builder ARG JAR_FILE=target/gs-cloud-*-bin.jar @@ -10,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-geoserver-image:$TAG +FROM $REPOSITORY/spring-boot-common-gdal:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/geoserver/restconfig/Dockerfile b/src/apps/geoserver/restconfig/Dockerfile index 851d7cbb6..cd8027887 100644 --- a/src/apps/geoserver/restconfig/Dockerfile +++ b/src/apps/geoserver/restconfig/Dockerfile @@ -1,7 +1,7 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG as builder +FROM eclipse-temurin:21-jre-noble AS builder ARG JAR_FILE=target/gs-cloud-*-bin.jar @@ -10,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-geoserver-image:$TAG +FROM $REPOSITORY/spring-boot-common-gdal:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/geoserver/wcs/Dockerfile b/src/apps/geoserver/wcs/Dockerfile index 851d7cbb6..cd8027887 100644 --- a/src/apps/geoserver/wcs/Dockerfile +++ b/src/apps/geoserver/wcs/Dockerfile @@ -1,7 +1,7 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG as builder +FROM eclipse-temurin:21-jre-noble AS builder ARG JAR_FILE=target/gs-cloud-*-bin.jar @@ -10,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-geoserver-image:$TAG +FROM $REPOSITORY/spring-boot-common-gdal:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/geoserver/webui/Dockerfile b/src/apps/geoserver/webui/Dockerfile index 851d7cbb6..cd8027887 100644 --- a/src/apps/geoserver/webui/Dockerfile +++ b/src/apps/geoserver/webui/Dockerfile @@ -1,7 +1,7 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG as builder +FROM eclipse-temurin:21-jre-noble AS builder ARG JAR_FILE=target/gs-cloud-*-bin.jar @@ -10,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-geoserver-image:$TAG +FROM $REPOSITORY/spring-boot-common-gdal:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/geoserver/wfs/Dockerfile b/src/apps/geoserver/wfs/Dockerfile index 851d7cbb6..cd8027887 100644 --- a/src/apps/geoserver/wfs/Dockerfile +++ b/src/apps/geoserver/wfs/Dockerfile @@ -1,7 +1,7 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG as builder +FROM eclipse-temurin:21-jre-noble AS builder ARG JAR_FILE=target/gs-cloud-*-bin.jar @@ -10,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-geoserver-image:$TAG +FROM $REPOSITORY/spring-boot-common-gdal:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/geoserver/wms/Dockerfile b/src/apps/geoserver/wms/Dockerfile index 851d7cbb6..cd8027887 100644 --- a/src/apps/geoserver/wms/Dockerfile +++ b/src/apps/geoserver/wms/Dockerfile @@ -1,7 +1,7 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG as builder +FROM eclipse-temurin:21-jre-noble AS builder ARG JAR_FILE=target/gs-cloud-*-bin.jar @@ -10,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-geoserver-image:$TAG +FROM $REPOSITORY/spring-boot-common-gdal:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/geoserver/wps/Dockerfile b/src/apps/geoserver/wps/Dockerfile index 851d7cbb6..cd8027887 100644 --- a/src/apps/geoserver/wps/Dockerfile +++ b/src/apps/geoserver/wps/Dockerfile @@ -1,7 +1,7 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG as builder +FROM eclipse-temurin:21-jre-noble AS builder ARG JAR_FILE=target/gs-cloud-*-bin.jar @@ -10,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-geoserver-image:$TAG +FROM $REPOSITORY/spring-boot-common-gdal:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/infrastructure/admin/Dockerfile b/src/apps/infrastructure/admin/Dockerfile index 2e6762f69..6e34893e2 100644 --- a/src/apps/infrastructure/admin/Dockerfile +++ b/src/apps/infrastructure/admin/Dockerfile @@ -1,7 +1,8 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG AS builder +FROM eclipse-temurin:21-jre-noble AS builder + ARG JAR_FILE=target/gs-cloud-*-bin.jar COPY ${JAR_FILE} application.jar @@ -9,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-spring-boot:$TAG +FROM $REPOSITORY/spring-boot-common:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/infrastructure/config/Dockerfile b/src/apps/infrastructure/config/Dockerfile index 0c1a0e3fb..8a1935871 100644 --- a/src/apps/infrastructure/config/Dockerfile +++ b/src/apps/infrastructure/config/Dockerfile @@ -1,7 +1,8 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG AS builder +FROM eclipse-temurin:21-jre-noble AS builder + ARG JAR_FILE=target/gs-cloud-*-bin.jar COPY ${JAR_FILE} application.jar @@ -9,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-spring-boot:$TAG +FROM $REPOSITORY/spring-boot-common:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/infrastructure/discovery/Dockerfile b/src/apps/infrastructure/discovery/Dockerfile index d16b5892c..ecc3c1b48 100644 --- a/src/apps/infrastructure/discovery/Dockerfile +++ b/src/apps/infrastructure/discovery/Dockerfile @@ -1,7 +1,8 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG AS builder +FROM eclipse-temurin:21-jre-noble AS builder + ARG JAR_FILE=target/gs-cloud-*-bin.jar COPY ${JAR_FILE} application.jar @@ -9,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-spring-boot:$TAG +FROM $REPOSITORY/spring-boot-common:$TAG # WORKDIR already set to /opt/app/bin diff --git a/src/apps/infrastructure/gateway/Dockerfile b/src/apps/infrastructure/gateway/Dockerfile index d16b5892c..ecc3c1b48 100644 --- a/src/apps/infrastructure/gateway/Dockerfile +++ b/src/apps/infrastructure/gateway/Dockerfile @@ -1,7 +1,8 @@ ARG REPOSITORY=geoservercloud ARG TAG=latest -FROM $REPOSITORY/gs-cloud-base-jre:$TAG AS builder +FROM eclipse-temurin:21-jre-noble AS builder + ARG JAR_FILE=target/gs-cloud-*-bin.jar COPY ${JAR_FILE} application.jar @@ -9,7 +10,7 @@ COPY ${JAR_FILE} application.jar RUN java -Djarmode=layertools -jar application.jar extract ########## -FROM $REPOSITORY/gs-cloud-base-spring-boot:$TAG +FROM $REPOSITORY/spring-boot-common:$TAG # WORKDIR already set to /opt/app/bin