|
| 1 | +# Multi-stage build for the SQLRite Go edge/IoT collector (SQLR-43). |
| 2 | +# |
| 3 | +# Build context MUST be the repository root, because the Go module |
| 4 | +# links the engine's C library (built from `sqlrite-ffi`) and depends |
| 5 | +# on `sdk/go` via a replace directive: |
| 6 | +# |
| 7 | +# docker build -f examples/go-collector/Dockerfile -t sqlrite-collector . |
| 8 | +# |
| 9 | +# cgo + cross-compilation note: this image is built for the host's |
| 10 | +# architecture. cgo binaries can't be cross-compiled with the plain Go |
| 11 | +# toolchain, so produce per-arch images with `docker buildx --platform` |
| 12 | +# (the Rust and Go stages both honor the target platform). See the |
| 13 | +# README's "Build & distribution matrix" section. |
| 14 | + |
| 15 | +# ---- Stage 1: build libsqlrite_c.so from the engine source ---- |
| 16 | +FROM rust:1-bookworm AS rust |
| 17 | +WORKDIR /src |
| 18 | +COPY . . |
| 19 | +RUN cargo build --release -p sqlrite-ffi |
| 20 | + |
| 21 | +# ---- Stage 2: build the Go binaries against that library ---- |
| 22 | +FROM golang:1.22-bookworm AS go |
| 23 | +ENV CGO_ENABLED=1 |
| 24 | +WORKDIR /src |
| 25 | +# Bring the whole tree over (we need sdk/go, sqlrite-ffi/include, and |
| 26 | +# the freshly-built target/release/libsqlrite_c.so from the rust stage). |
| 27 | +COPY --from=rust /src /src |
| 28 | +WORKDIR /src/examples/go-collector |
| 29 | +RUN go build -trimpath -o /out/collector ./cmd/collector \ |
| 30 | + && go build -trimpath -o /out/loadgen ./cmd/loadgen |
| 31 | + |
| 32 | +# ---- Stage 3: slim runtime ---- |
| 33 | +FROM debian:bookworm-slim |
| 34 | +RUN apt-get update \ |
| 35 | + && apt-get install -y --no-install-recommends ca-certificates \ |
| 36 | + && rm -rf /var/lib/apt/lists/* \ |
| 37 | + && useradd --create-home --uid 10001 collector |
| 38 | +# Install the shared library where the dynamic linker will find it. |
| 39 | +# The Go binary was linked with an rpath pointing at the build tree; |
| 40 | +# that path is absent here, so cgo falls through to the ldconfig cache. |
| 41 | +COPY --from=rust /src/target/release/libsqlrite_c.so /usr/local/lib/ |
| 42 | +RUN ldconfig |
| 43 | +COPY --from=go /out/collector /usr/local/bin/collector |
| 44 | +COPY --from=go /out/loadgen /usr/local/bin/loadgen |
| 45 | +USER collector |
| 46 | +WORKDIR /data |
| 47 | +VOLUME ["/data"] |
| 48 | +EXPOSE 8080 |
| 49 | +ENTRYPOINT ["collector"] |
| 50 | +CMD ["-db", "/data/events.sqlrite", "-addr", ":8080"] |
0 commit comments