-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDockerfile.dpf-system
More file actions
67 lines (54 loc) · 2.2 KB
/
Dockerfile.dpf-system
File metadata and controls
67 lines (54 loc) · 2.2 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
ARG builder_image
ARG base_image
# 1) Firmware download stage - separate to cache this expensive download
FROM --platform=${BUILDPLATFORM} ${builder_image} AS firmware
# Download the bf3 firmware package
RUN curl --proto "=https" --tlsv1.2 -L https://linux.mellanox.com/public/repo/bluefield/BMC/BF3/bmc/24.10-17/bf3-bmc-24.10-17_opn.fwpkg -o /tmp/bf3-bmc.fwpkg
# 2) Builder stage - vendor dependencies and build binaries
FROM --platform=${BUILDPLATFORM} ${builder_image} AS builder
WORKDIR /workspace
ARG gcflags
ARG ldflags
ARG TARGETARCH
ENV GO_LDFLAGS=${ldflags}
ENV GO_GCFLAGS=${gcflags}
ENV ARCH=${TARGETARCH}
# Copy source files
COPY go.mod go.sum ./
COPY third_party/ third_party/
COPY api/ api/
COPY cmd/ cmd/
COPY test/ test/
COPY internal/ internal/
COPY pkg/ pkg/
# Vendor dependencies first
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod vendor
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=Makefile,target=Makefile \
--mount=type=bind,source=hack/tools/tools.mk,target=hack/tools/tools.mk \
GOFLAGS="-mod=vendor" make binaries-dpf-system
# Copy the go source code so it can be distributed in the final image.
RUN mkdir src && \
find . -name '*.go' -not -path "./hack/*" -not -path "./.gocache/*" \
-exec cp --parents \{\} src/ \; && \
tar -czf source-code.tar.gz src
# 3) Version stage to create the DPF version file.
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
# 4) Final stage copies artefacts from previous stages.
FROM ${base_image}
ARG TARGETARCH
WORKDIR /
# Ensure all files are copied with the correct user.
ENV uid=65532
USER ${uid}:${uid}
COPY --chown=${uid} --from=builder /workspace/source-code.tar.gz source-code.tar.gz
COPY --chown=${uid} --from=builder /workspace/bin/ .
COPY --chown=root:root --chmod=755 --from=firmware /tmp/bf3-bmc.fwpkg .
COPY --chown=root:root build/defaults.yaml /etc/dpf-defaults.yaml
COPY --chown=root:root --from=version /tmp/dpf-version /etc/dpf-version