quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.79k stars 2.68k forks source link

building-native-image / Using a scratch base image guide is not working #29857

Closed doublefx closed 1 year ago

doublefx commented 1 year ago

Describe the bug

If I follow the using-a-scratch-base-image instructions, docker fails to build the image.

Specifically, the musl build part is not up to date.

I guess the doc should be updated, this is working:

## Stage 1 : build with maven builder image with native capabilities
FROM quay.io/quarkus/ubi-quarkus-native-image:22.3-java17 AS build

USER root
RUN microdnf install make gcc
RUN mkdir /musl && \
    curl -L -o musl.tar.gz https://more.musl.cc/11.2.1/x86_64-linux-musl/x86_64-linux-musl-native.tgz && \
    tar -xvzf musl.tar.gz -C /musl --strip-components 1 && \
    curl -L -o zlib.tar.gz https://www.zlib.net/zlib-1.2.13.tar.gz && \
    mkdir zlib && tar -xvzf zlib.tar.gz -C zlib --strip-components 1 && \
    cd zlib && ./configure --static --prefix=/musl && \
    make && make install && \
    cd .. && rm -rf zlib && rm -f zlib.tar.gz && rm -f musl.tar.gz
ENV PATH="/musl/bin:${PATH}"

COPY --chown=quarkus:quarkus mvnw /code/mvnw
COPY --chown=quarkus:quarkus .mvn /code/.mvn
COPY --chown=quarkus:quarkus pom.xml /code/

USER quarkus
WORKDIR /code
RUN --mount=type=cache,target=/root/.m2 ./mvnw -B org.apache.maven.plugins:maven-dependency-plugin:3.1.2:go-offline
COPY src /code/src
RUN ./mvnw package -Pnative -DskipTests \
    -Dquarkus.native.container-build=false \
    -Dquarkus.native.additional-build-args="--static","--libc=musl"

## Stage 2 : create the docker final image
FROM scratch
WORKDIR /work
COPY --from=build /code/target/*-runner /work/application

EXPOSE 8080
ENTRYPOINT [ "/work/application" ]

Tested on Rest and Rest+CRUD Quarkus apps with amazing results using:

<profiles>
    <profile>
        <id>native</id>
        <activation>
            <property>
                <name>native</name>
            </property>
        </activation>
        <properties>
            <skipITs>true</skipITs>
            <quarkus.package.type>native</quarkus.package.type>
            <quarkus.native.container-build>true</quarkus.native.container-build>
            <quarkus.native.builder-image>quay.io/quarkus/ubi-quarkus-native-image:22.3-java17</quarkus.native.builder-image>
            <quarkus.native.compression.level>10</quarkus.native.compression.level>
            <quarkus.native.compression.additional-args>--lzma</quarkus.native.compression.additional-args>
        </properties>
    </profile>
</profiles>
mkouba commented 1 year ago

CC @andreaTP @cescoffier

cescoffier commented 1 year ago

I would be in favor of removing the whole section. Using musl is leading to nasty issues with native images (which we compile using the standard glibc)

cescoffier commented 1 year ago

We already have "micro" image supports with quarkus-micro.

cescoffier commented 1 year ago

The section is flagged as experimental - so actually, we can keep it.

Looking at the diff, it's only a musl update - I will open a PR.

quarkus-bot[bot] commented 1 year ago

/cc @geoand(jib)

andreaTP commented 1 year ago

@cescoffier @geoand do you have in place any automation to test in CI snippets for the Docs?

geoand commented 1 year ago

That's a question for @gsmet and @ebullient

cescoffier commented 1 year ago

No we don't- not for dockerfile

doublefx commented 1 year ago

@cescoffier What kind of nasty issues have you met?

I haven't seen anything weird using REST+CRUD + eventBus + read from FileSystem But it would be good to know what not to do when using Musl.

cescoffier commented 1 year ago

I have seen many issues, often related to TLS / https but not only:

ebullient commented 1 year ago

The updated docs can include tested code samples: https://quarkus.io/guides/doc-reference#reference-source-code

Detailed meta example/tutorial is here: https://quarkus.io/guides/doc-create-tutorial#using-a-source-file (this is in the context of a tutorial for creating a tutorial.. but the mechanics are there)