forked from mtusi2026/mtusi2026lab4
114 lines
3.9 KiB
Docker
114 lines
3.9 KiB
Docker
# Clean-clone build: Ubuntu 24.04 + libpqxx from a pinned git tag.
|
|
# S3 client: official minio-cpp v0.3.0 via FetchContent (library SigV4).
|
|
# No dependency on mtusi2026lab3-api or other prior-lab images.
|
|
|
|
ARG PQXX_VERSION=7.10.0
|
|
ARG MTUSI_MINIO_CPP_VERSION=v0.3.0
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Stage: build libpqxx into /opt/libpqxx
|
|
# ---------------------------------------------------------------------------
|
|
FROM ubuntu:24.04 AS pqxx
|
|
ARG PQXX_VERSION
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential cmake git ca-certificates pkg-config \
|
|
libpq-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /tmp
|
|
RUN git clone --depth 1 --branch "${PQXX_VERSION}" \
|
|
https://github.com/jtv/libpqxx.git libpqxx-src \
|
|
&& cmake -S libpqxx-src -B libpqxx-build \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_INSTALL_PREFIX=/opt/libpqxx \
|
|
-DBUILD_SHARED_LIBS=ON \
|
|
-DSKIP_BUILD_TEST=ON \
|
|
&& cmake --build libpqxx-build -j"$(nproc)" \
|
|
&& cmake --install libpqxx-build \
|
|
&& rm -rf /tmp/libpqxx-src /tmp/libpqxx-build
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Stage: build messenger + smokes
|
|
# ---------------------------------------------------------------------------
|
|
FROM ubuntu:24.04 AS builder
|
|
ARG MTUSI_MINIO_CPP_VERSION
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential cmake pkg-config git ca-certificates \
|
|
libpq-dev \
|
|
libhiredis-dev \
|
|
libsodium-dev \
|
|
nlohmann-json3-dev \
|
|
libcurl4-openssl-dev libssl-dev zlib1g-dev \
|
|
libpugixml-dev \
|
|
libcurlpp-dev \
|
|
libinih-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
COPY --from=pqxx /opt/libpqxx /opt/libpqxx
|
|
ENV PKG_CONFIG_PATH=/opt/libpqxx/lib/pkgconfig:/opt/libpqxx/lib/x86_64-linux-gnu/pkgconfig
|
|
ENV LD_LIBRARY_PATH=/opt/libpqxx/lib:/opt/libpqxx/lib/x86_64-linux-gnu
|
|
ENV CMAKE_PREFIX_PATH=/opt/libpqxx
|
|
|
|
WORKDIR /src
|
|
COPY CMakeLists.txt CMakePresets.json ./
|
|
COPY cmake ./cmake
|
|
COPY src ./src
|
|
COPY tools ./tools
|
|
COPY migrations ./migrations
|
|
COPY third_party ./third_party
|
|
|
|
RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
|
|
-DMTUSI_MINIO_CPP_VERSION=${MTUSI_MINIO_CPP_VERSION} \
|
|
&& cmake --build build -j"$(nproc)"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Runtime
|
|
# ---------------------------------------------------------------------------
|
|
FROM ubuntu:24.04
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
ca-certificates curl \
|
|
libpq5 \
|
|
libhiredis1.1.0 \
|
|
libsodium23 \
|
|
libssl3t64 \
|
|
libcurl4t64 \
|
|
zlib1g \
|
|
libpugixml1v5 \
|
|
libcurlpp0t64 \
|
|
libinih1 \
|
|
libinireader0 \
|
|
util-linux \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& groupadd --gid 10001 app \
|
|
&& useradd --uid 10001 --gid app --shell /usr/sbin/nologin --no-create-home app
|
|
|
|
COPY --from=pqxx /opt/libpqxx /opt/libpqxx
|
|
ENV LD_LIBRARY_PATH=/opt/libpqxx/lib:/opt/libpqxx/lib/x86_64-linux-gnu
|
|
|
|
WORKDIR /app
|
|
COPY --from=builder /src/build/messenger /app/messenger
|
|
COPY --from=builder /src/build/s3_smoke /app/s3_smoke
|
|
COPY --from=builder /src/build/image_smoke /app/image_smoke
|
|
COPY --from=builder /src/migrations /app/migrations
|
|
COPY tools/fixtures /app/fixtures
|
|
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
|
|
|
RUN chmod 0755 /docker-entrypoint.sh \
|
|
&& chown -R app:app /app
|
|
|
|
# Entrypoint starts as root to stage S3 secret files for uid 10001, then drops.
|
|
USER root
|
|
ENV APP_HOST=0.0.0.0
|
|
ENV APP_PORT=8080
|
|
|
|
EXPOSE 8080
|
|
|
|
HEALTHCHECK --interval=5s --timeout=3s --start-period=20s --retries=3 \
|
|
CMD curl -fsS http://127.0.0.1:8080/health/live || exit 1
|
|
|
|
ENTRYPOINT ["/docker-entrypoint.sh"]
|
|
CMD ["/app/messenger"]
|