From 4264988ac413e2e211eba72c4f2ea02ddfcd870d Mon Sep 17 00:00:00 2001 From: SataQiu Date: Fri, 9 Aug 2024 14:42:46 +0800 Subject: [PATCH] code cleanup and fix the bug that the default make goal can not work --- .github/workflows/main.yml | 5 +- Makefile | 38 ++++----------- docker/amd64/Dockerfile.centos7 | 43 ----------------- docker/amd64/Dockerfile.ubuntu20.04 | 32 +++++++++---- docker/amd64/Dockerfile.vgpu-ubuntu20.04 | 59 ------------------------ 5 files changed, 36 insertions(+), 141 deletions(-) delete mode 100644 docker/amd64/Dockerfile.centos7 delete mode 100644 docker/amd64/Dockerfile.vgpu-ubuntu20.04 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90b6744..8a6c684 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,5 +39,6 @@ jobs: id: buildx uses: docker/setup-buildx-action@v1 - - run: make vgpu - - run: TAG_VERSION="${BRANCH_NAME}" make push-vgpu-tag + - run: VERSION="${BRANCH_NAME}" make ubuntu20.04 + - run: VERSION="${BRANCH_NAME}" make push-short + - run: VERSION="${BRANCH_NAME}" make push-latest diff --git a/Makefile b/Makefile index 79e0dd7..eea0ea0 100644 --- a/Makefile +++ b/Makefile @@ -20,47 +20,27 @@ DOCKER ?= docker REGISTRY ?= projecthami -VERSION ?= latest -TAG_VERSION ?= 1.0.0 +VERSION ?= 1.0.0 ##### Public rules ##### -all: ubuntu20.04 centos7 +all: ubuntu20.04 push: - $(DOCKER) push "$(REGISTRY)/volcano-device-plugin:$(VERSION)-ubuntu20.04" - $(DOCKER) push "$(REGISTRY)/volcano-device-plugin:$(VERSION)-centos7" + $(DOCKER) push "$(REGISTRY)/volcano-vgpu-device-plugin:$(VERSION)-ubuntu20.04" push-short: - $(DOCKER) tag "$(REGISTRY)/volcano-device-plugin:$(VERSION)-ubuntu20.04" "$(REGISTRY)/volcano-device-plugin:$(VERSION)" - $(DOCKER) push "$(REGISTRY)/volcano-device-plugin:$(VERSION)" + $(DOCKER) tag "$(REGISTRY)/volcano-vgpu-device-plugin:$(VERSION)-ubuntu20.04" "$(REGISTRY)/volcano-vgpu-device-plugin:$(VERSION)" + $(DOCKER) push "$(REGISTRY)/volcano-vgpu-device-plugin:$(VERSION)" push-latest: - $(DOCKER) tag "$(REGISTRY)/volcano-device-plugin:$(VERSION)-ubuntu20.04" "$(REGISTRY)/volcano-device-plugin:latest" - $(DOCKER) push "$(REGISTRY)/volcano-device-plugin:latest" - -push-tag: - $(DOCKER) tag "$(REGISTRY)/volcano-device-plugin:$(VERSION)-ubuntu20.04" "$(REGISTRY)/volcano-device-plugin:$(TAG_VERSION)" - $(DOCKER) push "$(REGISTRY)/volcano-device-plugin:$(TAG_VERSION)" - -push-vgpu-tag: - $(DOCKER) tag "$(REGISTRY)/volcano-vgpu-device-plugin:$(VERSION)-ubuntu20.04" "$(REGISTRY)/volcano-vgpu-device-plugin:$(TAG_VERSION)" - $(DOCKER) push "$(REGISTRY)/volcano-vgpu-device-plugin:$(TAG_VERSION)" + $(DOCKER) tag "$(REGISTRY)/volcano-vgpu-device-plugin:$(VERSION)-ubuntu20.04" "$(REGISTRY)/volcano-vgpu-device-plugin:latest" + $(DOCKER) push "$(REGISTRY)/volcano-vgpu-device-plugin:latest" ubuntu20.04: - $(DOCKER) build --pull \ - --tag $(REGISTRY)/volcano-device-plugin:$(VERSION)-ubuntu20.04 \ - --file docker/amd64/Dockerfile.ubuntu20.04 . - -vgpu: $(DOCKER) build --pull \ --tag $(REGISTRY)/volcano-vgpu-device-plugin:$(VERSION)-ubuntu20.04 \ - --file docker/amd64/Dockerfile.vgpu-ubuntu20.04 . - -centos7: - $(DOCKER) build --pull \ - --tag $(REGISTRY)/volcano-device-plugin:$(VERSION)-centos7 \ - --file docker/amd64/Dockerfile.centos7 . + --file docker/amd64/Dockerfile.ubuntu20.04 . include Makefile.def @@ -74,4 +54,4 @@ init: gen_bin: init go get github.com/mitchellh/gox - CGO_ENABLED=1 gox -osarch=${REL_OSARCH} -ldflags ${LD_FLAGS} -output ${BIN_DIR}/${REL_OSARCH}/volcano-device-plugin cmd/vgpu + CGO_ENABLED=1 gox -osarch=${REL_OSARCH} -ldflags ${LD_FLAGS} -output ${BIN_DIR}/${REL_OSARCH}/volcano-vgpu-device-plugin ./cmd/vgpu diff --git a/docker/amd64/Dockerfile.centos7 b/docker/amd64/Dockerfile.centos7 deleted file mode 100644 index 7425d52..0000000 --- a/docker/amd64/Dockerfile.centos7 +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FROM centos:7 as build - -RUN yum install -y \ - gcc-c++ \ - ca-certificates \ - wget && \ - rm -rf /var/cache/yum/* - -ENV GOLANG_VERSION 1.17.6 -RUN wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz \ - | tar -C /usr/local -xz -ENV GOPATH /go -ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH - -WORKDIR /go/src/volcano.sh/devices -COPY . . - -RUN export CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' && \ - go build -ldflags="-s -w" -o volcano-device-plugin - - -FROM centos:7 - -ENV NVIDIA_VISIBLE_DEVICES=all -ENV NVIDIA_DRIVER_CAPABILITIES=utility - -COPY --from=build /go/src/volcano.sh/devices/volcano-device-plugin /usr/bin/volcano-device-plugin - -ENTRYPOINT ["volcano-device-plugin"] \ No newline at end of file diff --git a/docker/amd64/Dockerfile.ubuntu20.04 b/docker/amd64/Dockerfile.ubuntu20.04 index c05629a..19bed3b 100644 --- a/docker/amd64/Dockerfile.ubuntu20.04 +++ b/docker/amd64/Dockerfile.ubuntu20.04 @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM ubuntu:20.04 as build +ARG NVIDIA_IMAGE=nvidia/cuda:12.2.0-devel-ubuntu20.04 +ARG GOLANG_VERSION=1.19.3 +FROM ubuntu:20.04 as build RUN apt-get update && apt-get install -y --no-install-recommends \ g++ \ ca-certificates \ @@ -21,23 +23,37 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ rm -rf /var/lib/apt/lists/* ENV GOLANG_VERSION 1.19.3 -RUN wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz \ +RUN wget -nv -O - https://storage.googleapis.com/golang/go$GOLANG_VERSION.linux-amd64.tar.gz \ | tar -C /usr/local -xz ENV GOPATH /go ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH - WORKDIR /go/src/volcano.sh/devices COPY . . - +RUN go env -w GO111MODULE=on +RUN go env -w GOPROXY=https://goproxy.cn,direct RUN export CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' && \ - go build -ldflags="-s -w" -o volcano-device-plugin - + go build -ldflags="-s -w" -o volcano-vgpu-device-plugin ./cmd/vgpu + +FROM $NVIDIA_IMAGE AS NVBUILD +COPY ./libvgpu /libvgpu +WORKDIR /libvgpu +RUN apt-get -y update; apt-get -y install wget +RUN wget https://cmake.org/files/v3.19/cmake-3.19.8-Linux-x86_64.tar.gz +RUN tar -xf cmake-3.19.8-Linux-x86_64.tar.gz +RUN cp /libvgpu/cmake-3.19.8-Linux-x86_64/bin/cmake /libvgpu/cmake-3.19.8-Linux-x86_64/bin/cmake3 +ENV PATH="/libvgpu/cmake-3.19.8-Linux-x86_64/bin:${PATH}" +RUN apt-get -y install openssl libssl-dev +RUN rm -rf /libvgpu/build +RUN bash ./build.sh FROM debian:stretch-slim ENV NVIDIA_VISIBLE_DEVICES=all ENV NVIDIA_DRIVER_CAPABILITIES=utility -COPY --from=build /go/src/volcano.sh/devices/volcano-device-plugin /usr/bin/volcano-device-plugin +COPY --from=build /go/src/volcano.sh/devices/volcano-vgpu-device-plugin /usr/bin/volcano-vgpu-device-plugin +RUN mkdir -p /k8s-vgpu/lib/nvidia +COPY --from=build /go/src/volcano.sh/devices/lib/nvidia/ld.so.preload /k8s-vgpu/lib/nvidia/ +COPY --from=NVBUILD /libvgpu/build/libvgpu.so /k8s-vgpu/lib/nvidia/ -ENTRYPOINT ["volcano-device-plugin"] +ENTRYPOINT ["volcano-vgpu-device-plugin"] diff --git a/docker/amd64/Dockerfile.vgpu-ubuntu20.04 b/docker/amd64/Dockerfile.vgpu-ubuntu20.04 deleted file mode 100644 index 19bed3b..0000000 --- a/docker/amd64/Dockerfile.vgpu-ubuntu20.04 +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -ARG NVIDIA_IMAGE=nvidia/cuda:12.2.0-devel-ubuntu20.04 -ARG GOLANG_VERSION=1.19.3 - -FROM ubuntu:20.04 as build -RUN apt-get update && apt-get install -y --no-install-recommends \ - g++ \ - ca-certificates \ - wget && \ - rm -rf /var/lib/apt/lists/* - -ENV GOLANG_VERSION 1.19.3 -RUN wget -nv -O - https://storage.googleapis.com/golang/go$GOLANG_VERSION.linux-amd64.tar.gz \ - | tar -C /usr/local -xz -ENV GOPATH /go -ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH -WORKDIR /go/src/volcano.sh/devices -COPY . . -RUN go env -w GO111MODULE=on -RUN go env -w GOPROXY=https://goproxy.cn,direct -RUN export CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' && \ - go build -ldflags="-s -w" -o volcano-vgpu-device-plugin ./cmd/vgpu - -FROM $NVIDIA_IMAGE AS NVBUILD -COPY ./libvgpu /libvgpu -WORKDIR /libvgpu -RUN apt-get -y update; apt-get -y install wget -RUN wget https://cmake.org/files/v3.19/cmake-3.19.8-Linux-x86_64.tar.gz -RUN tar -xf cmake-3.19.8-Linux-x86_64.tar.gz -RUN cp /libvgpu/cmake-3.19.8-Linux-x86_64/bin/cmake /libvgpu/cmake-3.19.8-Linux-x86_64/bin/cmake3 -ENV PATH="/libvgpu/cmake-3.19.8-Linux-x86_64/bin:${PATH}" -RUN apt-get -y install openssl libssl-dev -RUN rm -rf /libvgpu/build -RUN bash ./build.sh - -FROM debian:stretch-slim - -ENV NVIDIA_VISIBLE_DEVICES=all -ENV NVIDIA_DRIVER_CAPABILITIES=utility - -COPY --from=build /go/src/volcano.sh/devices/volcano-vgpu-device-plugin /usr/bin/volcano-vgpu-device-plugin -RUN mkdir -p /k8s-vgpu/lib/nvidia -COPY --from=build /go/src/volcano.sh/devices/lib/nvidia/ld.so.preload /k8s-vgpu/lib/nvidia/ -COPY --from=NVBUILD /libvgpu/build/libvgpu.so /k8s-vgpu/lib/nvidia/ - -ENTRYPOINT ["volcano-vgpu-device-plugin"]