Skip to content

Commit 0dceab2

Browse files
committed
revert guessing host usr lib dir
1 parent d4a0919 commit 0dceab2

File tree

4 files changed

+21
-58
lines changed

4 files changed

+21
-58
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The environment variables can be used to configure various aspects of the inner
2020
| `CODER_IMAGE_PULL_SECRET` | The docker credentials to use when pulling the inner container. The recommended way to do this is to create an [Image Pull Secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-secret-by-providing-credentials-on-the-command-line) and then reference the secret using an [environment variable](https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#define-container-environment-variables-using-secret-data). See below for example. | false |
2121
| `CODER_DOCKER_BRIDGE_CIDR` | The bridge CIDR to start the Docker daemon with. | false |
2222
| `CODER_MOUNTS` | A list of mounts to mount into the inner container. Mounts default to `rw`. Ex: `CODER_MOUNTS=/home/coder:/home/coder,/var/run/mysecret:/var/run/mysecret:ro` | false |
23-
| `CODER_USR_LIB_DIR` | The location under which GPU drivers can be found, either if mounted manually from the host or automatically by the container runtime. Only required when using GPUs. If not set, Envbox will try to automatically set this to a sensible value. | false |
23+
| `CODER_USR_LIB_DIR` | The mountpoint of the host `/usr/lib` directory. Only required when using GPUs. | false |
2424
| `CODER_ADD_TUN` | If `CODER_ADD_TUN=true` add a TUN device to the inner container. | false |
2525
| `CODER_ADD_FUSE` | If `CODER_ADD_FUSE=true` add a FUSE device to the inner container. | false |
2626
| `CODER_ADD_GPU` | If `CODER_ADD_GPU=true` add detected GPUs and related files to the inner container. Requires setting `CODER_USR_LIB_DIR` and mounting in the hosts `/usr/lib/` directory. | false |

cli/docker.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -502,27 +502,7 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Client
502502

503503
if flags.addGPU {
504504
if flags.hostUsrLibDir == "" {
505-
// If the user didn't specify CODER_USR_LIB_DIR, try to default to a
506-
// sensible value.
507-
log.Info(ctx, EnvUsrLibDir+" not specified, determining from /etc/os-release (best-effort)")
508-
osReleaseFile, err := fs.Open("/etc/os-release")
509-
if err != nil {
510-
return xerrors.Errorf("open /etc/os-release: %w", err)
511-
}
512-
defer osReleaseFile.Close()
513-
contents, err := io.ReadAll(osReleaseFile)
514-
if err != nil {
515-
return xerrors.Errorf("read /etc/os-release: %w", err)
516-
}
517-
rid := dockerutil.GetOSReleaseID(contents)
518-
found, ok := dockerutil.UsrLibDirs[rid]
519-
if !ok {
520-
// This should actually be impossible as GetOSReleaseID will return
521-
// "linux" as a fallback.
522-
return xerrors.Errorf("developer error: no UsrLibDir for os-release id %q", rid)
523-
}
524-
log.Info(ctx, "automatically set CODER_USR_LIB_DIR", slog.F("path", found))
525-
flags.hostUsrLibDir = found
505+
return xerrors.Errorf("when using GPUs, %q must be specified", EnvUsrLibDir)
526506
}
527507

528508
// Unmount GPU drivers in /proc as it causes issues when creating any

cli/docker_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,21 @@ func TestDocker(t *testing.T) {
532532
require.True(t, called, "create function was not called for inner container")
533533
})
534534

535+
t.Run("GPUNoUsrLibDir", func(t *testing.T) {
536+
t.Parallel()
537+
538+
ctx, cmd := clitest.New(t, "docker",
539+
"--image=ubuntu",
540+
"--username=root",
541+
"--agent-token=hi",
542+
"--add-gpu=true",
543+
)
544+
545+
err := cmd.ExecuteContext(ctx)
546+
require.Error(t, err)
547+
require.ErrorContains(t, err, fmt.Sprintf("when using GPUs, %q must be specified", cli.EnvUsrLibDir))
548+
})
549+
535550
t.Run("GPU", func(t *testing.T) {
536551
t.Parallel()
537552

integration/gpu_test.go

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,9 @@ func TestDocker_Nvidia(t *testing.T) {
3333

3434
// Start the envbox container.
3535
ctID := startEnvboxCmd(ctx, t, integrationtest.UbuntuImage, "root",
36+
"-v", "/usr/lib/x86_64-linux-gnu:/var/coder/usr/lib",
3637
"--env", "CODER_ADD_GPU=true",
37-
"--env", "CODER_USR_LIB_DIR=/usr/lib/x86_64-linux-gnu",
38-
"--runtime=nvidia",
39-
"--gpus=all",
40-
)
41-
42-
// Assert that we can run nvidia-smi in the inner container.
43-
_, err := execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "nvidia-smi")
44-
require.NoError(t, err, "failed to run nvidia-smi in the inner container")
45-
})
46-
47-
t.Run("Ubuntu_NoUsrLibDir", func(t *testing.T) {
48-
t.Parallel()
49-
ctx, cancel := context.WithCancel(context.Background())
50-
t.Cleanup(cancel)
51-
52-
// Start the envbox container.
53-
ctID := startEnvboxCmd(ctx, t, integrationtest.UbuntuImage, "root",
54-
"--env", "CODER_ADD_GPU=true",
38+
"--env", "CODER_USR_LIB_DIR=/var/coder/usr/lib",
5539
"--runtime=nvidia",
5640
"--gpus=all",
5741
)
@@ -66,27 +50,11 @@ func TestDocker_Nvidia(t *testing.T) {
6650
ctx, cancel := context.WithCancel(context.Background())
6751
t.Cleanup(cancel)
6852

69-
// Start the envbox container.
70-
ctID := startEnvboxCmd(ctx, t, integrationtest.UbuntuImage, "root",
71-
"--env", "CODER_ADD_GPU=true",
72-
"--env", "CODER_USR_LIB_DIR=/usr/lib/x86_64-linux-gnu",
73-
"--runtime=nvidia",
74-
"--gpus=all",
75-
)
76-
77-
// Assert that we can run nvidia-smi in the inner container.
78-
_, err := execContainerCmd(ctx, t, ctID, "docker", "exec", "workspace_cvm", "nvidia-smi")
79-
require.NoError(t, err, "failed to run nvidia-smi in the inner container")
80-
})
81-
82-
t.Run("Redhat_NoUsrLibDir", func(t *testing.T) {
83-
t.Parallel()
84-
ctx, cancel := context.WithCancel(context.Background())
85-
t.Cleanup(cancel)
86-
8753
// Start the envbox container.
8854
ctID := startEnvboxCmd(ctx, t, integrationtest.RedhatImage, "root",
55+
"-v", "/usr/lib/x86_64-linux-gnu:/var/coder/usr/lib64",
8956
"--env", "CODER_ADD_GPU=true",
57+
"--env", "CODER_USR_LIB_DIR=/var/coder/usr/lib64",
9058
"--runtime=nvidia",
9159
"--gpus=all",
9260
)

0 commit comments

Comments
 (0)