Skip to content

[update] Add sync flag which syncs all dependencies to same resolved version under current working dir #1501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 25, 2023
2 changes: 1 addition & 1 deletion devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Devbox interface {
StopServices(ctx context.Context, allProjects bool, services ...string) error
ListServices(ctx context.Context) error

Update(ctx context.Context, pkgs ...string) error
Update(ctx context.Context, opts devopt.UpdateOpts) error
}

// Open opens a devbox by reading the config file in dir.
Expand Down
23 changes: 19 additions & 4 deletions examples/databases/mariadb/devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@
"lockfile_version": "1",
"packages": {
"mariadb@latest": {
"last_modified": "2023-05-01T16:53:22Z",
"last_modified": "2023-08-30T00:25:28Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#mariadb",
"version": "10.6.12"
"resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#mariadb_110",
"source": "devbox-search",
"version": "11.0.3",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/d5nb44vw8yy22lc21ld75nndmn9c3cgr-mariadb-server-11.0.3"
},
"aarch64-linux": {
"store_path": "/nix/store/sz5n9bkcjxklk4jd0p5h26yi5j79wh7h-mariadb-server-11.0.3"
},
"x86_64-darwin": {
"store_path": "/nix/store/4l6h83flncplm3kmry1w08msyy7b7vdw-mariadb-server-11.0.3"
},
"x86_64-linux": {
"store_path": "/nix/store/047g9nxp6jb2bqj1f53qk86sjzrscbmj-mariadb-server-11.0.3"
}
}
}
}
}
}
6 changes: 3 additions & 3 deletions examples/databases/mysql/devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"lockfile_version": "1",
"packages": {
"mysql80@latest": {
"last_modified": "2023-05-01T16:53:22Z",
"last_modified": "2023-06-29T16:20:38Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#mysql80",
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#mysql80",
"version": "8.0.33"
}
}
}
}
5 changes: 3 additions & 2 deletions examples/development/nodejs/nodejs-yarn/devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
}
},
"[email protected]": {
"last_modified": "2023-05-01T16:53:22Z",
"resolved": "github:NixOS/nixpkgs/844ffa82bbe2a2779c86ab3a72ff1b4176cec467#yarn",
"last_modified": "2023-05-21T19:52:09Z",
"resolved": "github:NixOS/nixpkgs/9356eead97d8d16956b0226d78f76bd66e06cb60#yarn",
"source": "devbox-search",
"version": "1.22.19",
"systems": {
"aarch64-darwin": {
Expand Down
128 changes: 109 additions & 19 deletions examples/stacks/laravel/devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,127 @@
"lockfile_version": "1",
"packages": {
"mariadb@latest": {
"last_modified": "2023-05-01T16:53:22Z",
"last_modified": "2023-08-30T00:25:28Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#mariadb",
"version": "10.6.12"
"resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#mariadb_110",
"source": "devbox-search",
"version": "11.0.3",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/d5nb44vw8yy22lc21ld75nndmn9c3cgr-mariadb-server-11.0.3"
},
"aarch64-linux": {
"store_path": "/nix/store/sz5n9bkcjxklk4jd0p5h26yi5j79wh7h-mariadb-server-11.0.3"
},
"x86_64-darwin": {
"store_path": "/nix/store/4l6h83flncplm3kmry1w08msyy7b7vdw-mariadb-server-11.0.3"
},
"x86_64-linux": {
"store_path": "/nix/store/047g9nxp6jb2bqj1f53qk86sjzrscbmj-mariadb-server-11.0.3"
}
}
},
"nginx@latest": {
"last_modified": "2023-05-01T16:53:22Z",
"last_modified": "2023-09-04T16:24:30Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#nginx",
"version": "1.24.0"
"resolved": "github:NixOS/nixpkgs/3c15feef7770eb5500a4b8792623e2d6f598c9c1#nginx",
"source": "devbox-search",
"version": "1.24.0",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/prz9lx44d3hicpmsri5rm9qk44r79ng8-nginx-1.24.0"
},
"aarch64-linux": {
"store_path": "/nix/store/b2v5yw11gmywahlyhbqajml7hjdkhsar-nginx-1.24.0"
},
"x86_64-darwin": {
"store_path": "/nix/store/1nyjvgj3hbhck80wkwi0h18561xbp3sy-nginx-1.24.0"
},
"x86_64-linux": {
"store_path": "/nix/store/vc66rk5b86lx1myxr18qkgzha0fjx2ks-nginx-1.24.0"
}
}
},
"nodejs@18": {
"last_modified": "2023-05-01T16:53:22Z",
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#nodejs",
"version": "18.16.0"
"last_modified": "2023-08-30T00:25:28Z",
"resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#nodejs_18",
"source": "devbox-search",
"version": "18.17.1",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/xpqj3zg5lx25abv9qybiqd7gcs8b81fp-nodejs-18.17.1"
},
"aarch64-linux": {
"store_path": "/nix/store/svc3bwhi6i1jd5387w8dwps23s7d4a62-nodejs-18.17.1"
},
"x86_64-darwin": {
"store_path": "/nix/store/kjsf1qk9w4rknr02silyfq4lxlkh53xq-nodejs-18.17.1"
},
"x86_64-linux": {
"store_path": "/nix/store/51nhk6ycfnj895q07v94jsrwmk2jmz8j-nodejs-18.17.1"
}
}
},
"php81Extensions.xdebug@latest": {
"last_modified": "2023-05-01T16:53:22Z",
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#php81Extensions.xdebug",
"version": "3.2.1"
"last_modified": "2023-08-30T00:25:28Z",
"resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#php81Extensions.xdebug",
"source": "devbox-search",
"version": "3.2.2",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/isd181vs56d55xarvlzqr0cl2c65skq7-php-xdebug-3.2.2"
},
"aarch64-linux": {
"store_path": "/nix/store/c0ij58mr8mqcbx6kkrs1wa6x0m433hzc-php-xdebug-3.2.2"
},
"x86_64-darwin": {
"store_path": "/nix/store/v4i2qbb7aivj3x4i7ipjg1vnfdc3ynvw-php-xdebug-3.2.2"
},
"x86_64-linux": {
"store_path": "/nix/store/q6gp1rn2p6319l8rbwk0arvbbi8kx6bg-php-xdebug-3.2.2"
}
}
},
"php81Packages.composer@latest": {
"last_modified": "2023-05-01T16:53:22Z",
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#php81Packages.composer",
"version": "2.5.5"
"last_modified": "2023-08-30T00:25:28Z",
"resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#php81Packages.composer",
"source": "devbox-search",
"version": "2.5.8",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/7hxmkxa9bmaplyy1ixl0yxv3j0qvxvc3-php-composer-2.5.8"
},
"aarch64-linux": {
"store_path": "/nix/store/vwrbpz9wr7blr7alx0fl3x79ym3jbdqa-php-composer-2.5.8"
},
"x86_64-darwin": {
"store_path": "/nix/store/fjy357jpj9q2bfahsgnak4mrh8y07izw-php-composer-2.5.8"
},
"x86_64-linux": {
"store_path": "/nix/store/6w2vrfjdwhr3mj1magr2rmbycln379f8-php-composer-2.5.8"
}
}
},
"[email protected]": {
"last_modified": "2023-05-01T16:53:22Z",
"last_modified": "2023-09-04T16:24:30Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#php",
"version": "8.1.18"
"resolved": "github:NixOS/nixpkgs/3c15feef7770eb5500a4b8792623e2d6f598c9c1#php81",
"source": "devbox-search",
"version": "8.1.23",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/lb1kvhs6brfphpmxa36kn9fki89ijx7f-php-with-extensions-8.1.23"
},
"aarch64-linux": {
"store_path": "/nix/store/2f935v7hg56faxdp0myam0v8ppdidrd1-php-with-extensions-8.1.23"
},
"x86_64-darwin": {
"store_path": "/nix/store/v5fdxi8pasc8mxacmg76q9qzqpsr04w6-php-with-extensions-8.1.23"
},
"x86_64-linux": {
"store_path": "/nix/store/ky5w9izkk4yyhni3nh31nicmcfch5ndz-php-with-extensions-8.1.23"
}
}
},
"redis@latest": {
"last_modified": "2023-05-01T16:53:22Z",
Expand All @@ -41,4 +131,4 @@
"version": "7.0.11"
}
}
}
}
23 changes: 19 additions & 4 deletions examples/stacks/spring/devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@
"lockfile_version": "1",
"packages": {
"gradle@latest": {
"last_modified": "2023-06-29T16:20:38Z",
"last_modified": "2023-08-30T00:25:28Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#gradle",
"version": "8.0.1"
"resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#gradle",
"source": "devbox-search",
"version": "8.3",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/4xjjls354jr8w7083qxsrpfs1fgl80fj-gradle-8.3"
},
"aarch64-linux": {
"store_path": "/nix/store/f0l5fscvcl9yand9jfpk5icr2ac8qx2v-gradle-8.3"
},
"x86_64-darwin": {
"store_path": "/nix/store/rxm9mpxswrd77fd6lafqcxaxizjlk1l4-gradle-8.3"
},
"x86_64-linux": {
"store_path": "/nix/store/qvp5jiik6q27qwlgiq80fx96wyh0r0nb-gradle-8.3"
}
}
},
"jdk@17": {
"last_modified": "2023-06-29T16:20:38Z",
Expand All @@ -19,4 +34,4 @@
"version": "8.0.33"
}
}
}
}
18 changes: 17 additions & 1 deletion internal/boxcli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"github.com/spf13/cobra"

"go.jetpack.io/devbox"
"go.jetpack.io/devbox/internal/boxcli/usererr"
"go.jetpack.io/devbox/internal/impl/devopt"
)

type updateCmdFlags struct {
config configFlags
sync bool
}

func updateCmd() *cobra.Command {
Expand All @@ -32,6 +34,13 @@ func updateCmd() *cobra.Command {
}

flags.config.register(command)
command.Flags().BoolVar(
&flags.sync,
"sync-lock",
false,
"Sync all devbox.lock dependencies in multiple projects. "+
"Dependencies will sync to the latest local version.",
)
return command
}

Expand All @@ -44,5 +53,12 @@ func updateCmdFunc(cmd *cobra.Command, args []string, flags *updateCmdFlags) err
return errors.WithStack(err)
}

return box.Update(cmd.Context(), args...)
if len(args) > 0 && flags.sync {
return usererr.New("cannot specify both a package and --sync")
}

return box.Update(cmd.Context(), devopt.UpdateOpts{
Pkgs: args,
Sync: flags.sync,
})
}
5 changes: 5 additions & 0 deletions internal/impl/devopt/devboxopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ type Credentials struct {
Email string
Sub string
}

type UpdateOpts struct {
Pkgs []string
Sync bool
}
9 changes: 7 additions & 2 deletions internal/impl/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"go.jetpack.io/devbox/internal/boxcli/featureflag"
"go.jetpack.io/devbox/internal/devpkg"
"go.jetpack.io/devbox/internal/impl/devopt"
"go.jetpack.io/devbox/internal/lock"
"go.jetpack.io/devbox/internal/nix"
"go.jetpack.io/devbox/internal/nix/nixprofile"
Expand All @@ -18,8 +19,12 @@ import (
"go.jetpack.io/devbox/internal/wrapnix"
)

func (d *Devbox) Update(ctx context.Context, pkgs ...string) error {
inputs, err := d.inputsToUpdate(pkgs...)
func (d *Devbox) Update(ctx context.Context, opts devopt.UpdateOpts) error {
if opts.Sync {
return lock.SyncLockfiles()
}

inputs, err := d.inputsToUpdate(opts.Pkgs...)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions internal/lock/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Package struct {
Version string `json:"version,omitempty"`
// Systems is keyed by the system name
Systems map[string]*SystemInfo `json:"systems,omitempty"`

// NOTE: if you add more fields, please update SyncLockfiles
}

type SystemInfo struct {
Expand Down
Loading