FROM quay.io/quarkus/ubi-quarkus-graalvmce-builder-image:22.3-java17 AS build

USER root

RUN microdnf install make gcc

COPY --chown=quarkus:quarkus . /code

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}"

USER quarkus

WORKDIR /code

RUN ./mvnw clean install -DskipTests
RUN ./mvnw -T 1.5C package -B -Pnative -Pprod -DskipTests -Dquarkus.native.additional-build-args="--initialize-at-run-time=org.apache.kafka.common.security.authenticator.SaslClientAuthenticator","--allow-incomplete-classpath","--static","--libc=musl" -f ./app/pom.xml

FROM scratch

COPY --from=build /code/app/target/meta /work/meta
COPY --from=build /code/app/target/*-runner /application

EXPOSE 8080

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
