diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..d11aa88c --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,67 @@ +FROM nvcr.io/nvidia/cuda:12.3.1-base-ubuntu22.04 +ARG GOLANG_VERSION=1.21.5 +ARG USERNAME=developer +ARG USER_UID=1000 +ARG USER_GID=1000 +ARG DCGM_VERSION=3.3.3 +# Create a user 'developer' with UID=1000, add to 'developer' group, and add to 'sudo' group +RUN groupadd -g $USER_GID $USERNAME && \ + useradd -m -u $USER_GID -g $USERNAME -s /bin/bash $USERNAME && \ + usermod -aG sudo $USERNAME +# Allow 'developer' to use sudo without a password +RUN echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +RUN --mount=type=cache,target=/var/cache/apt \ + set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + git \ + ca-certificates \ + g++ \ + gcc \ + libc6-dev \ + make \ + pkg-config \ + wget \ + datacenter-gpu-manager=1:${DCGM_VERSION} \ + libcap2-bin \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* + +RUN set -eux; \ + arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \ + url=; \ + echo "$arch"; \ + case "$arch" in \ + 'amd64') \ + url="https://dl.google.com/go/go${GOLANG_VERSION}.linux-amd64.tar.gz"; \ + ;; \ + 'arm64') \ + url="https://dl.google.com/go/go${GOLANG_VERSION}.linux-arm64.tar.gz"; \ + ;; \ + *) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \ + esac; \ + build=; \ + if [ -z "$url" ]; then \ +# https://github.com/golang/go/issues/38536#issuecomment-616897960 + build=1; \ + url="https://dl.google.com/go/go${GOLANG_VERSION}.src.tar.gz"; \ + echo >&2; \ + echo >&2 "warning: current architecture ($arch) does not have a compatible Go binary release; will be building from source"; \ + echo >&2; \ + fi; \ + wget -O go.tgz "$url" --progress=dot:giga; \ + tar -C /usr/local -xzf go.tgz; \ + rm go.tgz +ENV GOTOOLCHAIN=local +ENV GOPATH /go +ENV PATH $GOPATH/bin:$PATH +RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 1777 "$GOPATH" +ENV PATH $PATH:/usr/local/go/bin + +RUN rm -rfd /usr/local/dcgm/bindings /usr/local/dcgm/sdk_samples /usr/share/nvidia-validation-suite +# Required for DCP metrics +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,compat32 +# disable all constraints on the configurations required by NVIDIA container toolkit +ENV NVIDIA_DISABLE_REQUIRE="true" +ENV NVIDIA_VISIBLE_DEVICES=all \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..01ce35c1 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +// Read here https://containers.dev/implementors/json_reference/ +{ + "name": "dcgm-exporter-container", + "build": { + "dockerfile": "Dockerfile" + }, + "privileged": true, + "runArgs": [ + "-v", "/run/docker.sock:/run/docker.sock:rw", + "--mount", "type=bind,src=${env:HOME}/.ssh,dst=/home/developer/.ssh", + "-p", "2222:22", + "--name", "vscode_dev_container", + "-e", "DCGM_BUILD_INSIDE_DOCKER=1", + "-e", "NVIDIA_DRIVER_CAPABILITIES=compute,utility", + "-e", "NVIDIA_VISIBLE_DEVICES=ALL", + "--cap-add=SYS_ADMIN", + "--security-opt", + "seccomp=unconfined", + "--gpus=all" + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index 055d8d39..524b5c2a 100644 --- a/Makefile +++ b/Makefile @@ -92,3 +92,7 @@ validate-modules: @echo "- Checking for any unused/missing packages in go.mod..." go mod tidy @git diff --exit-code -- go.sum go.mod + +.PHONY: tools +tools: ## Install required tools and utilities + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 \ No newline at end of file