forked from Mellanox/ovn-kubernetes-dpf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
113 lines (88 loc) · 3.73 KB
/
Dockerfile
File metadata and controls
113 lines (88 loc) · 3.73 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
ARG builder_image
FROM --platform=${BUILDPLATFORM} ${builder_image} AS builder
ARG TARGETARCH
ARG gcflags
ARG ldflags
WORKDIR /workspace
ARG ipallocator_dir
COPY ./ ./
COPY go.mod go.mod
COPY go.sum go.sum
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath \
-ldflags="${ldflags}" \
-gcflags="${gcflags}" \
-o ipallocator ./cmd/ipallocator
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath \
-ldflags="${ldflags}" \
-gcflags="${gcflags}" \
-o dpucniprovisioner ./cmd/dpucniprovisioner
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath \
-ldflags="${ldflags}" \
-gcflags="${gcflags}" \
-o ovnkubernetesresourceinjector ./cmd/ovnkubernetesresourceinjector
# Create source code archive excluding .gocache, and test files.
# Skipping `.gocache` since it contains pre-compiled versions of packages and other build artifacts for speeding up subsequent builds
RUN mkdir src && \
find . -name '*.go' \
-not -path "./hack/*" \
-not -path "./.gocache/*" \
-not -name "*_test.go" \
-exec cp --parents {} src/ \; && \
tar -czf source-code.tar.gz src
# Build the final image
FROM nvcr.io/nvidia/doca/canonical:ubuntu24.04
ARG TARGETARCH
USER root
ARG ubuntu_mirror=http://archive.ubuntu.com/ubuntu/
# Dependencies for installing OVN (Netplan, systemd and udev required by dpucniprovisioner).
ARG PACKAGES="openvswitch-switch netplan.io udev systemd dnsmasq"
RUN dpkg -l | awk '/^ii/{print $2"="$3}' | sort > /initial-dpkg-list.txt
RUN find /etc/apt/sources.list* -type f -exec sed -i \
-e "s|http://archive.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" \
-e "s|http://security.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" '{}' \;
RUN apt-get update && \
apt-get install -y --no-install-recommends ${PACKAGES} && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN dpkg -l | awk '/^ii/{print $2"="$3}' | sort > /after-ovn-dpkg-list.txt
RUN mkdir -p /var/run/openvswitch
RUN mkdir -p /usr/libexec/cni/
COPY --from=builder /workspace/ipallocator /ipallocator
COPY --from=builder /workspace/dpucniprovisioner /cniprovisioner
COPY --from=builder /workspace/ovnkubernetesresourceinjector /ovnkubernetesresourceinjector
# Get all the source code
RUN mkdir -p /src
WORKDIR /src
# Copy source code from builder stage
COPY --from=builder /workspace/source-code.tar.gz ovn-kubernetes-source-code.tar.gz
# Download source code for apt packages.
# Starting from Ubuntu 24.04 shifted to the new deb822 format for source management.
# Enable `deb-src` to be able to fetch sources using `apt-get source`
ARG PACKAGE_SOURCES
RUN test "${PACKAGE_SOURCES}" = "false" || ( \
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} && \
comm -23 /after-ovn-dpkg-list.txt /initial-dpkg-list.txt | xargs -r apt-get source --download-only && \
apt-get clean && \
rm -f /initial-dpkg-list.txt /after-ovn-dpkg-list.txt && \
rm -rf /var/lib/apt/lists/* && \
cd / && \
tar -cf source-code.tar /src && \
rm -rf /src \
)
LABEL io.k8s.display-name="ovn-kubernetes dpf utilities" \
io.k8s.description="ovn-kubernetes dpf utilities ubuntu image"
WORKDIR /root