Repository navigation
Expand file tree
/
Copy pathDockerfile.storage-system
More file actions
79 lines (65 loc) · 2.98 KB
/
Copy pathDockerfile.storage-system
File metadata and controls
79 lines (65 loc) · 2.98 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
ARG builder_image
ARG base_image
# 1) Build stage builds go binaries (no emulation).
FROM --platform=${BUILDPLATFORM} ${builder_image} AS builder
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 --mount=type=cache,target=/go/pkg/mod \
go mod download
COPY third_party/ third_party/
COPY api/ api/
COPY cmd/ cmd/
COPY test/ test/
COPY internal/ internal/
COPY pkg/ pkg/
# Note: .gitmodules and .git/modules/ NOT copied - they cause cache invalidation
# The third_party/ directory already contains the submodule contents
COPY hack/tools/tools.mk hack/tools/tools.mk
COPY hack/boilerplate.go.txt hack/boilerplate.go.txt
ARG gcflags
ARG ldflags
ARG TARGETARCH
ENV GO_LDFLAGS=${ldflags}
ENV GO_GCFLAGS=${gcflags}
ENV ARCH=${TARGETARCH}
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=bind,source=Makefile,target=Makefile \
--mount=type=bind,source=hack/tools/tools.mk,target=hack/tools/tools.mk \
make binaries-storage-system
# Copy the go source code so it can be distributed in the final image.
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod vendor
RUN mkdir src && \
find . -name '*.go' -not -path "./hack/*" -not -path "./.gocache/*" \
-exec cp --parents \{\} src/ \; && \
tar -czf source-code.tar.gz src
# 2) Version stage creates the version file separately to avoid invalidating builder cache
FROM ${builder_image} AS version
ARG TAG
# Write the DPF version file (separate stage to preserve builder cache when only TAG changes).
# The command echo is not present in the final image so this stage is needed.
RUN echo "${TAG}" > /tmp/dpf-version
# 3) Final stage copies artifacts from the builder stage.
FROM ${base_image}
ARG TARGETARCH
WORKDIR /
# Ensure all files are copied with the correct user.
ENV uid=65532
USER ${uid}:${uid}
# Add the source code.
COPY --chown=${uid} --from=builder /workspace/source-code.tar.gz source-code.tar.gz
# Add the DPF binaries
COPY --chown=${uid} --chmod=755 --from=builder /workspace/bin/snap-csi-plugin /snap-csi-plugin
COPY --chown=${uid} --chmod=755 --from=builder /workspace/bin/snap-node-driver /snap-node-driver
COPY --chown=${uid} --chmod=755 --from=builder /workspace/bin/block-storage-vendor-dpu-plugin /block-storage-vendor-dpu-plugin
COPY --chown=${uid} --chmod=755 --from=builder /workspace/bin/nfs-storage-vendor-dpu-plugin /nfs-storage-vendor-dpu-plugin
COPY --chown=${uid} --chmod=755 --from=builder /workspace/bin/nvidia-external-attacher /nvidia-external-attacher
COPY --chown=${uid} --chmod=755 --from=builder /workspace/bin/snap-host-controller /snap-host-controller
# Copy the DPF version file from version stage (not builder, to preserve builder cache)
COPY --chown=root:root --from=version /tmp/dpf-version /etc/dpf-version