Skip to content

Commit 8e6e2b8

Browse files
authored
fix --process-compose-file issue (#1345)
## Summary Fix the issue where passing a custom process compose file with `--process-compose-file` failed to load custom services ## How was it tested? 1. Add a process-compose.yaml with a service in a custom path 2. Load the file with `devbox services up --process-compose-file path/to/file 3. Verify that the service starts
1 parent f53929d commit 8e6e2b8

File tree

5 files changed

+42
-38
lines changed

5 files changed

+42
-38
lines changed

internal/boxcli/services.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ func startProcessManager(
169169
flags serviceUpFlags,
170170
) error {
171171
box, err := devbox.Open(&devopt.Opts{
172-
Dir: servicesFlags.config.path,
173-
Writer: cmd.ErrOrStderr(),
172+
Dir: servicesFlags.config.path,
173+
CustomProcessComposeFile: flags.processComposeFile,
174+
Writer: cmd.ErrOrStderr(),
174175
})
175176
if err != nil {
176177
return errors.WithStack(err)

internal/impl/devbox.go

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@ const (
5252
)
5353

5454
type Devbox struct {
55-
cfg *devconfig.Config
56-
lockfile *lock.File
57-
nix nix.Nixer
58-
projectDir string
59-
pluginManager *plugin.Manager
60-
pure bool
61-
allowInsecureAdds bool
55+
cfg *devconfig.Config
56+
lockfile *lock.File
57+
nix nix.Nixer
58+
projectDir string
59+
pluginManager *plugin.Manager
60+
pure bool
61+
allowInsecureAdds bool
62+
customProcessComposeFile string
6263

6364
// Possible TODO: hardcode this to stderr. Allowing the caller to specify the
6465
// writer is error prone. Since it is almost always stderr, we should default
@@ -82,13 +83,14 @@ func Open(opts *devopt.Opts) (*Devbox, error) {
8283
}
8384

8485
box := &Devbox{
85-
cfg: cfg,
86-
nix: &nix.Nix{},
87-
projectDir: projectDir,
88-
pluginManager: plugin.NewManager(),
89-
writer: opts.Writer,
90-
pure: opts.Pure,
91-
allowInsecureAdds: opts.AllowInsecureAdds,
86+
cfg: cfg,
87+
nix: &nix.Nix{},
88+
projectDir: projectDir,
89+
pluginManager: plugin.NewManager(),
90+
writer: opts.Writer,
91+
pure: opts.Pure,
92+
customProcessComposeFile: opts.CustomProcessComposeFile,
93+
allowInsecureAdds: opts.AllowInsecureAdds,
9294
}
9395

9496
lock, err := lock.GetFile(box)
@@ -487,7 +489,7 @@ func (d *Devbox) Services() (services.Services, error) {
487489
return nil, err
488490
}
489491

490-
userSvcs := services.FromUserProcessCompose(d.projectDir)
492+
userSvcs := services.FromUserProcessCompose(d.projectDir, d.customProcessComposeFile)
491493

492494
svcSet := lo.Assign(pluginSvcs, userSvcs)
493495
keys := make([]string, 0, len(svcSet))
@@ -656,6 +658,19 @@ func (d *Devbox) StartProcessManager(
656658
background bool,
657659
processComposeFileOrDir string,
658660
) error {
661+
662+
if !d.IsEnvEnabled() {
663+
args := []string{"services", "up"}
664+
args = append(args, requestedServices...)
665+
if processComposeFileOrDir != "" {
666+
args = append(args, "--process-compose-file", processComposeFileOrDir)
667+
}
668+
if background {
669+
args = append(args, "--background")
670+
}
671+
return d.RunScript(ctx, "devbox", args)
672+
}
673+
659674
svcs, err := d.Services()
660675
if err != nil {
661676
return err
@@ -685,17 +700,6 @@ func (d *Devbox) StartProcessManager(
685700
return err
686701
}
687702
}
688-
if !d.IsEnvEnabled() {
689-
args := []string{"services", "up"}
690-
args = append(args, requestedServices...)
691-
if processComposeFileOrDir != "" {
692-
args = append(args, "--process-compose-file", processComposeFileOrDir)
693-
}
694-
if background {
695-
args = append(args, "--background")
696-
}
697-
return d.RunScript(ctx, "devbox", args)
698-
}
699703

700704
// Start the process manager
701705

@@ -705,7 +709,7 @@ func (d *Devbox) StartProcessManager(
705709
requestedServices,
706710
svcs,
707711
d.projectDir,
708-
processComposePath, processComposeFileOrDir,
712+
processComposePath,
709713
background,
710714
)
711715
}

internal/impl/devopt/devboxopts.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
)
66

77
type Opts struct {
8-
AllowInsecureAdds bool
9-
Dir string
10-
Pure bool
11-
IgnoreWarnings bool
12-
Writer io.Writer
8+
AllowInsecureAdds bool
9+
Dir string
10+
Pure bool
11+
IgnoreWarnings bool
12+
CustomProcessComposeFile string
13+
Writer io.Writer
1314
}

internal/services/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"go.jetpack.io/devbox/internal/cuecfg"
1515
)
1616

17-
func FromUserProcessCompose(projectDir string) Services {
18-
processComposeYaml := lookupProcessCompose(projectDir, "")
17+
func FromUserProcessCompose(projectDir string, userProcessCompose string) Services {
18+
processComposeYaml := lookupProcessCompose(projectDir, userProcessCompose)
1919
if processComposeYaml == "" {
2020
return nil
2121
}

internal/services/manager.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,9 @@ func StartProcessManager(
122122
availableServices Services,
123123
projectDir string,
124124
processComposeBinPath string,
125-
processComposeFilePath string,
126125
processComposeBackground bool,
127126
) error {
128127
// Check if process-compose is already running
129-
130128
if ProcessManagerIsRunning(projectDir) {
131129
return fmt.Errorf("process-compose is already running. To stop it, run `devbox services stop`")
132130
}

0 commit comments

Comments
 (0)