From a267157d24676a7878adca20bbb18bd6f1acccaa Mon Sep 17 00:00:00 2001 From: Guillaume Galy Date: Tue, 11 Apr 2023 18:42:33 +0200 Subject: [PATCH] chore: Execute Maven build outside of Docker build --- .dockerignore | 2 -- .github/workflows/build.yml | 11 ++++------- Dockerfile | 20 +++++++------------- 3 files changed, 11 insertions(+), 22 deletions(-) delete mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 342ee83..0000000 --- a/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -target/ -Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ad9964b..2dec54f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,13 +35,10 @@ jobs: with: distribution: 'zulu' java-version: '17' + cache: 'maven' - - name: Cache Maven - uses: actions/cache@v3 - with: - path: | - ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + - name: Build Maven + run: mvn --batch-mode clean package - name: Configure AWS credentials if: github.ref == 'refs/heads/main' @@ -66,7 +63,7 @@ jobs: docker build \ --tag ${ECR_REGISTRY:-dummy}/$ECR_REPOSITORY:$IMAGE_VERSION \ --file Dockerfile \ - . + ./target - name: Docker push if: github.ref == 'refs/heads/main' diff --git a/Dockerfile b/Dockerfile index f2a4063..136d787 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,20 @@ -FROM maven:3-openjdk-17 AS builder +FROM gatlingcorp/openjdk-base:17-jre-headless AS builder -COPY ./pom.xml /build/pom.xml +COPY ./demo-store-*.jar /app/demo-store.jar -WORKDIR /build - -RUN mvn --batch-mode dependency:resolve - -COPY . /build - -RUN mvn --batch-mode clean package - -RUN chmod -R g=u /build/target/demo-store-*.jar +# Doing this modifies a lot of files, duplicating the content of /app in two layers: COPY above and RUN below, +# hence the builder image. +RUN chmod -R g=u /app FROM gatlingcorp/openjdk-base:17-jre-headless LABEL gatling="demostore" -COPY --from=builder --chown=1001:0 /build/target/demo-store-*.jar /app/demo-store.jar +COPY --from=builder --chown=1001:0 /app /app WORKDIR /app ENV HOME=/app USER 1001 EXPOSE 8080 -ENTRYPOINT ["java", "-jar", "./demo-store.jar"] +ENTRYPOINT ["java", "-jar", "/app/demo-store.jar"] CMD []