ARG BASE_IMAGE=n-os-tr/alpine-musl-base:3.19
FROM ${BASE_IMAGE} AS builder

RUN apk add --no-cache \
    bash \
    ncurses-dev \
    ncurses-static

WORKDIR /work

COPY includes/nostr_core_lib /work/includes/nostr_core_lib
COPY stack/nostr-id-tui /work/stack/nostr-id-tui

RUN cd /work/includes/nostr_core_lib && bash ./build.sh x64

RUN cmake -S /work/stack/nostr-id-tui -B /work/stack/nostr-id-tui/build-cmake \
        -DCMAKE_BUILD_TYPE=Release \
        -DNOSTR_CORE_LIB_DIR=/work/includes/nostr_core_lib \
        -DNOSTR_CORE_STATIC_LIB=/work/includes/nostr_core_lib/libnostr_core_x64.a \
        -DNOSTR_TUI_FORCE_STATIC=ON && \
    cmake --build /work/stack/nostr-id-tui/build-cmake --target nostr-id-tui -j"$(nproc)" && \
    mkdir -p /out && \
    cp /work/stack/nostr-id-tui/build-cmake/nostr-id-tui /out/nostr-id-tui

FROM scratch AS output
COPY --from=builder /out/nostr-id-tui /nostr-id-tui
