# Multi-stage build for libevent
# Builder stage: compile libevent from source using CMake
FROM ubuntu:22.04 AS builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
pkg-config \
zlib1g-dev \
libssl-dev \
libmbedtls-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Copy source
WORKDIR /src
COPY . /src
# Build and install
RUN mkdir -p build && cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=Release \
&& cmake --build . -- -j$(nproc) \
&& cmake --build . --target install
# Runtime stage: minimal image with the built library
FROM ubuntu:22.04-slim AS runtime
ENV DEBIAN_FRONTEND=noninteractive
# Basic runtime dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
libssl1.1 \
libcrypto1.1 \
\
&& rm -rf /var/lib/apt/lists/*
# Copy installed libs from builder
COPY "/src/build"/install /usr/local
# Ensure dynamic linker can find libraries installed to /usr/local
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:$LD_LIBRARY_PATH
# Update the linker cache in case needed
RUN ldconfig || true
WORKDIR /work
CMD ["bash"]
# Multi-stage build for libevent
# Builder stage: compile libevent from source using CMake
FROM ubuntu:22.04 AS builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
pkg-config \
zlib1g-dev \
libssl-dev \
libmbedtls-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Copy source
WORKDIR /src
COPY . /src
# Build and install
RUN mkdir -p build && cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=Release \
&& cmake --build . -- -j"$(nproc)" \
&& cmake --build . --target install
# Runtime stage: minimal image with the built library
FROM ubuntu:22.04 AS runtime
ENV DEBIAN_FRONTEND=noninteractive
# Copy installed libs from builder
COPY --from=builder /usr/local /usr/local
# Ensure dynamic linker can find libraries installed to /usr/local
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:$LD_LIBRARY_PATH
WORKDIR /work
CMD ["bash"]
Concerns: No runtime smoke test asserting that libevent can be linked/used (e.g., building a tiny test program) — only header/lib existence checks are performed., Final image CMD is a bash shell, which is fine for debugging but not representative of a library container's typical usage; consider removing or replacing with a minimal entrypoint. Smoke [PASS]: test -f /usr/local/include/event2/event.h Smoke [PASS]: ls /usr/local/lib | grep -E '^libevent' >/dev/null 2>&1