Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ linters-settings:
- name: bool-literal-in-expr
- name: cognitive-complexity
arguments:
- 36 # TODO: gradually reduce it
- 30 # TODO: gradually reduce it
- name: datarace
- name: duplicated-imports
- name: early-return
Expand Down
2 changes: 0 additions & 2 deletions internal/boxcli/featureflag/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type feature struct {

var features = map[string]*feature{}

// nolint:unparam
func disabled(name string) *feature {
if features[name] == nil {
features[name] = &feature{name: name}
Expand All @@ -23,7 +22,6 @@ func disabled(name string) *feature {
return features[name]
}

// nolint:unparam
func enabled(name string) *feature {
if features[name] == nil {
features[name] = &feature{name: name}
Expand Down
2 changes: 1 addition & 1 deletion internal/boxcli/generate/devcontainer_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type vscode struct {
Extensions []string `json:"extensions"`
}

// Creates a Dockerfile in path and writes devcontainerDockerfile.tmpl's content into it
// CreateDockerfile creates a Dockerfile in path and writes devcontainerDockerfile.tmpl's content into it
func CreateDockerfile(tmplFS embed.FS, path string) error {
// create dockerfile
file, err := os.Create(filepath.Join(path, "Dockerfile"))
Expand Down
15 changes: 0 additions & 15 deletions internal/fileutil/fileutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,6 @@ func IsFile(path string) bool {
return info.Mode().IsRegular()
}

// IsSymlink returns true if the path exists *and* it is a symlink.
//
// It does *not* traverse symbolic links, and returns true even if the symlink
// is broken.
//
// This is a convenience function that coerces errors to false. If it cannot
// read the path for any reason (including a permission error) it returns false.
func IsSymlink(path string) bool {
info, err := os.Lstat(path)
if err != nil {
return false
}
return (info.Mode().Type() & os.ModeSymlink) == os.ModeSymlink
}

func Exists(path string) bool {
err := TryExists(path)
return err == nil
Expand Down
8 changes: 4 additions & 4 deletions internal/impl/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,21 +434,21 @@ func (d *Devbox) saveCfg() error {
}

func (d *Devbox) Services() (services.Services, error) {
result := services.Services{}
pluginSvcs, err := plugin.GetServices(d.mergedPackages(), d.projectDir)
if err != nil {
return result, err
return nil, err
}

userSvcs := services.FromProcessComposeYaml(d.projectDir)

svcSet, err := lo.Assign(pluginSvcs, userSvcs), nil

svcSet := lo.Assign(pluginSvcs, userSvcs)
keys := make([]string, 0, len(svcSet))
for k := range svcSet {
keys = append(keys, k)
}
slices.Sort(keys)

result := services.Services{}
for _, k := range keys {
result[k] = svcSet[k]
}
Expand Down
9 changes: 4 additions & 5 deletions internal/impl/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/alessio/shellescape"
"github.com/pkg/errors"

"go.jetpack.io/devbox/internal/debug"
"go.jetpack.io/devbox/internal/nix"
"go.jetpack.io/devbox/internal/xdg"
Expand All @@ -40,12 +41,11 @@ const (
shPosix name = "posix"
)

var ErrNoRecognizableShellFound = errors.New(
"SHELL in undefined, and couldn't find any common shells in PATH")
var ErrNoRecognizableShellFound = errors.New("SHELL in undefined, and couldn't find any common shells in PATH")

// TODO consider splitting this struct's functionality so that there is a simpler
// `nix.Shell` that can produce a raw nix shell once again.
//

// DevboxShell configures a user's shell to run in Devbox. Its zero value is a
// fallback shell that launches a regular Nix shell.
type DevboxShell struct {
Expand Down Expand Up @@ -179,8 +179,7 @@ func WithHooksFilePath(hooksFilePath string) ShellOption {
}
}

// TODO: Consider removing this once plugins add env vars directly to binaries
// via wrapper scripts.
// TODO: Consider removing this once plugins add env vars directly to binaries via wrapper scripts.
func WithEnvVariables(envVariables map[string]string) ShellOption {
return func(s *DevboxShell) {
s.env = envVariables
Expand Down
24 changes: 13 additions & 11 deletions internal/services/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ import (

"github.com/f1bonacc1/process-compose/src/types"
"github.com/pkg/errors"

"go.jetpack.io/devbox/internal/cuecfg"
)

func FromProcessComposeYaml(projectDir string) Services {
// TODO need to handle if a filepath is passed in
if processComposeYaml := lookupProcessCompose(projectDir, ""); processComposeYaml != "" {
userSvcs, err := readProcessCompose(processComposeYaml)
if err != nil {
fmt.Fprintf(os.Stderr, "error reading process-compose.yaml: %s, skipping", err)
return nil
}
return userSvcs
processComposeYaml := lookupProcessCompose(projectDir, "")
if processComposeYaml == "" {
return nil
}
userSvcs, err := readProcessCompose(processComposeYaml)
if err != nil {
fmt.Fprintf(os.Stderr, "error reading process-compose.yaml: %s, skipping", err)
return nil
}
return Services{}
return userSvcs
}

func readProcessCompose(path string) (Services, error) {
processCompose := &types.Project{}
services := Services{}
errors := errors.WithStack(cuecfg.ParseFile(path, processCompose))
if errors != nil {
return nil, errors
err := errors.WithStack(cuecfg.ParseFile(path, processCompose))
if err != nil {
return nil, err
}

for name := range processCompose.Processes {
Expand Down
59 changes: 31 additions & 28 deletions internal/services/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/fsnotify/fsnotify"
"github.com/pkg/errors"

"go.jetpack.io/devbox/internal/cloud/envir"
)

Expand Down Expand Up @@ -44,40 +45,42 @@ func ListenToChanges(ctx context.Context, opts *ListenerOpts) error {
}()

// Start listening for events.
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
go listenToEvents(watcher, opts)

// mutagen sync changes show up as create events
if event.Has(fsnotify.Write) || event.Has(fsnotify.Create) {
status, err := readServiceStatus(event.Name)
if err != nil {
fmt.Fprintf(opts.Writer, "Error reading status file: %s\n", err)
continue
}
// We only want events for the specific host.
return errors.WithStack(watcher.Add(filepath.Join(cloudFilePath(opts.ProjectDir), opts.HostID)))
}

status, saveChanges := opts.UpdateFunc(status)
if saveChanges {
if err := writeServiceStatusFile(event.Name, status); err != nil {
fmt.Fprintf(opts.Writer, "Error updating status file: %s\n", err)
}
}
func listenToEvents(watcher *fsnotify.Watcher, opts *ListenerOpts) {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}

// mutagen sync changes show up as create events
if event.Has(fsnotify.Write) || event.Has(fsnotify.Create) {
status, err := readServiceStatus(event.Name)
if err != nil {
fmt.Fprintf(opts.Writer, "Error reading status file: %s\n", err)
continue
}
case err, ok := <-watcher.Errors:
if !ok {
return

status, saveChanges := opts.UpdateFunc(status)
if saveChanges {
if err := writeServiceStatusFile(event.Name, status); err != nil {
fmt.Fprintf(opts.Writer, "Error updating status file: %s\n", err)
}
}
fmt.Fprintf(opts.Writer, "error: %s\n", err)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
fmt.Fprintf(opts.Writer, "error: %s\n", err)
}
}()

// We only want events for the specific host.
return errors.WithStack(watcher.Add(filepath.Join(cloudFilePath(opts.ProjectDir), opts.HostID)))
}
}

func cloudFilePath(projectDir string) string {
Expand Down