Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
120 lines (114 loc) · 6.59 KB
/
Copy pathDockerfile
File metadata and controls
120 lines (114 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.25 AS builder
ARG TARGETOS
ARG TARGETARCH
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the Go source (relies on .dockerignore to filter)
COPY . .
# Build
# the GOARCH has no default value to allow the binary to be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
#
# Bug 169: stamp `version.LinstorGitHash` / `version.LinstorBuildTime`
# at link time via `-ldflags -X`. Pre-fix the constants in
# `pkg/version/version.go` shipped as the literal placeholders
# `"blockstor"` and `"2026-01-01T00:00:00+00:00"`, so every image
# carried the same fake identity on /v1/controller/version and
# operators could not correlate a wire bug to a commit. The vars are
# also propagated for legacy `version.Version` / `version.GitCommit`
# (logger banners).
#
# Bug 171: callers (`stand/build-images.sh`, top-level Makefile)
# resolve the SHA on the HOST and pass it via --build-arg, because
# `.dockerignore` excludes `.git` — the in-container `git rev-parse`
# fallback below only kicks in for the (rare) case where someone runs
# `docker build .` directly without going through the wrappers and
# `.dockerignore` happens to be permissive. Default is the structured
# sentinel `sha-build-arg-missing` so a misconfigured CI is obvious
# (not the previous `unknown`, which is indistinguishable from a real
# tarball build).
ARG GIT_HASH=sha-build-arg-missing
ARG BUILD_TIME
# VERSION is the release the image is built for, logged by every binary
# at start-up (`blockstor_version`). The release workflow passes the tag;
# a dev build keeps version.go's `0.0.0-dev`.
ARG VERSION=0.0.0-dev
ENV LDFLAGS="-X github.com/cozystack/blockstor/pkg/version.LinstorGitHash=${GIT_HASH} \
-X github.com/cozystack/blockstor/pkg/version.GitCommit=${GIT_HASH} \
-X github.com/cozystack/blockstor/pkg/version.Version=${VERSION} \
-X github.com/cozystack/blockstor/pkg/version.LinstorBuildTime=${BUILD_TIME}"
RUN if [ -d .git ]; then GIT_HASH=$(git rev-parse HEAD 2>/dev/null || echo "${GIT_HASH}"); fi; \
BUILD_TIME=${BUILD_TIME:-$(date -u +%FT%TZ)}; \
LDFLAGS="-X github.com/cozystack/blockstor/pkg/version.LinstorGitHash=${GIT_HASH} \
-X github.com/cozystack/blockstor/pkg/version.GitCommit=${GIT_HASH} \
-X github.com/cozystack/blockstor/pkg/version.Version=${VERSION} \
-X github.com/cozystack/blockstor/pkg/version.LinstorBuildTime=${BUILD_TIME}"; \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "${LDFLAGS}" -o controller ./cmd/controller && \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "${LDFLAGS}" -o apiserver ./cmd/apiserver && \
CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "${LDFLAGS}" -o satellite ./cmd/satellite
# The satellite needs to shell out to drbdadm/lvs/zfs/cryptsetup, none
# of which are in distroless:static. We use debian-slim for it (and let
# the controller image stay distroless for the smaller surface). The
# manager is what ships under "blockstor:dev"; the satellite ships under
# "blockstor-satellite:dev".
FROM gcr.io/distroless/static:nonroot AS controller
WORKDIR /
COPY --from=builder /workspace/controller .
USER 65532:65532
ENTRYPOINT ["/controller"]
# The apiserver is the LINSTOR-compatible REST front-end split out
# of the controller (Phase 11). It runs N replicas behind a Service
# and serves linstor-csi / `linstor` CLI / piraeus-operator. Same
# distroless surface as the controller — no shell-outs.
FROM gcr.io/distroless/static:nonroot AS apiserver
WORKDIR /
COPY --from=builder /workspace/apiserver .
USER 65532:65532
ENTRYPOINT ["/apiserver"]
FROM debian:trixie-slim AS satellite
# drbd-utils comes from LINBIT's public repository, the one the LINSTOR
# satellite image is built from, and which that image installs unpinned.
# Debian's own package is 9.22, whose drbdadm predates the device options
# (block-size, discard-granularity) LINSTOR writes into a volume's disk
# section: it refuses such a .res as a parse error, and since drbdadm
# reads every .res on the node, one adopted volume carrying block-size
# stops adjust for every resource there.
# 9.36.0 is the first drbdmeta that keeps the bitmap provenance feature
# DRBD 9.3.4 writes into the superblock. Older ones clear it, so the
# apply-al run after every crash makes the kernel count a crashed
# Secondary's activity log bits as bits its peers lack: at equal current
# UUIDs the crashed node then becomes a resync source, or a Primary peer
# refuses the connection as a SyncTarget.
ARG DRBD_UTILS_VERSION=9.36.0-1
# zfsutils-linux is in contrib on trixie — enable it so we can pull
# zpool/zfs alongside drbd-utils, lvm2, cryptsetup. Note: the kernel
# module is provided by the host (Talos siderolabs/zfs extension);
# this image only ships the userspace tools.
# The keyring is the root of trust for every LINBIT package, so it is
# pinned by digest rather than trusted on TLS alone: a changed file
# fails the build instead of installing a key nobody reviewed.
ARG LINBIT_KEYRING_SHA256=4d5d50224d5e2da0d0afa3ccf56e4ea9c1afa07d690ac458b445481584cd3947
ADD https://packages.linbit.com/public/linbit-keyring.deb /tmp/linbit-keyring.deb
RUN echo "${LINBIT_KEYRING_SHA256} /tmp/linbit-keyring.deb" | sha256sum -c - && \
sed -i 's|^Components: main$|Components: main contrib|' /etc/apt/sources.list.d/debian.sources && \
apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates && \
dpkg -i /tmp/linbit-keyring.deb && rm /tmp/linbit-keyring.deb && \
echo "deb https://packages.linbit.com/public trixie misc" > /etc/apt/sources.list.d/linbit.list && \
apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
drbd-utils="${DRBD_UTILS_VERSION}" lvm2 cryptsetup-bin zfsutils-linux gdisk parted \
iptables \
e2fsprogs xfsprogs && \
rm -rf /var/lib/apt/lists/*
WORKDIR /
COPY --from=builder /workspace/satellite /usr/local/bin/satellite
ENTRYPOINT ["/usr/local/bin/satellite"]