Skip to content

Commit 64ee717

Browse files
committed
inception: Ignore config and profile selection
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
1 parent 7cc8f13 commit 64ee717

File tree

6 files changed

+49
-14
lines changed

6 files changed

+49
-14
lines changed

cmd/cli/run.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package cli
33
import (
44
"context"
55

6+
"github.com/qubesome/cli/internal/inception"
67
"github.com/qubesome/cli/internal/qubesome"
8+
"github.com/qubesome/cli/internal/types"
79
"github.com/urfave/cli/v3"
810
)
911

@@ -36,16 +38,29 @@ qubesome run -profile <profile> chrome - Run the chrome workload on a specif
3638
},
3739
},
3840
Action: func(ctx context.Context, cmd *cli.Command) error {
39-
prof, err := profileOrActive(targetProfile)
40-
if err != nil {
41-
return err
42-
}
41+
var cfg *types.Config
42+
43+
// Commands that can be executed from within a profile
44+
// (a.k.a. inception mode) should not check for profile
45+
// names nor configs, as those are imposed by the inception
46+
// server.
47+
if !inception.Inside() {
48+
prof, err := profileOrActive(targetProfile)
49+
if err != nil {
50+
return err
51+
}
4352

44-
cfg := profileConfigOrDefault(prof.Name)
53+
targetProfile = prof.Name
54+
cfg = profileConfigOrDefault(targetProfile)
55+
56+
if runner == "" {
57+
runner = prof.Runner
58+
}
59+
}
4560

4661
return qubesome.Run(
4762
qubesome.WithWorkload(workload),
48-
qubesome.WithProfile(prof.Name),
63+
qubesome.WithProfile(targetProfile),
4964
qubesome.WithConfig(cfg),
5065
qubesome.WithRunner(runner),
5166
qubesome.WithExtraArgs(cmd.Args().Slice()),

cmd/cli/xdg.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package cli
33
import (
44
"context"
55

6+
"github.com/qubesome/cli/internal/inception"
67
"github.com/qubesome/cli/internal/qubesome"
8+
"github.com/qubesome/cli/internal/types"
79
"github.com/urfave/cli/v3"
810
)
911

@@ -28,12 +30,20 @@ qubesome xdg-open -profile <profile> https://github.com/qubesome - Opens the
2830
},
2931
},
3032
Action: func(ctx context.Context, cmd *cli.Command) error {
31-
prof, err := profileOrActive(targetProfile)
32-
if err != nil {
33-
return err
34-
}
33+
var cfg *types.Config
34+
35+
// Commands that can be executed from within a profile
36+
// (a.k.a. inception mode) should not check for profile
37+
// names nor configs, as those are imposed by the inception
38+
// server.
39+
if !inception.Inside() {
40+
prof, err := profileOrActive(targetProfile)
41+
if err != nil {
42+
return err
43+
}
3544

36-
cfg := profileConfigOrDefault(prof.Name)
45+
cfg = profileConfigOrDefault(prof.Name)
46+
}
3747

3848
return qubesome.XdgRun(
3949
qubesome.WithConfig(cfg),

internal/inception/inception.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package inception
22

33
import (
4+
"log/slog"
45
"os"
56

67
"github.com/qubesome/cli/internal/files"
@@ -9,5 +10,8 @@ import (
910
func Inside() bool {
1011
path := files.InProfileSocketPath()
1112
_, err := os.Stat(path)
12-
return (err == nil)
13+
inside := (err == nil)
14+
15+
slog.Debug("inception check", "inside", inside)
16+
return inside
1317
}

internal/profiles/profiles.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func StartFromGit(runner, name, gitURL, path, local string) error {
157157
return fmt.Errorf("cannot file profile %q in config %q", name, cfgPath)
158158
}
159159

160+
if p.Runner != "" {
161+
runner = p.Runner
162+
}
163+
160164
// When sourcing from git, ensure profile path is relative to the git repository.
161165
pp, err := securejoin.SecureJoin(filepath.Dir(cfgPath), p.Path)
162166
if err != nil {
@@ -462,6 +466,9 @@ func createNewDisplay(bin string, profile *types.Profile, display string) error
462466
dockerArgs = append(dockerArgs, "-v="+xdgRuntimeDir+":/run/user/1000")
463467
}
464468
if profile.HostAccess.Gpus != "" {
469+
if strings.HasSuffix(bin, "podman") {
470+
dockerArgs = append(dockerArgs, "--runtime=nvidia.com/gpu=all")
471+
}
465472
dockerArgs = append(dockerArgs, "--gpus", profile.HostAccess.Gpus)
466473
}
467474

internal/runners/podman/run.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ func Run(ew types.EffectiveWorkload) error {
8383

8484
if wl.HostAccess.Gpus != "" {
8585
args = append(args, "--gpus", wl.HostAccess.Gpus)
86-
args = append(args, "--runtime=nvidia")
8786
}
8887

8988
for _, cap := range wl.HostAccess.CapsAdd {

internal/types/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ type Profile struct {
107107
// config is being consumed. When sourcing from git, it descends
108108
// from the git repository directory.
109109
Path string `yaml:"path"`
110-
Runner string // TODO: Better name runner
110+
Runner string `yaml:"runner"`
111111

112112
// HostAccess defines all the access request which are allowed for
113113
// its workloads.

0 commit comments

Comments
 (0)