Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
doublefx opened this issue Dec 14, 2022 · 11 comments · Fixed by #29949
Closed

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

doublefx opened this issue Dec 14, 2022 · 11 comments · Fixed by #29949
Labels
area/container-image kind/bug Something isn't working
Milestone

Comments

@doublefx
Copy link

doublefx commented Dec 14, 2022

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>
@doublefx doublefx added the kind/bug Something isn't working label Dec 14, 2022
@mkouba
Copy link
Contributor

mkouba commented Dec 19, 2022

CC @andreaTP @cescoffier

@cescoffier
Copy link
Member

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
Copy link
Member

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

@cescoffier
Copy link
Member

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
Copy link

quarkus-bot bot commented Dec 19, 2022

/cc @geoand(jib)

@andreaTP
Copy link
Contributor

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

@geoand
Copy link
Contributor

geoand commented Dec 19, 2022

That's a question for @gsmet and @ebullient

@cescoffier
Copy link
Member

No we don't- not for dockerfile

@doublefx
Copy link
Author

doublefx commented Dec 19, 2022

@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
Copy link
Member

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

  • segfault and other crash
  • slowness for 1-2 min every 30min or so

@gsmet gsmet modified the milestones: 2.16 - main, 2.15.1.Final Dec 20, 2022
@ebullient
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/container-image kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants