From 324610e25421b6ab8136ac1d8d46407e3298f4d9 Mon Sep 17 00:00:00 2001 From: Antonio Cerciello Date: Wed, 18 Sep 2024 18:36:02 +0200 Subject: [PATCH] Multistage build --- .github/workflows/docker-image.yml | 15 ++------------- georoma/Dockerfile => Dockerfile | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 16 deletions(-) rename georoma/Dockerfile => Dockerfile (71%) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index bb730388faad..b90d4ac7f5ba 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -28,18 +28,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - uses: actions/setup-java@v4 - with: - java-version: '11' - distribution: 'temurin' - architecture: x64 - cache: maven - - - run: mvn install --batch-mode --update-snapshots -DskipTests - - - run: mkdir staging && cp web/target/geonetwork.war staging - - - name: Log in to the Container registry + - name: Log in to the Container registry uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d with: registry: ${{ env.REGISTRY }} @@ -55,7 +44,7 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 with: - context: ./georoma + context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/georoma/Dockerfile b/Dockerfile similarity index 71% rename from georoma/Dockerfile rename to Dockerfile index 34cc8176dd74..2441e56f5268 100755 --- a/georoma/Dockerfile +++ b/Dockerfile @@ -1,3 +1,13 @@ +# +# Build stage +# +FROM maven:3.6.0-jdk-11-slim AS build +COPY ./ /home/app +RUN mvn -f /home/app/pom.xml clean install + +# +# Package stage +# FROM tomcat:8.5-jdk11 ENV GN_FILE geonetwork.war @@ -17,17 +27,17 @@ RUN apt-get -y update && \ curl \ unzip -COPY ./staging/geonetwork.war geonetwork.war +COPY --from=build /home/app/web/target/geonetwork.war geonetwork.war RUN mkdir -p geonetwork && \ unzip -e $GN_FILE -d geonetwork && \ rm $GN_FILE # To enable AJP and support for traefik headers -COPY ./server.xml $CATALINA_HOME/conf/server.xml +COPY ./georoma/server.xml $CATALINA_HOME/conf/server.xml #Set geonetwork data dir -COPY ./docker-entrypoint.sh /entrypoint.sh +COPY ./georoma/docker-entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh