|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2019 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +ARG GOLANG_VERSION=x.x.x |
| 17 | +ARG VERSION="N/A" |
| 18 | + |
| 19 | +FROM nvcr.io/nvidia/cuda:12.9.0-base-ubi8 AS build |
| 20 | + |
| 21 | +RUN dnf install -y \ |
| 22 | + wget make git gcc \ |
| 23 | + && \ |
| 24 | + rm -rf /var/cache/yum/* |
| 25 | + |
| 26 | +ARG GOLANG_VERSION=x.x.x |
| 27 | +RUN set -eux; \ |
| 28 | + \ |
| 29 | + arch="$(uname -m)"; \ |
| 30 | + case "${arch##*-}" in \ |
| 31 | + x86_64 | amd64) ARCH='amd64' ;; \ |
| 32 | + ppc64el | ppc64le) ARCH='ppc64le' ;; \ |
| 33 | + aarch64 | arm64) ARCH='arm64' ;; \ |
| 34 | + *) echo "unsupported architecture" ; exit 1 ;; \ |
| 35 | + esac; \ |
| 36 | + wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${ARCH}.tar.gz \ |
| 37 | + | tar -C /usr/local -xz |
| 38 | + |
| 39 | + |
| 40 | +ENV GOPATH=/go |
| 41 | +ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH |
| 42 | + |
| 43 | +WORKDIR /build |
| 44 | +COPY . . |
| 45 | + |
| 46 | +RUN mkdir -p /artifacts/bin |
| 47 | +ARG VERSION="N/A" |
| 48 | +ARG GIT_COMMIT="unknown" |
| 49 | +RUN make PREFIX=/artifacts/bin cmd-nvidia-ctk-installer |
| 50 | + |
| 51 | +# The packaging stage collects the deb and rpm packages built for supported |
| 52 | +# architectures. |
| 53 | +FROM nvcr.io/nvidia/cuda:12.9.0-base-ubi8 AS packaging |
| 54 | + |
| 55 | +ARG ARTIFACTS_ROOT |
| 56 | +COPY ${ARTIFACTS_ROOT} /artifacts/packages/ |
| 57 | + |
| 58 | +WORKDIR /artifacts/packages |
| 59 | + |
| 60 | +# build-args are added to the manifest.txt file below. |
| 61 | +ARG PACKAGE_VERSION |
| 62 | +ARG GIT_BRANCH |
| 63 | +ARG GIT_COMMIT |
| 64 | +ARG GIT_COMMIT_SHORT |
| 65 | +ARG SOURCE_DATE_EPOCH |
| 66 | +ARG VERSION |
| 67 | + |
| 68 | +# Create a manifest.txt file with the absolute paths of all deb and rpm packages in the container |
| 69 | +RUN echo "#IMAGE_EPOCH=$(date '+%s')" > /artifacts/manifest.txt && \ |
| 70 | + env | sed 's/^/#/g' >> /artifacts/manifest.txt && \ |
| 71 | + find /artifacts/packages -iname '*.deb' -o -iname '*.rpm' >> /artifacts/manifest.txt |
| 72 | + |
| 73 | +RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE |
| 74 | + |
| 75 | +# The debpackages stage is used to extract the contents of deb packages. |
| 76 | +FROM nvcr.io/nvidia/cuda:12.9.0-base-ubuntu20.04 AS debpackages |
| 77 | + |
| 78 | +ARG TARGETARCH |
| 79 | +ARG PACKAGE_DIST_DEB=ubuntu18.04 |
| 80 | + |
| 81 | +COPY --from=packaging /artifacts/packages/${PACKAGE_DIST_DEB} /deb-packages |
| 82 | + |
| 83 | +RUN mkdir -p /artifacts/deb |
| 84 | +RUN set -eux; \ |
| 85 | + \ |
| 86 | + case "${TARGETARCH}" in \ |
| 87 | + x86_64 | amd64) ARCH='amd64' ;; \ |
| 88 | + ppc64el | ppc64le) ARCH='ppc64le' ;; \ |
| 89 | + aarch64 | arm64) ARCH='arm64' ;; \ |
| 90 | + *) echo "unsupported architecture" ; exit 1 ;; \ |
| 91 | + esac; \ |
| 92 | + for p in $(ls /deb-packages/${ARCH}/*.deb); do dpkg-deb -xv $p /artifacts/deb/; done |
| 93 | + |
| 94 | +# The rpmpackages stage is used to extract the contents of the rpm packages. |
| 95 | +FROM nvcr.io/nvidia/cuda:12.9.0-base-ubi8 AS rpmpackages |
| 96 | +RUN dnf install -y cpio |
| 97 | + |
| 98 | +ARG TARGETARCH |
| 99 | +ARG PACKAGE_DIST_RPM=centos7 |
| 100 | + |
| 101 | +COPY --from=packaging /artifacts/packages/${PACKAGE_DIST_RPM} /rpm-packages |
| 102 | + |
| 103 | +RUN mkdir -p /artifacts/rpm |
| 104 | +RUN set -eux; \ |
| 105 | + \ |
| 106 | + case "${TARGETARCH}" in \ |
| 107 | + x86_64 | amd64) ARCH='x86_64' ;; \ |
| 108 | + ppc64el | ppc64le) ARCH='ppc64le' ;; \ |
| 109 | + aarch64 | arm64) ARCH='aarch64' ;; \ |
| 110 | + *) echo "unsupported architecture" ; exit 1 ;; \ |
| 111 | + esac; \ |
| 112 | + for p in $(ls /rpm-packages/${ARCH}/*.rpm); do rpm2cpio $p | cpio -idmv -D /artifacts/rpm; done |
| 113 | + |
| 114 | +# The artifacts image serves as an intermediate stage to collect the artifacts |
| 115 | +# From the previous stages: |
| 116 | +# - The extracted deb packages |
| 117 | +# - The extracted rpm packages |
| 118 | +# - The nvidia-ctk-installer binary |
| 119 | +FROM nvcr.io/nvidia/cuda:12.9.0-base-ubi8 AS artifacts |
| 120 | + |
| 121 | +COPY --from=rpmpackages /artifacts/rpm /artifacts/rpm |
| 122 | +COPY --from=debpackages /artifacts/deb /artifacts/deb |
| 123 | +COPY --from=build /artifacts/bin /artifacts/build |
| 124 | + |
| 125 | +FROM nvcr.io/nvidia/cuda:12.9.0-base-ubi8 |
| 126 | + |
| 127 | +ENV NVIDIA_DISABLE_REQUIRE="true" |
| 128 | +ENV NVIDIA_VISIBLE_DEVICES=void |
| 129 | +ENV NVIDIA_DRIVER_CAPABILITIES=utility |
| 130 | + |
| 131 | +COPY --from=artifacts /artifacts/rpm /artifacts/rpm |
| 132 | +COPY --from=artifacts /artifacts/deb /artifacts/deb |
| 133 | +COPY --from=artifacts /artifacts/build /work |
| 134 | + |
| 135 | +WORKDIR /work |
| 136 | +ENV PATH=/work:$PATH |
| 137 | + |
| 138 | +ARG VERSION |
| 139 | +LABEL io.k8s.display-name="NVIDIA Container Runtime Config" |
| 140 | +LABEL name="NVIDIA Container Runtime Config" |
| 141 | +LABEL vendor="NVIDIA" |
| 142 | +LABEL version="${VERSION}" |
| 143 | +LABEL release="N/A" |
| 144 | +LABEL summary="Automatically Configure your Container Runtime for GPU support." |
| 145 | +LABEL description="See summary" |
| 146 | + |
| 147 | +RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE |
| 148 | + |
| 149 | +ENTRYPOINT ["/work/nvidia-ctk-installer"] |
0 commit comments