quarkusio / quarkus-images

Set of container images delivered for Quarkus
Apache License 2.0
110 stars 75 forks source link

Help to debug build of quarkus-native #181

Closed celsomarques closed 2 years ago

celsomarques commented 2 years ago

Hello,

I'm building quarkus native application in two different ways and one works properly and another one don't.

The app is able to connect to Kafka properly when running the docker using this Dockerfile.

ARG BUILD_MEMORY=6g

## Stage 1 : build with gradle builder image with native capabilities
FROM quay.io/quarkus/ubi-quarkus-mandrel:21.3-java11 AS build
USER root
ARG BUILD_MEMORY
COPY gradlew /code/gradlew
COPY gradle /code/gradle
COPY build.gradle /code/
COPY settings.gradle /code/
COPY gradle.properties /code/

WORKDIR /code
COPY src /code/src

RUN ./gradlew build -Dquarkus.package.type=native -Dquarkus.native.native-image-xmx=$BUILD_MEMORY

## Stage 2 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
USER root
WORKDIR /work/
COPY --from=build /code/build/*-runner /work/application
COPY docker-entrypoint.sh /work/entrypoint.sh
RUN chmod 775 /work && chmod 755 /work/entrypoint.sh
EXPOSE 8080
ENTRYPOINT [ "/work/entrypoint.sh" ]
CMD ["/work/application", "-Dquarkus.http.host=0.0.0.0"]

But when building native-sources first and then build native app, the app was not able to connect to Kafka

# Limit memory of build
ARG BUILD_MEMORY=4g

## Stage 1: build native sources
FROM gradle:7.3-jdk11 AS gradle-build
USER root
COPY build.gradle /code/
COPY settings.gradle /code/
COPY gradle.properties /code/

WORKDIR /code
COPY src /code/src

RUN gradle clean build -Dquarkus.package.type=native-sources

## Stage 2: build quarkus-native
FROM quay.io/quarkus/ubi-quarkus-mandrel:21.3-java11 AS native-build
USER root
ARG BUILD_MEMORY
COPY --from=gradle-build /code/build/native-sources /build
WORKDIR /build

RUN native-image $(cat native-image.args) -J-Xmx$BUILD_MEMORY

## Stage 3 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
WORKDIR /work
COPY --from=native-build /build/*-runner /work/application
COPY docker-entrypoint.sh /work/entrypoint.sh
RUN chmod 755 /work/entrypoint.sh
EXPOSE 8080
ENTRYPOINT [ "/work/entrypoint.sh" ]
CMD ["/work/application", "-Dquarkus.http.host=0.0.0.0"]

application.properties

# Build Native
quarkus.native.additional-build-args=-H:ResourceConfigurationFiles=resources-config.json, -H:ReflectionConfigurationFiles=reflection-config.json
quarkus.native.native-image-xmx=6g

# Server
quarkus.http.port=${PORT:8080}

# Database
quarkus.datasource.db-kind=postgresql
quarkus.datasource.jdbc.url=${DATABASE_URL}
quarkus.datasource.jdbc.max-size=${DB_POOL_SIZE:20}
quarkus.datasource.username=${DATABASE_USERNAME:user}
quarkus.datasource.password=${DATABASE_PASSWORD:user}
%dev.quarkus.hibernate-orm.log.sql=true
%dev.quarkus.hibernate-orm.log.format-sql=false

# Elasticsearch
%prod.quarkus.elasticsearch.protocol=https
quarkus.elasticsearch.hosts=${ELASTICSEARCH_HOSTS:localhost:9200}
quarkus.elasticsearch.username=${ELASTICSEARCH_USERNAME:}
quarkus.elasticsearch.password=${ELASTICSEARCH_PASSWORD:}

# Kafka
kafka.bootstrap.servers=${KAFKA_URL:localhost:9093}
mp.messaging.connector.smallrye-kafka.auto.offset.reset=earliest
mp.messaging.connector.smallrye-kafka.group.id=consumer-group

mp.messaging.connector.smallrye-kafka.security.protocol=SASL_PLAINTEXT
mp.messaging.connector.smallrye-kafka.ssl.endpoint.identification.algorithm=https
mp.messaging.connector.smallrye-kafka.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="${KAFKA_USERNAME:user}" password="${KAFKA_PASSWORD:bitnami}";
mp.messaging.connector.smallrye-kafka.sasl.mechanism=PLAIN

Is there any way to find what's going on here?

Repository

Best regards

cescoffier commented 2 years ago

My guess is that the native sources do not contain quarkus.native.additional-build-args=-H:ResourceConfigurationFiles=resources-config.json, -H:ReflectionConfigurationFiles=reflection-config.json.

cescoffier commented 2 years ago

BTW, this issue should be re-opened in the main quarkus repository, as it's not related to the images.

cescoffier commented 2 years ago

BTW, the reproducer does not work for me, it does not pass the tests.

cescoffier commented 2 years ago

My guess is that the native sources do not contain quarkus.native.additional-build-args=-H:ResourceConfigurationFiles=resources-config.json, -H:ReflectionConfigurationFiles=reflection-config.json.

I was wrong, it contains them.

cescoffier commented 2 years ago

Looking at the generated native sources, it does not contain lots of the reflection we need for Kafka.

So, please re-open this issue on the quarkus main repository as it seems to be the missing piece.