Skip to content

Commit

Permalink
Use jlink to create a smaller docker image (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartelliEnrico authored Oct 21, 2023
1 parent d7ec922 commit b71acc8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
build/
src/test/
src/main/resources/images/
.gitattributes
.gitignore
*.md
gradlew.bat
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM eclipse-temurin:21-jdk AS builder
FROM eclipse-temurin AS builder
WORKDIR /app
COPY settings.gradle build.gradle gradlew ./
COPY gradle ./gradle
RUN --mount=type=cache,target=/home/gradle/.gradle/caches \
./gradlew dependencies --no-daemon
COPY . .
RUN ./gradlew shadowJar --no-daemon
RUN ./gradlew runtime --no-daemon

FROM eclipse-temurin:21-jre-alpine AS bot
WORKDIR /app
FROM gcr.io/distroless/base-nossl AS bot
COPY --from=builder /app/build/jre ./jre
COPY --from=builder /app/build/libs/Stickerify-shadow.jar .
COPY --from=mwader/static-ffmpeg:6.0 /ffmpeg /usr/local/bin/
COPY --from=mwader/static-ffmpeg /ffmpeg /usr/local/bin/
ENV FFMPEG_PATH=/usr/local/bin/ffmpeg
CMD ["java", "-jar", "Stickerify-shadow.jar"]
CMD ["jre/bin/java", "-jar", "Stickerify-shadow.jar"]
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
alias(libs.plugins.runtime)
alias(libs.plugins.shadow)
id 'application'
id 'java'
}

Expand Down Expand Up @@ -52,6 +52,11 @@ application {
mainClass = 'com.github.stickerifier.stickerify.runner.Main'
}

runtime {
options = ['--strip-debug', '--no-header-files', '--no-man-pages', '--compress=2']
modules = ['java.desktop', 'java.naming', 'java.sql', 'jdk.crypto.ec']
}

shadowJar {
archiveBaseName = 'Stickerify'
archiveClassifier = 'shadow'
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ telegram-bot-api = "com.github.pengrad:java-telegram-bot-api:6.9.1"
tika = "org.apache.tika:tika-core:2.9.1"

[plugins]
runtime = "org.beryx.runtime:1.13.0"
shadow = "com.github.johnrengelman.shadow:8.1.1"
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ private static boolean isSupportedVideo(String mimeType) {
* @throws TelegramApiException if an error occurred processing passed-in image
*/
private static File convertToPng(BufferedImage image, String mimeType) throws TelegramApiException {
if (isImageCompliant(image, mimeType)) {
LOGGER.atInfo().log("The image doesn't need conversion");
try {
if (isImageCompliant(image, mimeType)) {
LOGGER.atInfo().log("The image doesn't need conversion");

return null;
}
return null;
}

try {
return createPngFile(resizeImage(image));
} finally {
image.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public File createImage(int width, int height, String extension) {
ImageIO.write(image, extension, file);
} catch (IOException e) {
abort("Image could not be written to file [%s].".formatted(file.getName()));
} finally {
image.flush();
}

return file;
Expand Down

0 comments on commit b71acc8

Please sign in to comment.