Files
n_signer/Dockerfile.alpine-musl
Laan Tungir 268b33b6d3 first
2026-05-02 12:31:26 -04:00

78 lines
2.1 KiB
Docker

# Alpine-based MUSL static binary builder for nsigner
# Produces portable binaries with zero runtime dependencies
ARG DEBUG_BUILD=false
FROM alpine:3.19 AS builder
ARG DEBUG_BUILD=false
RUN apk add --no-cache \
build-base \
musl-dev \
git \
cmake \
pkgconfig \
autoconf \
automake \
libtool \
openssl-dev \
openssl-libs-static \
zlib-dev \
zlib-static \
curl-dev \
curl-static \
linux-headers \
wget \
bash
WORKDIR /build
# Build libsecp256k1 static for nostr_core_lib
RUN cd /tmp && \
git clone https://github.com/bitcoin-core/secp256k1.git && \
cd secp256k1 && \
./autogen.sh && \
./configure --enable-static --disable-shared --prefix=/usr CFLAGS="-fPIC" && \
make -j$(nproc) && \
make install && \
rm -rf /tmp/secp256k1
# Copy and build nostr_core_lib with signer-focused NIPs
COPY nostr_core_lib /build/nostr_core_lib/
RUN cd nostr_core_lib && \
chmod +x build.sh && \
sed -i 's/CFLAGS="-Wall -Wextra -std=c99 -fPIC -O2"/CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -Wall -Wextra -std=c99 -fPIC -O2"/' build.sh && \
rm -f *.o *.a 2>/dev/null || true && \
./build.sh --nips=1,6,13,17,19,44,46,59
# Copy project source
COPY src/ /build/src/
# Build nsigner static binary
RUN if [ "$DEBUG_BUILD" = "true" ]; then \
CFLAGS="-g -O2 -DDEBUG -fno-omit-frame-pointer"; \
STRIP_CMD="echo 'Keeping debug symbols'"; \
echo "Building debug binary"; \
else \
CFLAGS="-O2"; \
STRIP_CMD="strip /build/nsigner_static"; \
echo "Building production binary"; \
fi && \
gcc -static $CFLAGS -Wall -Wextra -std=c99 \
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 \
-Isrc \
src/main.c \
-o /build/nsigner_static && \
eval "$STRIP_CMD"
RUN echo "=== Binary Information ===" && \
file /build/nsigner_static && \
ls -lh /build/nsigner_static && \
echo "=== Checking for dynamic dependencies ===" && \
(ldd /build/nsigner_static 2>&1 || echo "Binary is static") && \
echo "=== Build complete ==="
FROM scratch AS output
COPY --from=builder /build/nsigner_static /nsigner_static