Skip to content

Commit 770557e

Browse files
committed
move build step to Dockerfile
1 parent e061afb commit 770557e

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

.github/actions/docker-build-or-tag/action.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,14 @@ runs:
4646
- name: Set up Docker Buildx
4747
uses: docker/setup-buildx-action@v3
4848

49-
- name: Set up JDK 17
50-
uses: actions/setup-java@v3
51-
with:
52-
java-version: '17'
53-
distribution: 'corretto'
54-
cache: maven
55-
56-
- name: Build with Maven
57-
run: mvn clean package -DskipTests
58-
shell: bash
59-
6049
- name: Build and push
6150
uses: docker/build-push-action@v6
6251
with:
6352
push: true
6453
platforms: linux/amd64,linux/arm64
6554
context: ${{ inputs.dockerfile-dir }}
55+
cache-from: type=gha
56+
cache-to: type=gha,mode=max
6657
tags: |
6758
ghcr.io/januschung/${{ inputs.image-name }}:${{ env.COMMIT_SHA }}
6859
ghcr.io/januschung/${{ inputs.image-name }}:latest

Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1+
# Stage 1: build the application
2+
FROM maven:3.9.4-eclipse-temurin-17 AS build
3+
WORKDIR /workspace
4+
COPY pom.xml ./
5+
COPY .mvn .mvn
6+
# use BuildKit cache for Maven repo
7+
RUN --mount=type=cache,target=/root/.m2 mvn -B -DskipTests dependency:go-offline
8+
COPY src ./src
9+
RUN --mount=type=cache,target=/root/.m2 mvn -B -DskipTests package
10+
11+
# Stage 2: runtime image
112
FROM amazoncorretto:17-alpine3.21
2-
COPY target/*.jar app.jar
13+
WORKDIR /app
14+
COPY --from=build /workspace/target/*.jar app.jar
315
EXPOSE 8080
416
ENTRYPOINT ["java", "-jar", "/app.jar"]

0 commit comments

Comments
 (0)