ARG VERSION=dev FROM golang:1.27.2-bookworm@sha256:5cf287a799e6b94384bad13d16b14904c531f51ba65792237e122ce42b392f61 AS builder ARG VERSION RUN apt-get update && apt-get install -y --no-install-recommends \ nbdkit nbdkit-plugin-dev pkg-config gcc make \ && rm -rf /var/lib/apt/lists/* WORKDIR /build # Copy module files for dependency caching COPY spinifex/go.mod spinifex/go.sum ./spinifex/ COPY predastore/go.mod predastore/go.sum ./predastore/ COPY viperblock/go.mod viperblock/go.sum ./viperblock/ COPY viperblock/nbd/go.mod viperblock/nbd/go.sum ./viperblock/nbd/ COPY viperblock/nbd/libguestfs.org/nbdkit/go.mod ./viperblock/nbd/libguestfs.org/nbdkit/ COPY northstar/go.mod northstar/go.sum ./northstar/ COPY bluebottle/go.mod bluebottle/go.sum ./bluebottle/ # Generate go.work (gitignored, so not in checkout) RUN cd spinifex && go work init . ../predastore ../viperblock ../viperblock/nbd ../viperblock/nbd/libguestfs.org/nbdkit ../northstar ../bluebottle # Download dependencies (cached layer) RUN cd spinifex && go mod download # Copy full source COPY spinifex/ ./spinifex/ COPY predastore/ ./predastore/ COPY viperblock/ ./viperblock/ COPY northstar/ ./northstar/ COPY bluebottle/ ./bluebottle/ # Build spinifex binary (spx) RUN COMMIT=$(cd spinifex && git rev-parse --short HEAD 2>/dev/null || echo "unknown") && \ cd spinifex && GOFIPS140=v1.0.0 go build -ldflags "-s -w \ -X github.com/mulgadc/spinifex/spinifex/operator/cli.Version=${VERSION} \ -X github.com/mulgadc/spinifex/spinifex/operator/cli.Commit=${COMMIT}" \ -o /out/spx cmd/spinifex/main.go # Build nbdkit viperblock plugin (.so) RUN cd viperblock && GOFIPS140=v1.0.0 go build -o /out/nbdkit-viperblock-plugin.so -buildmode=c-shared nbd/viperblock.go # Copy setup scripts and systemd units RUN cp spinifex/scripts/setup.sh /out/setup.sh 2>/dev/null || true RUN cp spinifex/scripts/setup-ovn.sh /out/setup-ovn.sh RUN mkdir -p /out/systemd && cp spinifex/build/systemd/* /out/systemd/ RUN mkdir -p /out/scripts && cp spinifex/build/scripts/* /out/scripts/ RUN cp spinifex/build/logrotate/spinifex /out/logrotate-spinifex FROM scratch AS export COPY --from=builder /out/ /