Skip to content

Commit 698eb74

Browse files
authored
General improvements (#12)
2 parents 7cc8f13 + fd665c3 commit 698eb74

File tree

12 files changed

+70
-40
lines changed

12 files changed

+70
-40
lines changed

cmd/cli/host_run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ qubesome host-run -profile <profile> firefox - Run firefox on the host and d
3939
return err
4040
}
4141

42-
c := exec.Command(commandName)
42+
c := exec.Command(commandName, cmd.Args().Slice()...) //nolint
4343
c.Env = append(c.Env, fmt.Sprintf("DISPLAY=:%d", prof.Display))
4444
out, err := c.CombinedOutput()
45-
fmt.Println(out)
45+
fmt.Println(string(out))
4646

4747
return err
4848
},

cmd/cli/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func profileConfigOrDefault(profile string) *types.Config {
8787
// Try to load the profile specific config.
8888
path := files.ProfileConfig(profile)
8989
target, err := os.Readlink(path)
90+
slog.Debug("try to load profile config", "profile", profile, "path", path, target, "target")
9091

9192
if err == nil {
9293
c := config(target)

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/start.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ qubesome start -git https://github.com/qubesome/sample-dotfiles i3
4747
},
4848
},
4949
Action: func(ctx context.Context, cmd *cli.Command) error {
50-
cfg := profileConfigOrDefault(targetProfile)
51-
5250
return profiles.Run(
53-
profiles.WithConfig(cfg),
5451
profiles.WithProfile(targetProfile),
5552
profiles.WithGitURL(gitURL),
5653
profiles.WithPath(path),

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/env/env.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package env
22

33
import (
44
"fmt"
5+
"log/slog"
56
"os"
67
)
78

@@ -16,6 +17,7 @@ var mapping = map[string]string{
1617
}
1718

1819
func Update(k, v string) error {
20+
slog.Debug("setting env", k, v)
1921
if _, ok := mapping[k]; ok {
2022
mapping[k] = v
2123
return nil

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/options.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package profiles
22

33
import (
44
"github.com/qubesome/cli/internal/command"
5-
"github.com/qubesome/cli/internal/types"
65
)
76

87
type Options struct {
@@ -11,7 +10,6 @@ type Options struct {
1110
Local string
1211
Profile string
1312
Runner string
14-
Config *types.Config
1513
}
1614

1715
func WithGitURL(gitURL string) command.Option[Options] {
@@ -37,11 +35,6 @@ func WithProfile(profile string) command.Option[Options] {
3735
o.Profile = profile
3836
}
3937
}
40-
func WithConfig(config *types.Config) command.Option[Options] {
41-
return func(o *Options) {
42-
o.Config = config
43-
}
44-
}
4538

4639
func WithRunner(runner string) command.Option[Options] {
4740
return func(o *Options) {

internal/profiles/profiles.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,25 @@ func Run(opts ...command.Option[Options]) error {
4545
return StartFromGit(o.Runner, o.Profile, o.GitURL, o.Path, o.Local)
4646
}
4747

48-
if o.Config == nil {
48+
path := filepath.Join(o.Local, o.Path, "qubesome.config")
49+
if _, err := os.Stat(path); err != nil {
50+
return err
51+
}
52+
cfg, err := types.LoadConfig(path)
53+
if err != nil {
54+
return err
55+
}
56+
cfg.RootDir = filepath.Dir(path)
57+
58+
if cfg == nil {
4959
return fmt.Errorf("cannot start profile: nil config")
5060
}
51-
profile, ok := o.Config.Profile(o.Profile)
61+
profile, ok := cfg.Profile(o.Profile)
5262
if !ok {
5363
return fmt.Errorf("cannot start profile: profile %q not found", o.Profile)
5464
}
5565

56-
return Start(o.Runner, profile, o.Config)
66+
return Start(o.Runner, profile, cfg)
5767
}
5868

5969
func validGitDir(path string) bool {
@@ -157,6 +167,10 @@ func StartFromGit(runner, name, gitURL, path, local string) error {
157167
return fmt.Errorf("cannot file profile %q in config %q", name, cfgPath)
158168
}
159169

170+
if p.Runner != "" {
171+
runner = p.Runner
172+
}
173+
160174
// When sourcing from git, ensure profile path is relative to the git repository.
161175
pp, err := securejoin.SecureJoin(filepath.Dir(cfgPath), p.Path)
162176
if err != nil {
@@ -462,6 +476,9 @@ func createNewDisplay(bin string, profile *types.Profile, display string) error
462476
dockerArgs = append(dockerArgs, "-v="+xdgRuntimeDir+":/run/user/1000")
463477
}
464478
if profile.HostAccess.Gpus != "" {
479+
if strings.HasSuffix(bin, "podman") {
480+
dockerArgs = append(dockerArgs, "--runtime=nvidia.com/gpu=all")
481+
}
465482
dockerArgs = append(dockerArgs, "--gpus", profile.HostAccess.Gpus)
466483
}
467484

internal/qubesome/run.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,7 @@ func runner(in WorkloadInfo, runnerOverride string) error {
9191
return fmt.Errorf("profile %q does not exist", in.Profile)
9292
}
9393

94-
path := files.ProfileConfig(in.Profile)
95-
target, err := os.Readlink(path)
96-
if err != nil {
97-
slog.Debug("not able find profile path", "path", path, "error", err)
98-
return nil
99-
}
100-
101-
gitdir := filepath.Dir(filepath.Dir(target))
102-
err = env.Update("GITDIR", gitdir)
94+
err := env.Update("GITDIR", in.Config.RootDir)
10395
if err != nil {
10496
return err
10597
}

0 commit comments

Comments
 (0)