|
| 1 | +ARG builder_image |
| 2 | + |
| 3 | +FROM --platform=${BUILDPLATFORM} ${builder_image} AS ovnkubernetes-builder |
| 4 | + |
| 5 | +ARG TARGETARCH |
| 6 | +ARG gcflags |
| 7 | +ARG ldflags |
| 8 | + |
| 9 | +WORKDIR /workspace |
| 10 | +RUN apt update && apt install -y make git |
| 11 | +ARG ovn_kubernetes_dir |
| 12 | +COPY ${ovn_kubernetes_dir} ovn-kubernetes |
| 13 | +RUN cd ovn-kubernetes/dist/images && \ |
| 14 | + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make bld |
| 15 | + |
| 16 | +ARG ipallocator_dir |
| 17 | +COPY ./ ./ |
| 18 | +COPY go.mod go.mod |
| 19 | +COPY go.sum go.sum |
| 20 | + |
| 21 | +RUN --mount=type=cache,target=/go/pkg/mod \ |
| 22 | + go mod download |
| 23 | + |
| 24 | +RUN --mount=type=cache,target=/root/.cache/go-build \ |
| 25 | + --mount=type=cache,target=/go/pkg/mod \ |
| 26 | + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ |
| 27 | + go build -trimpath \ |
| 28 | + -ldflags="${ldflags}" \ |
| 29 | + -gcflags="${gcflags}" \ |
| 30 | + -o ipallocator ./cmd/ipallocator |
| 31 | + |
| 32 | +RUN --mount=type=cache,target=/root/.cache/go-build \ |
| 33 | + --mount=type=cache,target=/go/pkg/mod \ |
| 34 | + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ |
| 35 | + go build -trimpath \ |
| 36 | + -ldflags="${ldflags}" \ |
| 37 | + -gcflags="${gcflags}" \ |
| 38 | + -o dpucniprovisioner ./cmd/dpucniprovisioner |
| 39 | + |
| 40 | +RUN --mount=type=cache,target=/root/.cache/go-build \ |
| 41 | + --mount=type=cache,target=/go/pkg/mod \ |
| 42 | + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ |
| 43 | + go build -trimpath \ |
| 44 | + -ldflags="${ldflags}" \ |
| 45 | + -gcflags="${gcflags}" \ |
| 46 | + -o ovnkubernetesresourceinjector ./cmd/ovnkubernetesresourceinjector |
| 47 | + |
| 48 | +# Create source code archive excluding .gocache, and test files. |
| 49 | +# Skipping `.gocache` since it contains pre-compiled versions of packages and other build artifacts for speeding up subsequent builds |
| 50 | +RUN mkdir src && \ |
| 51 | + find . -name '*.go' \ |
| 52 | + -not -path "./hack/*" \ |
| 53 | + -not -path "./.gocache/*" \ |
| 54 | + -not -name "*_test.go" \ |
| 55 | + -exec cp --parents {} src/ \; && \ |
| 56 | + tar -czf source-code.tar.gz src |
| 57 | + |
| 58 | +# Build the final image |
| 59 | +FROM nvcr.io/nvidia/doca/canonical:ubuntu24.04 |
| 60 | + |
| 61 | +ARG TARGETARCH |
| 62 | + |
| 63 | +USER root |
| 64 | + |
| 65 | +ARG ubuntu_mirror=http://archive.ubuntu.com/ubuntu/ |
| 66 | +ARG BASE_PACKAGES="iproute2 curl software-properties-common util-linux dnsmasq" |
| 67 | + |
| 68 | +# Dependencies for installing OVN (Netplan, systemd and udev required by dpucniprovisioner). |
| 69 | +ARG OVN_PACKAGES="openvswitch-switch openvswitch-common netplan.io udev systemd" |
| 70 | + |
| 71 | +RUN dpkg -l | awk '/^ii/{print $2"="$3}' | sort > /initial-dpkg-list.txt |
| 72 | + |
| 73 | +RUN find /etc/apt/sources.list* -type f -exec sed -i \ |
| 74 | + -e "s|http://archive.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" \ |
| 75 | + -e "s|http://ports.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" \ |
| 76 | + -e "s|http://security.ubuntu.com/ubuntu/|${ubuntu_mirror}|g" '{}' \; |
| 77 | + |
| 78 | +RUN apt-get update && \ |
| 79 | + apt-get install -y -qq ${BASE_PACKAGES} && \ |
| 80 | + apt-get clean && \ |
| 81 | + rm -rf /var/lib/apt/lists/* |
| 82 | + |
| 83 | +RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - |
| 84 | + |
| 85 | +RUN apt-get update && \ |
| 86 | + apt-get install -y -qq --no-install-recommends ${OVN_PACKAGES} && \ |
| 87 | + apt-get clean && \ |
| 88 | + rm -rf /var/lib/apt/lists/* |
| 89 | + |
| 90 | +RUN dpkg -l | awk '/^ii/{print $2"="$3}' | sort > /after-ovn-dpkg-list.txt |
| 91 | + |
| 92 | +ARG KUBECTL_VERSION=1.33.2 |
| 93 | +RUN curl -LO "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${TARGETARCH}/kubectl" && \ |
| 94 | + install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl |
| 95 | + |
| 96 | +ARG OVN_VERSION="24.03.6" |
| 97 | + |
| 98 | +RUN curl -fsSL "https://github.com/Mellanox/ovn/releases/download/v${OVN_VERSION}/ovn-common_${OVN_VERSION}-1_${TARGETARCH}.deb" \ |
| 99 | + -o ovn-common_${OVN_VERSION}-1_${TARGETARCH}.deb && \ |
| 100 | + curl -fsSL "https://github.com/Mellanox/ovn/releases/download/v${OVN_VERSION}/ovn-central_${OVN_VERSION}-1_${TARGETARCH}.deb" \ |
| 101 | + -o ovn-central_${OVN_VERSION}-1_${TARGETARCH}.deb && \ |
| 102 | + curl -fsSL "https://github.com/Mellanox/ovn/releases/download/v${OVN_VERSION}/ovn-host_${OVN_VERSION}-1_${TARGETARCH}.deb" \ |
| 103 | + -o ovn-host_${OVN_VERSION}-1_${TARGETARCH}.deb |
| 104 | + |
| 105 | +RUN dpkg -i "ovn-common_${OVN_VERSION}-1_${TARGETARCH}.deb" \ |
| 106 | + "ovn-central_${OVN_VERSION}-1_${TARGETARCH}.deb" \ |
| 107 | + "ovn-host_${OVN_VERSION}-1_${TARGETARCH}.deb" && \ |
| 108 | + rm "ovn-common_${OVN_VERSION}-1_${TARGETARCH}.deb" \ |
| 109 | + "ovn-central_${OVN_VERSION}-1_${TARGETARCH}.deb" \ |
| 110 | + "ovn-host_${OVN_VERSION}-1_${TARGETARCH}.deb" |
| 111 | + |
| 112 | +RUN mkdir -p /var/run/openvswitch |
| 113 | + |
| 114 | +# Built in ../../go_controller, then the binaries are copied here. |
| 115 | +# put things where they are in the pkg |
| 116 | +RUN mkdir -p /usr/libexec/cni/ |
| 117 | +COPY --from=ovnkubernetes-builder /workspace/ipallocator /ipallocator |
| 118 | +COPY --from=ovnkubernetes-builder /workspace/dpucniprovisioner /cniprovisioner |
| 119 | +COPY --from=ovnkubernetes-builder /workspace/ovnkubernetesresourceinjector /ovnkubernetesresourceinjector |
| 120 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/go-controller/_output/go/bin/ovnkube /usr/bin/ |
| 121 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/go-controller/_output/go/bin/ovn-kube-util /usr/bin/ |
| 122 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/go-controller/_output/go/bin/ovndbchecker /usr/bin/ |
| 123 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/go-controller/_output/go/bin/hybrid-overlay-node /usr/bin/ |
| 124 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/go-controller/_output/go/bin/ovnkube-identity /usr/bin/ |
| 125 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/go-controller/_output/go/bin/ovn-k8s-cni-overlay /usr/libexec/cni/ovn-k8s-cni-overlay |
| 126 | + |
| 127 | +# ovnkube.sh is the entry point. This script examines environment |
| 128 | +# variables to direct operation and configure ovn |
| 129 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/ovnkube.sh /root/ |
| 130 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/ovndb-raft-functions.sh /root/ |
| 131 | +# override the pkg's ovn_k8s.conf with this local copy |
| 132 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/ovn_k8s.conf /etc/openvswitch/ovn_k8s.conf |
| 133 | + |
| 134 | +# copy git commit number into image |
| 135 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/git_info /root |
| 136 | + |
| 137 | +# iptables wrappers |
| 138 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/iptables-scripts/iptables /usr/sbin/ |
| 139 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/iptables-scripts/iptables-save /usr/sbin/ |
| 140 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/iptables-scripts/iptables-restore /usr/sbin/ |
| 141 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/iptables-scripts/ip6tables /usr/sbin/ |
| 142 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/iptables-scripts/ip6tables-save /usr/sbin/ |
| 143 | +COPY --from=ovnkubernetes-builder /workspace/ovn-kubernetes/dist/images/iptables-scripts/ip6tables-restore /usr/sbin/ |
| 144 | + |
| 145 | +# Get all the source code |
| 146 | +RUN mkdir -p /src |
| 147 | +WORKDIR /src |
| 148 | + |
| 149 | +# Copy ovn-kubernetes source code from builder stage |
| 150 | +COPY --from=ovnkubernetes-builder /workspace/source-code.tar.gz ovn-kubernetes-source-code.tar.gz |
| 151 | + |
| 152 | +RUN curl -fsSL -o kubectl-${KUBECTL_VERSION}.tar.gz \ |
| 153 | + https://github.com/kubernetes/kubectl/archive/refs/tags/kubernetes-${KUBECTL_VERSION}.tar.gz |
| 154 | + |
| 155 | +RUN curl -fsSL -o ovn-${OVN_VERSION}.tar.gz \ |
| 156 | + https://github.com/Mellanox/ovn/archive/refs/tags/v${OVN_VERSION}.tar.gz |
| 157 | + |
| 158 | +# Download source code for apt packages. |
| 159 | +# Starting from Ubuntu 24.04 shifted to the new deb822 format for source management. |
| 160 | +# Enable `deb-src` to be able to fetch sources using `apt-get source` |
| 161 | +ARG PACKAGE_SOURCES |
| 162 | +RUN test "${PACKAGE_SOURCES}" = "false" || ( \ |
| 163 | + sed -i 's/^# deb-src/deb-src/g' /etc/apt/sources.list /etc/apt/sources.list.d/* && \ |
| 164 | + sed -i 's/^Types: deb$/Types: deb deb-src/g' /etc/apt/sources.list.d/*.sources && \ |
| 165 | + apt-get update && \ |
| 166 | + apt-get source --download-only ${BASE_PACKAGES} ${OVN_PACKAGES} && \ |
| 167 | + comm -23 /after-ovn-dpkg-list.txt /initial-dpkg-list.txt | xargs -r apt-get source --download-only && \ |
| 168 | + apt-get clean && \ |
| 169 | + rm -f /initial-dpkg-list.txt /after-ovn-dpkg-list.txt && \ |
| 170 | + rm -rf /var/lib/apt/lists/* && \ |
| 171 | + cd / && \ |
| 172 | + tar -cf source-code.tar /src && \ |
| 173 | + rm -rf /src \ |
| 174 | + ) |
| 175 | + |
| 176 | +LABEL io.k8s.display-name="ovn-kubernetes" \ |
| 177 | + io.k8s.description="ovn-kubernetes ubuntu image" |
| 178 | + |
| 179 | +WORKDIR /root |
| 180 | +ENTRYPOINT /root/ovnkube.sh |
0 commit comments