|
| 1 | +FROM debian:bookworm-slim AS builder |
| 2 | + |
| 3 | +# Install dependencies for building |
| 4 | +RUN apt-get update && apt-get install -y \ |
| 5 | + build-essential \ |
| 6 | + cmake \ |
| 7 | + gcc \ |
| 8 | + pkg-config \ |
| 9 | + libjansson-dev \ |
| 10 | + libmicrohttpd-dev \ |
| 11 | + libsodium-dev \ |
| 12 | + libcurl4-openssl-dev \ |
| 13 | + git \ |
| 14 | + --no-install-recommends \ |
| 15 | + && apt-get clean \ |
| 16 | + && rm -rf /var/lib/apt/lists/* |
| 17 | + |
| 18 | +WORKDIR /build |
| 19 | + |
| 20 | +# Copy entire repository for git information |
| 21 | +COPY . . |
| 22 | + |
| 23 | +# Build the application with optimization flags |
| 24 | +RUN cmake -DCMAKE_BUILD_TYPE=Release . && make -j$(nproc) |
| 25 | + |
| 26 | +# Use the same Debian version for runtime to ensure library compatibility |
| 27 | +FROM debian:bookworm-slim AS runtime |
| 28 | + |
| 29 | +# Install only runtime dependencies |
| 30 | +RUN apt-get update && apt-get install -y \ |
| 31 | + libjansson4 \ |
| 32 | + libmicrohttpd12 \ |
| 33 | + libsodium23 \ |
| 34 | + libcurl4 \ |
| 35 | + netcat-traditional \ |
| 36 | + --no-install-recommends \ |
| 37 | + && apt-get clean \ |
| 38 | + && rm -rf /var/lib/apt/lists/* \ |
| 39 | + && rm -rf /usr/share/doc /usr/share/man \ |
| 40 | + && find /var/cache -type f -delete |
| 41 | + |
| 42 | +WORKDIR /app |
| 43 | + |
| 44 | +# Copy only the built binary and necessary files from builder |
| 45 | +COPY --from=builder /build/datum_gateway /app/ |
| 46 | +COPY --from=builder /build/www/ /app/www/ |
| 47 | +COPY --from=builder /build/doc/example_datum_gateway_config.json /app/config/config.json |
| 48 | + |
| 49 | +# Create a configuration directory if it doesn't exist |
| 50 | +RUN mkdir -p /app/config |
| 51 | + |
| 52 | +# Verify shared library dependencies |
| 53 | +RUN ldd /app/datum_gateway |
| 54 | + |
| 55 | +# Create a non-root user |
| 56 | +RUN useradd -r -s /bin/false datumuser && \ |
| 57 | + chown -R datumuser:datumuser /app |
| 58 | + |
| 59 | +# Change to non-root user |
| 60 | +USER datumuser |
| 61 | + |
| 62 | +# Set up healthcheck |
| 63 | +HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \ |
| 64 | + CMD nc -zv localhost 23334 || exit 1 |
| 65 | + |
| 66 | +# Expose ports |
| 67 | +EXPOSE 23334/tcp 7152/tcp |
| 68 | + |
| 69 | +# Create a volume for configuration and data |
| 70 | +VOLUME ["/app/config"] |
| 71 | + |
| 72 | +# Set the entrypoint |
| 73 | +ENTRYPOINT ["/app/datum_gateway", "--config", "/app/config/config.json"] |
0 commit comments