Kubernetes Operator for Tangled Spindles
1# Build both binaries
2# Use BUILDPLATFORM so Go runs natively, cross-compile for target arch
3FROM --platform=$BUILDPLATFORM golang:1.25-trixie AS builder
4
5ARG TARGETOS
6ARG TARGETARCH
7ARG BUILDARCH
8
9# Install C cross-compiler for CGO when building arm64 from amd64
10RUN if [ "$BUILDARCH" = "amd64" ] && [ "$TARGETARCH" = "arm64" ]; then \
11 apt-get update && apt-get install -y gcc-aarch64-linux-gnu && rm -rf /var/lib/apt/lists/*; \
12 fi
13
14WORKDIR /workspace
15
16# Copy go mod files and download deps
17COPY go.mod go.sum ./
18RUN go mod download
19
20# Copy source code
21COPY api/ api/
22COPY cmd/ cmd/
23COPY internal/ internal/
24
25# Build runner (static, no CGO)
26# Use -s -w to strip debug symbols and reduce binary size
27RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \
28 go build -a -ldflags='-s -w -extldflags "-static"' \
29 -o loom-runner ./cmd/runner
30
31# Build controller (requires CGO for sqlite3)
32# Use -s -w to strip debug symbols and reduce binary size
33# Use cross-compiler for arm64 when building from amd64
34RUN CC=$(if [ "$TARGETARCH" = "arm64" ] && [ "$BUILDARCH" = "amd64" ]; then echo "aarch64-linux-gnu-gcc"; else echo "gcc"; fi) && \
35 CGO_ENABLED=1 CC=$CC GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \
36 go build -a -ldflags='-s -w' -o manager ./cmd/controller
37
38# Unified image with both binaries
39FROM gcr.io/distroless/base-debian13:nonroot
40COPY --from=builder /workspace/manager /manager
41COPY --from=builder /workspace/loom-runner /loom-runner
42
43LABEL org.opencontainers.image.title="Loom" \
44 org.opencontainers.image.description="Kubernetes Operator for Tangled Spindles " \
45 org.opencontainers.image.authors="Evan Jarrett" \
46 org.opencontainers.image.source="https://tangled.org/evan.jarrett.net/loom" \
47 org.opencontainers.image.documentation="https://tangled.org/evan.jarrett.net/loom" \
48 org.opencontainers.image.licenses="Apache-2.0" \
49 org.opencontainers.image.version="latest"
50
51ENTRYPOINT ["/manager"]