Skip to content

Commit 9d3919d

Browse files
update patterns and allow external config of devices
1 parent 1d8bca7 commit 9d3919d

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

doxy.pattern

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
^/(v\d\.\d+/)?services(/[0-9a-f]+)?$
55
# List and inspect tasks
66
^/(v\d\.\d+/)?tasks(/\w+)?$
7+
# List and inspect images
8+
^/(v\d\.\d+/)?images(/\w+)?$
79
# List and inspect networks
810
^/(v\d\.\d+/)?networks(/\w+)?$
911
# List and inspect volumes
@@ -16,5 +18,3 @@
1618
^/(v\d\.\d+/)?version$
1719
# Healthcheck
1820
^/_ping$
19-
# List and inspect images
20-
^/(v\d\.\d+/)?images(/\w+)?$

main.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ var (
5959
Usage: "File holding line-separated regex-patterns to be allowed (comments allowed, use #)",
6060
EnvVar: "DOXY_PATTERN_FILE",
6161
}
62+
deviceFileFlag = cli.StringFlag{
63+
Name: "device-file",
64+
Value: proxy.DEVICE_FILE,
65+
Usage: "File holding line-separated devices to be mapped in when in (GPU|HPC) mode (comments allowed, use #)",
66+
EnvVar: "DOXY_DEVICE_FILE",
67+
}
6268
)
6369

6470
func EvalOptions(cfg *config.Config) (po []proxy.ProxyOption) {
@@ -90,10 +96,25 @@ func EvalPatternOpts(cfg *config.Config) (proxy.ProxyOption) {
9096
os.Exit(1)
9197

9298
}
93-
patterns, err = proxy.ReadPatterns(reader)
99+
patterns, err = proxy.ReadLineFile(reader)
94100
return proxy.WithPatterns(patterns)
95101
}
96102

103+
func EvalDevicesOpts(cfg *config.Config) (proxy.ProxyOption) {
104+
deviceFile, _ := cfg.String("device-file")
105+
reader, err := os.Open(deviceFile)
106+
defer reader.Close()
107+
devices := []string{}
108+
if err != nil {
109+
return proxy.WithPatterns(proxy.DEVICES)
110+
}
111+
devices, err = proxy.ReadLineFile(reader)
112+
if err != nil {
113+
log.Printf("Error while reading device file: %s", err.Error())
114+
}
115+
return proxy.WithDevMappings(devices)
116+
}
117+
97118
func EvalBindMountOpts(cfg *config.Config) (proxy.ProxyOption) {
98119
bindStr, _ := cfg.String("add-binds")
99120
bindMounts := strings.Split(bindStr,",")
@@ -106,6 +127,7 @@ func RunApp(ctx *cli.Context) {
106127
cfg := config.NewConfig([]config.Provider{config.NewCLI(ctx, true)})
107128
po := EvalOptions(cfg)
108129
po = append(po, EvalPatternOpts(cfg))
130+
po = append(po, EvalDevicesOpts(cfg))
109131
po = append(po, EvalBindMountOpts(cfg))
110132
p := proxy.NewProxy(po...)
111133
p.Run()
@@ -121,6 +143,7 @@ func main() {
121143
proxySocketFlag,
122144
debugFlag,
123145
gpuEnabled,
146+
deviceFileFlag,
124147
patternFileFlag,
125148
proxyPatternKey,
126149
bindAddFlag,

proxy/main.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const (
1313
DOCKER_SOCKET = "/var/run/docker.sock"
1414
PROXY_SOCKET = "/tmp/doxy.sock"
1515
PATTERN_FILE = "/etc/doxy.pattern"
16+
DEVICE_FILE = "/etc/doxy.devices"
1617
)
1718

1819
var (
@@ -29,15 +30,17 @@ var (
2930
}
3031
HPC_PAT = []string{
3132
`^/(v\d\.\d+/)?containers(/\w+)?/(json|stats|top|create|start|run|kill)$`,
32-
`^/(v\d\.\d+/)?services(/[0-9a-f]+)?$`,
33-
`^/(v\d\.\d+/)?tasks(/\w+)?$`,
34-
`^/(v\d\.\d+/)?networks(/\w+)?$`,
35-
`^/(v\d\.\d+/)?volumes(/\w+)?$`,
36-
`^/(v\d\.\d+/)?nodes(/\w+)?$`,
33+
`^/(v\d\.\d+/)?images(/\w+)?/(json|pull)$`,
3734
`^/(v\d\.\d+/)?info$`,
35+
`^/(v\d\.\d+/)?images(/\w+)?/(pull)$`,
3836
`^/(v\d\.\d+/)?version$`,
3937
"^/_ping$",
4038
}
39+
DEVICES = []string{
40+
"/dev/nvidia0:/dev/nvidia0:rwm",
41+
"/dev/nvidia-uvm:/dev/nvidia-uvm:rwm",
42+
"/dev/nvidiactl:/dev/nvidiactl:rwm",
43+
}
4144
PATTERNS = map[string][]string{
4245
"default": DEF_PAT,
4346
"hpc": HPC_PAT,

proxy/patterns.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"io"
77
)
88

9-
func ReadPatterns(reader io.Reader) (patterns []string, err error) {
9+
func ReadLineFile(reader io.Reader) (patterns []string, err error) {
1010
scanner := bufio.NewScanner(reader)
1111
for scanner.Scan() {
1212
line := scanner.Text()

proxy/proxy.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,9 @@ func (u *UpStream) ServeHTTP(w http.ResponseWriter, req *http.Request) {
121121
if u.gpu {
122122
fmt.Println("Add GPU stuff")
123123
// TODO: Be smarter about the version of the driver
124-
hostConfig.Binds = append(hostConfig.Binds, "/var/lib/nvidia-docker/volumes/nvidia_driver/384.81/:/usr/local/nvidia/")
125-
devMappings = append(devMappings, "/dev/nvidia0:/dev/nvidia0:rwm")
126-
devMappings = append(devMappings, "/dev/nvidia-uvm:/dev/nvidia-uvm:rwm")
127-
devMappings = append(devMappings, "/dev/nvidia-uvm-tools:/dev/nvidia-uvm-tools:rwm")
128-
devMappings = append(devMappings, "/dev/nvidiactl:/dev/nvidiactl:rwm")
124+
hostConfig.Binds = append(hostConfig.Binds, "/usr/lib/nvidia-384/:/usr/local/nvidia/")
129125
config.Env = append(config.Env, "PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
126+
config.Env = append(config.Env, "LD_LIBRARY_PATH=/usr/local/nvidia/")
130127
}
131128
for _, bMount := range u.bindMounts {
132129
if bMount == "" {

0 commit comments

Comments
 (0)