From 3d123356cf105fc429608019f80a0f759ba6954c Mon Sep 17 00:00:00 2001 From: Daniel Svensson Date: Sat, 2 Nov 2024 15:41:23 +0100 Subject: [PATCH] Switch to alpine and build q3asm. This shrinks the image from ~200MB to ~30MB. --- Dockerfile | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a4a17a..86c00e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,34 @@ -FROM debian:bookworm-slim AS builder +FROM alpine:3.20.3 AS builder ARG TARGETOS ARG TARGETARCH -RUN apt-get update -qq && apt-get install -qq --no-install-recommends build-essential bison +RUN --mount=type=cache,id=${TARGETARCH}/var/cache/apk,target=/var/cache/apk \ + apk add --update build-base bison ADD /q3lcc /opt/q3lcc -WORKDIR /opt/q3lcc +ADD /q3asm /opt/q3asm -RUN make -j $(nproc) PLATFORM=${TARGETOS} ARCH=${TARGETARCH} +WORKDIR /opt + +RUN cd q3lcc && make -j $(nproc) PLATFORM=${TARGETOS} ARCH=${TARGETARCH} +RUN cd q3asm && make -j $(nproc) WORKDIR /opt/q3lcc/build-${TARGETOS}-${TARGETARCH} +RUN install -s -m 0755 q3lcc q3cpp q3rcc /usr/local/bin/ + +WORKDIR /opt/q3asm +RUN install -s -m 0755 q3asm /usr/local/bin/ -RUN install -s -m 0755 q3lcc q3cpp q3rcc /usr/local/bin/ +FROM alpine:3.20.3 -FROM debian:bookworm-slim +RUN --mount=type=cache,id=${TARGETARCH}/var/cache/apk,target=/var/cache/apk \ + apk add --no-cache cmake bash ninja-build && rm /usr/bin/cpack /usr/bin/ctest -RUN apt-get update -qq && apt-get install -qq --no-install-recommends build-essential cmake ninja-build && mkdir /src +COPY --from=builder /usr/local/bin/q3asm /usr/local/bin/q3lcc /usr/local/bin/q3cpp /usr/local/bin/q3rcc /usr/local/bin/ -COPY --from=builder /usr/local/bin/q3lcc /usr/local/bin/q3cpp /usr/local/bin/q3rcc /usr/local/bin/ +# cmake needs to have some kind of cc installed, even if not used for regular C code +ENV CC="q3lcc" \ + PATH="$PATH:/usr/lib/ninja-build/bin" WORKDIR /src \ No newline at end of file