beryx / badass-runtime-plugin

Create a custom runtime image of your non-modular application
https://badass-runtime-plugin.beryx.org
Apache License 2.0
161 stars 21 forks source link

Multi stage docker build for Alpine #52

Closed tonsV2 closed 4 years ago

tonsV2 commented 4 years ago

I'm trying to use the plugin for building a runtime image for Alpine.

My Dockerfile

#FROM adoptopenjdk/openjdk14:x86_64-alpine-jdk-14_36 AS builder
FROM azul/zulu-openjdk-alpine:14 AS builder
WORKDIR /src

COPY *.gradle *.properties gradlew ./
COPY gradle gradle
RUN ./gradlew --version

COPY . .
RUN ./gradlew jpackageImage

FROM alpine
WORKDIR /app
COPY --from=builder /src/build/jpackage/jibcmd .
CMD exec ./bin/jibcmd

My build.gradle

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.3.61'
    id 'application'
    id "org.beryx.runtime" version "1.8.0"
}

group 'org.example'
version '1.0.0'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation "com.github.ajalt:clikt:2.3.0"
    implementation "com.google.cloud.tools:jib-core:0.12.0"
    testCompile group: 'junit', name: 'junit', version: '4.12'

    implementation 'org.glassfish.jaxb:jaxb-runtime:2.4.0-b180830.0438'
    implementation 'com.sun.xml.ws:jaxws-ri:2.3.2'
}

runtime {
    modules = ['java.logging', 'java.desktop', 'java.compiler', 'java.xml']
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

The error Error: no such option: "-Djava.library.path".

If I'm using adoptopenjdk/openjdk14:x86_64-alpine-jdk-14_36 as a base image I get the following error. jibcmd_1 | /bin/sh: exec: line 1: ./bin/jibcmd: not found

Adding to that it's worth noting that jibcmd is executable and the output of ldd shows all dependencies are found. Assuming I install gcompat.

    /lib64/ld-linux-x86-64.so.2 (0x7ff667c34000)
    libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7ff667c34000)
    libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7ff667c34000)
    libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7ff667c34000)
    ld-linux-x86-64.so.2 => /lib/ld-linux-x86-64.so.2 (0x7ff667c2e000)

Any suggestions about how to get this running?

tonsV2 commented 4 years ago

It might help someone to find the complete repository here.

siordache commented 4 years ago

Try this:

FROM gradle:6.3-jdk14 AS builder
WORKDIR /src
COPY . .
RUN gradle jpackageImage

FROM panga/alpine:3.8-glibc2.27
WORKDIR /app
COPY --from=builder /src/build/jpackage/jibcmd .
CMD exec ./bin/jibcmd
tonsV2 commented 4 years ago

I suppose it's an Java/musl problem, thanks.