Skip to content

Commit 8565b96

Browse files
author
Piotr Stankiewicz
committed
sandbox: Make updated resource path configurable
Signed-off-by: Piotr Stankiewicz <[email protected]>
1 parent 620fba8 commit 8565b96

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

pkg/inference/backends/llamacpp/llamacpp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func (l *llamaCpp) Run(ctx context.Context, socket, model string, mode inference
171171
command.Stdout = serverLogStream
172172
command.Stderr = out
173173
},
174+
l.updatedServerStoragePath,
174175
filepath.Join(binPath, "com.docker.llama-server"),
175176
args...,
176177
)

pkg/sandbox/sandbox_darwin.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"os/user"
9+
"path/filepath"
910
"strings"
1011
)
1112

@@ -78,8 +79,8 @@ const ConfigurationLlamaCpp = `(version 1)
7879
(subpath "/usr")
7980
(subpath "/System")
8081
(regex #"Docker\.app/Contents/Resources/model-runner")
81-
(subpath "[HOMEDIR]/.docker/bin/inference")
82-
(subpath "[HOMEDIR]/.docker/bin/lib"))
82+
(subpath "[UPDATEDBINPATH]")
83+
(subpath "[UPDATEDLIBPATH]"))
8384
(allow file-write*
8485
(literal "/dev/null")
8586
(subpath "/private/var")
@@ -116,7 +117,7 @@ func (s *sandbox) Close() error {
116117
// configuration, for which a pre-defined value should be used. The modifier
117118
// function allows for an optional callback (which may be nil) to configure the
118119
// command before it is started.
119-
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), name string, arg ...string) (Sandbox, error) {
120+
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
120121
// Look up the user's home directory.
121122
currentUser, err := user.Current()
122123
if err != nil {
@@ -133,6 +134,8 @@ func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd),
133134
// text/template if this gets any more complex.
134135
profile := strings.ReplaceAll(configuration, "[HOMEDIR]", currentUser.HomeDir)
135136
profile = strings.ReplaceAll(profile, "[WORKDIR]", currentDirectory)
137+
profile = strings.ReplaceAll(profile, "[UPDATEDBINPATH]", updatedBinPath)
138+
profile = strings.ReplaceAll(profile, "[UPDATEDLIBPATH]", filepath.Join(filepath.Dir(updatedBinPath), "lib"))
136139

137140
// Create a subcontext we can use to regulate the process lifetime.
138141
ctx, cancel := context.WithCancel(ctx)

pkg/sandbox/sandbox_other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (s *sandbox) Close() error {
3636
// configuration, for which a pre-defined value should be used. The modifier
3737
// function allows for an optional callback (which may be nil) to configure the
3838
// command before it is started.
39-
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), name string, arg ...string) (Sandbox, error) {
39+
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
4040
// Create a subcontext we can use to regulate the process lifetime.
4141
ctx, cancel := context.WithCancel(ctx)
4242

pkg/sandbox/sandbox_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ func TestSandbox(t *testing.T) {
1010
var sandbox Sandbox
1111
var err error
1212
if runtime.GOOS == "windows" {
13-
sandbox, err = Create(t.Context(), ConfigurationLlamaCpp, nil, "go", "version")
13+
sandbox, err = Create(t.Context(), ConfigurationLlamaCpp, nil, "/some/path/bin", "go", "version")
1414
} else {
15-
sandbox, err = Create(t.Context(), ConfigurationLlamaCpp, nil, "date")
15+
sandbox, err = Create(t.Context(), ConfigurationLlamaCpp, nil, "/some/path/bin", "date")
1616
}
1717
if err != nil {
1818
t.Fatal("unable to create sandboxed process:", err)

pkg/sandbox/sandbox_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (s *sandbox) Close() error {
6565
// configuration, for which a pre-defined value should be used. The modifier
6666
// function allows for an optional callback (which may be nil) to configure the
6767
// command before it is started.
68-
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), name string, arg ...string) (Sandbox, error) {
68+
func Create(ctx context.Context, configuration string, modifier func(*exec.Cmd), updatedBinPath, name string, arg ...string) (Sandbox, error) {
6969
// Parse the configuration and configure limits.
7070
limits := []winjob.Limit{winjob.WithKillOnJobClose()}
7171
tokens := limitTokenMatcher.FindAllString(configuration, -1)

0 commit comments

Comments
 (0)