Skip to content

Commit d05c898

Browse files
committed
Refactor Docker command execution to support custom engine configuration
1 parent 9c7b462 commit d05c898

File tree

5 files changed

+98
-43
lines changed

5 files changed

+98
-43
lines changed

internal/commands/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var shellCmd = &cobra.Command{
5454
}
5555
}
5656

57-
checkCmd := exec.Command("docker", "exec", project.BoxName, "test", "-f", "/etc/devbox-initialized")
57+
checkCmd := exec.Command(engineCmd(), "exec", project.BoxName, "test", "-f", "/etc/devbox-initialized")
5858
if checkCmd.Run() != nil {
5959
fmt.Printf("Setting up devbox commands in box...\n")
6060
if err := dockerClient.SetupDevboxInBox(project.BoxName, projectName); err != nil {

internal/commands/up.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ import (
66
"os"
77
"os/exec"
88
"path/filepath"
9+
"strings"
910

1011
"github.com/spf13/cobra"
1112

1213
"devbox/internal/config"
1314
)
1415

16+
func engineCmd() string {
17+
if v := strings.TrimSpace(os.Getenv("DEVBOX_ENGINE")); v != "" {
18+
return v
19+
}
20+
return "docker"
21+
}
22+
1523
var (
1624
upDotfilesPath string
1725
)
@@ -76,7 +84,7 @@ var upCmd = &cobra.Command{
7684
}
7785
}
7886

79-
checkCmd := exec.Command("docker", "exec", boxName, "test", "-f", "/etc/devbox-initialized")
87+
checkCmd := exec.Command(engineCmd(), "exec", boxName, "test", "-f", "/etc/devbox-initialized")
8088
if checkCmd.Run() != nil {
8189
if err := dockerClient.SetupDevboxInBox(boxName, projectName); err != nil {
8290
return fmt.Errorf("failed to setup devbox in existing box: %w", err)

internal/config/config.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"strings"
99
"time"
1010

11+
"errors"
12+
1113
"github.com/xeipuuv/gojsonschema"
1214
)
1315

@@ -50,6 +52,7 @@ type ProjectConfig struct {
5052
Restart string `json:"restart,omitempty"`
5153
HealthCheck *HealthCheck `json:"health_check,omitempty"`
5254
Resources *Resources `json:"resources,omitempty"`
55+
Gpus string `json:"gpus,omitempty"`
5356
}
5457

5558
type HealthCheck struct {
@@ -145,9 +148,21 @@ func (cm *ConfigManager) Save(config *Config) error {
145148
}
146149

147150
func (cm *ConfigManager) LoadProjectConfig(projectPath string) (*ProjectConfig, error) {
148-
configPath := filepath.Join(projectPath, "devbox.json")
149-
150-
if _, err := os.Stat(configPath); os.IsNotExist(err) {
151+
// Support multiple filenames for project config to avoid clashes with other tools
152+
candidates := []string{
153+
filepath.Join(projectPath, "devbox.json"), // default
154+
filepath.Join(projectPath, "devbox.project.json"), // alternative
155+
filepath.Join(projectPath, ".devbox.json"), // dotfile style
156+
}
157+
158+
var configPath string
159+
for _, p := range candidates {
160+
if _, err := os.Stat(p); err == nil {
161+
configPath = p
162+
break
163+
}
164+
}
165+
if configPath == "" {
151166
return nil, nil
152167
}
153168

@@ -165,7 +180,19 @@ func (cm *ConfigManager) LoadProjectConfig(projectPath string) (*ProjectConfig,
165180
}
166181

167182
func (cm *ConfigManager) SaveProjectConfig(projectPath string, config *ProjectConfig) error {
168-
configPath := filepath.Join(projectPath, "devbox.json")
183+
// If an existing config file with a supported name exists, write back to it; otherwise use default
184+
candidates := []string{
185+
filepath.Join(projectPath, "devbox.json"),
186+
filepath.Join(projectPath, "devbox.project.json"),
187+
filepath.Join(projectPath, ".devbox.json"),
188+
}
189+
configPath := candidates[0]
190+
for _, p := range candidates {
191+
if _, err := os.Stat(p); err == nil {
192+
configPath = p
193+
break
194+
}
195+
}
169196

170197
data, err := json.MarshalIndent(config, "", " ")
171198
if err != nil {
@@ -199,7 +226,7 @@ func (cm *ConfigManager) ValidateProjectConfig(cfg *ProjectConfig) error {
199226
b.WriteString(e.String())
200227
b.WriteString("\n")
201228
}
202-
return fmt.Errorf(strings.TrimSpace(b.String()))
229+
return errors.New(strings.TrimSpace(b.String()))
203230
}
204231

205232
for _, port := range cfg.Ports {
@@ -523,7 +550,8 @@ const ProjectConfigJSONSchema = `{
523550
"memory": {"type": "string"}
524551
},
525552
"additionalProperties": false
526-
}
553+
},
554+
"gpus": {"type": "string"}
527555
},
528556
"additionalProperties": false
529557
}`

0 commit comments

Comments
 (0)