From 9e6e76306471b3cc139ae68c0363ec95616d1b23 Mon Sep 17 00:00:00 2001 From: Ansari Date: Mon, 30 Mar 2026 00:13:13 +0530 Subject: docker: use multi-stage build to reduce image size --- Dockerfile | 61 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 27 deletions(-) (limited to 'Dockerfile') diff --git a/Dockerfile b/Dockerfile index 14b67b8..11aac36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,46 @@ -FROM alpine:latest +# ---------- Build stage ---------- +FROM alpine:3.20 AS builder -# Install required dependencies RUN apk add --no-cache \ - libxml2-dev \ + build-base \ curl-dev \ - shadow \ - git \ - make \ - gcc \ - musl-dev \ - pkgconf \ + libxml2-dev \ openssl-dev \ - openrc - -# Clone and install beaker -RUN git clone https://git.bwaaa.monster/beaker /tmp/beaker \ - && cd /tmp/beaker \ - && make \ - && make install \ - && rm -rf /tmp/beaker + git \ + pkgconf -# Import omnisearch source WORKDIR /app COPY . /app -# Clone and install omnisearch -RUN cd /app \ - && make \ - && make install-openrc +RUN git clone https://git.bwaaa.monster/beaker /tmp/beaker && \ + cd /tmp/beaker && \ + make && make install && \ + rm -rf /tmp/beaker + +RUN make clean && make && strip bin/omnisearch + +# ---------- Runtime stage ---------- +FROM alpine:3.20 + +RUN apk add --no-cache \ + libcurl \ + libxml2 \ + openssl + +WORKDIR /app + +# Copy only required artifacts +COPY --from=builder /app/bin/omnisearch /app/omnisearch +COPY --from=builder /usr/lib/libbeaker.so /usr/lib/libbeaker.so +COPY --from=builder /app/templates /app/templates +COPY --from=builder /app/static /app/static + +# Security: non-root user +RUN adduser -D appuser && chmod +x /app/omnisearch +USER appuser -# Enable OpenRC and start the service -RUN rc-update add omnisearch default +ENV LD_LIBRARY_PATH=/usr/lib -# Expose the default port EXPOSE 5000 -# Start OpenRC and the service -CMD sh -c "openrc default && touch /run/openrc/softlevel && omnisearch" +CMD ["/app/omnisearch"] -- cgit v1.2.3