Skip to content

Commit

Permalink
chore: update build + docker build and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
matteo-s committed Mar 26, 2024
1 parent 5e47826 commit 1c5c6e6
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
submodules: 'true'
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.5.1
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/update_cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
branches:
- main
paths:
- pom.xml
- '**.pom.xml'
- '**.package.json'
tags-ignore:
- "*"
env:
Expand All @@ -25,6 +26,7 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
submodules: 'true'
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.5.1
Expand Down
24 changes: 20 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ COPY frontend /tmp/frontend
COPY modules /tmp/modules
COPY pom.xml /tmp/pom.xml
WORKDIR /tmp
RUN --mount=type=cache,target=/root/.m2,source=/root/.m2,from=ghcr.io/scc-digitalhub/digitalhub-core:cache \
mvn package -DskipTests
RUN --mount=type=cache,target=/root/.m2,source=/cache/.m2,from=digitalhub-core:cache \
mvn install -pl modules/commons
RUN --mount=type=cache,target=/root/.m2,source=/cache/.m2,from=digitalhub-core:cache \
--mount=type=cache,target=/tmp/frontend/target,source=/cache/frontend/target,from=digitalhub-core:cache \
--mount=type=cache,target=/tmp/frontend/console/node_modules,source=/cache/frontend/console/node_modules,from=digitalhub-core:cache \
mvn install -pl frontend
RUN --mount=type=cache,target=/root/.m2,source=/cache/.m2,from=digitalhub-core:cache \
mvn package -DskipTests -pl '!frontend'

FROM maven:3-eclipse-temurin-21-alpine as builder
WORKDIR /tmp
COPY --from=build /tmp/application/target/*.jar /tmp/
RUN java -Djarmode=layertools -jar *.jar extract

FROM gcr.io/distroless/java21-debian12:nonroot
ENV APP=core.jar
WORKDIR /app
LABEL org.opencontainers.image.source=https://github.com/scc-digitalhub/digitalhub-core
COPY --from=build /tmp/application/target/*.jar /app/${APP}
COPY --from=builder /tmp/dependencies/ ./
COPY --from=builder /tmp/snapshot-dependencies/ ./
COPY --from=builder /tmp/spring-boot-loader/ ./
COPY --from=builder /tmp/dh-dependencies/ ./
COPY --from=builder /tmp/application/ ./
EXPOSE 8080
CMD ["/app/core.jar"]
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
6 changes: 5 additions & 1 deletion Dockerfile-cache
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ COPY modules /tmp/modules
COPY pom.xml /tmp/pom.xml
WORKDIR /tmp
RUN mvn dependency:go-offline
RUN mvn clean generate-resources -pl frontend

FROM scratch
LABEL org.opencontainers.image.source=https://github.com/scc-digitalhub/digitalhub-core
COPY --from=cache /root/.m2 /root/.m2
WORKDIR /cache
COPY --from=cache /root/.m2 /cache/.m2
COPY --from=cache /tmp/frontend/target /cache/frontend/target
COPY --from=cache /tmp/frontend/console/node_modules /cache/frontend/console/node_modules
4 changes: 4 additions & 0 deletions application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<layers>
<enabled>true</enabled>
<configuration>${project.basedir}/src/main/layers.xml</configuration>
</layers>
<mainClass>it.smartcommunitylabdhub.core.CoreApplication</mainClass>
</configuration>
</plugin>
Expand Down
26 changes: 26 additions & 0 deletions application/src/main/layers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<layers xmlns="http://www.springframework.org/schema/boot/layers"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/boot/layers https://www.springframework.org/schema/boot/layers/layers-2.3.xsd">
<application>
<into layer="spring-boot-loader">
<include>org/springframework/boot/loader/**</include>
</into>
<into layer="application" />
</application>
<dependencies>
<into layer="dh-dependencies">
<include>it.smartcommunitylabdhub:*:*</include>
</into>
<into layer="snapshot-dependencies">
<include>*:*:*SNAPSHOT</include>
</into>
<into layer="dependencies" />
</dependencies>
<layerOrder>
<layer>dependencies</layer>
<layer>spring-boot-loader</layer>
<layer>snapshot-dependencies</layer>
<layer>dh-dependencies</layer>
<layer>application</layer>
</layerOrder>
</layers>

0 comments on commit 1c5c6e6

Please sign in to comment.