diff --git a/.github/actions/docker-build-or-tag/action.yml b/.github/actions/docker-build-or-tag/action.yml index 9d7fed47..ebdffb84 100644 --- a/.github/actions/docker-build-or-tag/action.yml +++ b/.github/actions/docker-build-or-tag/action.yml @@ -46,23 +46,14 @@ runs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'corretto' - cache: maven - - - name: Build with Maven - run: mvn clean package -DskipTests - shell: bash - - name: Build and push uses: docker/build-push-action@v6 with: push: true platforms: linux/amd64,linux/arm64 context: ${{ inputs.dockerfile-dir }} + cache-from: type=gha + cache-to: type=gha,mode=max tags: | ghcr.io/januschung/${{ inputs.image-name }}:${{ env.COMMIT_SHA }} ghcr.io/januschung/${{ inputs.image-name }}:latest diff --git a/Dockerfile b/Dockerfile index bec730d4..7acb5ed6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,16 @@ +# Stage 1: build the application +FROM maven:3.9.4-eclipse-temurin-17 AS build +WORKDIR /workspace +COPY pom.xml ./ +COPY .mvn .mvn +# use BuildKit cache for Maven repo +RUN --mount=type=cache,target=/root/.m2 mvn -B -DskipTests dependency:go-offline +COPY src ./src +RUN --mount=type=cache,target=/root/.m2 mvn -B -DskipTests package + +# Stage 2: runtime image FROM amazoncorretto:17-alpine3.21 -COPY target/*.jar app.jar +WORKDIR /app +COPY --from=build /workspace/target/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "/app.jar"]