nim-censor-bot/Dockerfile
baalajimaestro 7ffa1bdabf
Strip the binaries further to reduce size
Signed-off-by: baalajimaestro <me@baalajimaestro.me>
2022-04-25 11:43:54 +05:30

54 lines
1.6 KiB
Docker

FROM nimlang/nim:alpine as builder
RUN apk update && apk add git build-base clang perl autoconf automake libtool llvm llvm-dev lld curl bash openssl sqlite-dev sqlite-static
RUN git clone https://github.com/libressl-portable/portable && \
cd portable && \
./autogen.sh &> /dev/null && \
./configure --with-openssldir=/usr/local/libressl --disable-shared &> /dev/null && \
make -j$(nproc) &> /dev/null && \
make install &> /dev/null
COPY . /app
WORKDIR /app
# Build with necessary params to enable statically linking openssl, glibc and sqlite3
RUN nimble build --passL:-L/usr/lib \
--passL:-L/usr/local/lib \
-d:ssl \
--os:any \
-d:posix \
-d:libressl \
-d:useMalloc \
-d:noSignalHandler \
--cc:clang \
-p:. \
--dynlibOverride:ssl \
--dynlibOverride:crypto \
--dynlibOverride:sqlite3 \
--passl:-lssl \
--passl:-lsqlite3 \
--passl:-lcrypto \
--passL:-static \
--passL:"-flto=full" \
--passL:"-fuse-ld=lld" \
--gc:arc \
--panics:on \
-d:danger \
--opt:speed \
--accept
RUN strip -s /app/nim_censor_bot && \
strip -R .comment -R .note -R .note.ABI-tag /app/nim_censor_bot
# Our binary lives in this image
FROM gcr.io/distroless/base:latest
COPY --from=builder /app/nim_censor_bot /
ENV DB_HOST="/data/censordata.db"
EXPOSE 8080
VOLUME /data
CMD ["./nim_censor_bot"]