-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDockerfile.storage-host
More file actions
104 lines (84 loc) · 3.69 KB
/
Dockerfile.storage-host
File metadata and controls
104 lines (84 loc) · 3.69 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
ARG builder_image
ARG storage_host_base_image
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-host
# 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
# 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
FROM ${storage_host_base_image}
ARG PACKAGES="keyutils libevent-core-2.1-7t64 libnfsidmap1 libwrap0 nfs-common rpcbind ucf"
ARG ubuntu_mirror=http://archive.ubuntu.com/ubuntu/
RUN find /etc/apt/sources.list* -type f -exec sed -i \
-e "s|http://archive.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" \
-e "s|http://ports.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" \
-e "s|http://security.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" '{}' \;
RUN rm -f /etc/apt/sources.list.d/doca.list
# install nfs-common required by the fs-storage-vendor-dpu-plugin
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get upgrade -y -qq && \
apt-get install -y -qq --no-install-recommends ${PACKAGES}
WORKDIR /
# Move source code to a directory
ARG PACKAGE_SOURCES
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
test "${PACKAGE_SOURCES}" = "false" || ( \
mkdir /src && \
cd /src && \
# Enable deb-src to be able to fetch sources
sed -i 's/^# deb-src/deb-src/g' /etc/apt/sources.list /etc/apt/sources.list.d/* && \
sed -i 's/^Types: deb$/Types: deb deb-src/g' /etc/apt/sources.list.d/*.sources && \
apt-get update && \
apt-get source --download-only ${PACKAGES} && \
cd / && \
tar -cf pkg-source-code.tar /src && \
rm -rf /src \
)
# Add the source code.
COPY --from=builder /workspace/source-code.tar.gz /source-code.tar.gz
# Add the DPF binaries
COPY --from=builder /workspace/bin/snap-csi-plugin /snap-csi-plugin
COPY --from=builder /workspace/bin/fs-storage-vendor-dpu-plugin /fs-storage-vendor-dpu-plugin
# 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