Skip to content

Commit b5f5178

Browse files
committed
Add docker image with Cuda support.
1 parent e010b57 commit b5f5178

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ensure all C and PHP files use LF.
2+
*.py eol=lf
3+
*.cs eol=lf
4+
*.sh eol=lf
5+
*Dockerfile eol=lf

entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/env bash
2+
3+
echo "my entry point"
4+
python -m myproject.hello

nix/build_container.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
project_dependencies ? import ./dependencies.nix {}
3+
}:
4+
let
5+
pkgs = project_dependencies.pkgs;
6+
lib = project_dependencies.lib;
7+
cudatoolkit = project_dependencies.cudatoolkit;
8+
project = import ./project.nix { project_dependencies = project_dependencies; };
9+
entrypointScriptPath = ../entrypoint.sh; # Adjust the path as necessary
10+
entrypointScript = pkgs.runCommand "entrypoint-script" {} ''
11+
mkdir -p $out/bin
12+
cp ${entrypointScriptPath} $out/bin/entrypoint
13+
chmod +x $out/bin/entrypoint
14+
'';
15+
in import ./docker/buildCudaLayeredImage.nix {
16+
inherit cudatoolkit;
17+
buildLayeredImage = pkgs.dockerTools.streamLayeredImage;
18+
lib = pkgs.lib;
19+
maxLayers = 2;
20+
name = "project_nix";
21+
tag = "latest";
22+
23+
contents = [
24+
pkgs.coreutils
25+
pkgs.findutils
26+
pkgs.gnugrep
27+
pkgs.gnused
28+
pkgs.gawk
29+
pkgs.bashInteractive
30+
pkgs.which
31+
pkgs.file
32+
pkgs.binutils
33+
pkgs.diffutils
34+
pkgs.less
35+
pkgs.gzip
36+
pkgs.btar
37+
pkgs.nano
38+
(pkgs.python311.withPackages (ps: [
39+
project
40+
]))
41+
entrypointScript
42+
];
43+
config = {
44+
Entrypoint = ["${entrypointScript}/bin/entrypoint"];
45+
};
46+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# https://sebastian-staffa.eu/posts/nvidia-docker-with-nix/
2+
# https://github.com/Staff-d/nix-cuda-docker-example
3+
{ cudatoolkit
4+
, buildLayeredImage
5+
, lib
6+
, name
7+
, tag ? null
8+
, fromImage ? null
9+
, contents ? null
10+
, config ? {Env = [];}
11+
, extraCommands ? ""
12+
, maxLayers ? 2
13+
, fakeRootCommands ? ""
14+
, enableFakechroot ? false
15+
, created ? "2024-03-08T00:00:01Z"
16+
, includeStorePaths ? true
17+
}:
18+
19+
let
20+
21+
# cut the patch version from the version string
22+
cutVersion = with lib; versionString:
23+
builtins.concatStringsSep "."
24+
(take 3 (builtins.splitVersion versionString )
25+
);
26+
27+
cudaVersionString = "CUDA_VERSION=" + (cutVersion cudatoolkit.version);
28+
29+
cudaEnv = [
30+
"${cudaVersionString}"
31+
"NVIDIA_VISIBLE_DEVICES=all"
32+
"NVIDIA_DRIVER_CAPABILITIES=all"
33+
34+
"LD_LIBRARY_PATH=/usr/lib64/"
35+
];
36+
37+
cudaConfig = config // {Env = cudaEnv;};
38+
39+
in buildLayeredImage {
40+
inherit name tag fromImage
41+
contents extraCommands
42+
maxLayers
43+
fakeRootCommands enableFakechroot
44+
created includeStorePaths;
45+
46+
config = cudaConfig;
47+
}

nix/shell.nix

Whitespace-only changes.

src/myproject/hello.py

Whitespace-only changes.

src/setup.py

Whitespace-only changes.

0 commit comments

Comments
 (0)