Skip to content

Commit 9411a3e

Browse files
authored
Update Process Compose to 0.85.0 (#1820)
## Summary Devbox will now install process-compose 0.85.0 if an older version (or no version) is installed on the user's system If an older version of process compose was installed in the utility profile, Devbox will remove that older version first. This PR provides a general way to remove packages (either from Flakes or Nixpkgs) from the utils profile This PR also fixes a bug where using `devbox services up` with the `--config` flag would cause process compose to fail. This PR doesn't add any new 0.85.0 features, though that could be a follow up. ## How was it tested? * Install an older version in the utils profile, check that this upgrades * Remove process-compose from the utlis profile, check that 0.85.0 is installed * This should be pre-released first, for more extensive testing
1 parent b0d6032 commit 9411a3e

File tree

10 files changed

+81
-69
lines changed

10 files changed

+81
-69
lines changed

examples/stacks/lapp-stack/devbox.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"packages": [
33
4-
"postgresql@14",
54
65
"php81Extensions.pgsql@latest",
7-
6+
7+
"postgresql@14"
88
],
99
"env": {
10-
"PGPORT": "5432",
11-
"PGHOST": "/tmp/devbox/lapp"
10+
"PGHOST": "/tmp/devbox/lapp",
11+
"PGPORT": "5432"
1212
},
1313
"shell": {
1414
"scripts": {
@@ -19,10 +19,11 @@
1919
],
2020
"init_db": "initdb",
2121
"run_test": [
22-
"mkdir -p /tmp/devbox/lapp",
22+
"mkdir -p /tmp/devbox/lapp",
2323
"initdb",
24-
"devbox services start",
25-
"echo 'sleep 1 second for the postgres server to initialize.' && sleep 1",
24+
"devbox services up -b",
25+
"echo 'sleep 5 second for the postgres server to initialize.' && sleep 5",
26+
"cat .devbox/compose.log",
2627
"dropdb --if-exists devbox_lapp",
2728
"createdb devbox_lapp",
2829
"psql devbox_lapp < setup_postgres_db.sql",

examples/stacks/lapp-stack/devbox.lock

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
},
6363
6464
"last_modified": "2023-09-04T16:24:30Z",
65-
"plugin_version": "0.0.2",
65+
"plugin_version": "0.0.3",
6666
"resolved": "github:NixOS/nixpkgs/3c15feef7770eb5500a4b8792623e2d6f598c9c1#php81",
6767
"source": "devbox-search",
6868
"version": "8.1.23",
@@ -82,23 +82,22 @@
8282
}
8383
},
8484
"postgresql@14": {
85-
"last_modified": "2023-08-30T00:25:28Z",
86-
"plugin_version": "0.0.2",
87-
"resolved": "github:NixOS/nixpkgs/a63a64b593dcf2fe05f7c5d666eb395950f36bc9#postgresql",
85+
"last_modified": "2023-10-21T19:15:59Z",
86+
"resolved": "github:NixOS/nixpkgs/51d906d2341c9e866e48c2efcaac0f2d70bfd43e#postgresql",
8887
"source": "devbox-search",
8988
"version": "14.9",
9089
"systems": {
9190
"aarch64-darwin": {
92-
"store_path": "/nix/store/x6058p5djhvn57fqyqfs4hvf193m847j-postgresql-14.9"
91+
"store_path": "/nix/store/fp6hphss6sm5r4bflhl35y9mfpl1hmqv-postgresql-14.9"
9392
},
9493
"aarch64-linux": {
95-
"store_path": "/nix/store/0gfagnjbaqlgzf17hrc5pzfr170s6wdl-postgresql-14.9"
94+
"store_path": "/nix/store/ijc70wkgbgc2l8y2va049wrdgrlxd6js-postgresql-14.9"
9695
},
9796
"x86_64-darwin": {
98-
"store_path": "/nix/store/hd25shwpmqcki920ii1cxhh95qa51kfh-postgresql-14.9"
97+
"store_path": "/nix/store/rbicral6k0rzk99wvmj1fd24qc2dc7g3-postgresql-14.9"
9998
},
10099
"x86_64-linux": {
101-
"store_path": "/nix/store/vfcdf4n8f7mxx4rby11f7vhhpi62474m-postgresql-14.9"
100+
"store_path": "/nix/store/ki3srrjjzqalvh0hd9lmqavp5v9wr9jp-postgresql-14.9"
102101
}
103102
}
104103
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/cloudflare/ahocorasick v0.0.0-20210425175752-730270c3e184
1919
github.com/creekorful/mvnparser v1.5.0
2020
github.com/denisbrodbeck/machineid v1.0.1
21-
github.com/f1bonacc1/process-compose v0.43.1
21+
github.com/f1bonacc1/process-compose v0.85.0
2222
github.com/fatih/color v1.16.0
2323
github.com/fsnotify/fsnotify v1.7.0
2424
github.com/getsentry/sentry-go v0.27.0

go.sum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5Jflh
136136
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
137137
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
138138
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
139-
github.com/f1bonacc1/process-compose v0.43.1 h1:XAN7ohegNfMFxYnj59g2jN7y6HfnJWhDCGtD/nN/TbE=
140-
github.com/f1bonacc1/process-compose v0.43.1/go.mod h1:jvg1NakjJd8V1LjGKu21HLLOVxbwkOHEgkaDjSWRXc0=
139+
github.com/f1bonacc1/process-compose v0.85.0 h1:BD3nRHRTLO5jqB5zG1Bu6UJ1Qh5wAkyOWQQ6OKtRRnQ=
140+
github.com/f1bonacc1/process-compose v0.85.0/go.mod h1:NFkS+lyAyKCokif7KvtO3H8MpjD0W4r3PReLn3x4yiQ=
141141
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
142142
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
143143
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
@@ -361,12 +361,8 @@ github.com/yuin/gopher-lua v0.0.0-20190514113301-1cd887cd7036/go.mod h1:gqRgreBU
361361
github.com/zaffka/mongodb-boltdb-mock v0.0.0-20221014194232-b4bb03fbe3a0/go.mod h1:GsDD1qsG+86MeeCG7ndi6Ei3iGthKL3wQ7PTFigDfNY=
362362
github.com/zealic/go2node v0.1.0 h1:ofxpve08cmLJBwFdI0lPCk9jfwGWOSD+s6216x0oAaA=
363363
github.com/zealic/go2node v0.1.0/go.mod h1:GrkFr+HctXwP7vzcU9RsgtAeJjTQ6Ud0IPCQAqpTfBg=
364-
go.jetpack.io/envsec v0.0.16-0.20240111222345-e1fd0e1204ca h1:7Ocnr+mVZTCG8MHlcAdW5d8ir7eqZTmD8S/aEskjXWk=
365-
go.jetpack.io/envsec v0.0.16-0.20240111222345-e1fd0e1204ca/go.mod h1:kCgRGNSHU5AgQXQGUenohPPDoUd87SRL00uOzQsa+Q8=
366364
go.jetpack.io/envsec v0.0.16-0.20240214025624-d233cf877eec h1:IvdOF1C8tAxvKEauWBd/4IWXZfeyXh5vmcfTrcTBPvQ=
367365
go.jetpack.io/envsec v0.0.16-0.20240214025624-d233cf877eec/go.mod h1:koTmI1q2QKqtxaX4P/7r5ygODwgJQ56FKoKRfzpZ0bM=
368-
go.jetpack.io/pkg v0.0.0-20240108193620-a28b84329d15 h1:ztX3CydpNKLePPMRmWgdi4HcxE/AXY6HViOJOmmYNiA=
369-
go.jetpack.io/pkg v0.0.0-20240108193620-a28b84329d15/go.mod h1:kGUL8aZ7ddvoGro0AQxXos9GKn5Qw0J18qW7d5FP4Ws=
370366
go.jetpack.io/pkg v0.0.0-20240213204231-ec96be3d78fb h1:ELaZEV3BL+/GDfPxWPXt6ODNig/VlywWhfAC4P8EG5A=
371367
go.jetpack.io/pkg v0.0.0-20240213204231-ec96be3d78fb/go.mod h1:kGUL8aZ7ddvoGro0AQxXos9GKn5Qw0J18qW7d5FP4Ws=
372368
go.jetpack.io/typeid v1.0.0 h1:8gQ+iYGdyiQ0Pr40ydSB/PzMOIwlXX5DTojp1CBeSPQ=

internal/devbox/devbox.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"os"
1414
"os/exec"
1515
"path/filepath"
16+
"regexp"
1617
"runtime/trace"
1718
"slices"
1819
"strconv"
@@ -31,6 +32,7 @@ import (
3132
"go.jetpack.io/devbox/internal/searcher"
3233
"go.jetpack.io/devbox/internal/shellgen"
3334
"go.jetpack.io/devbox/internal/telemetry"
35+
"go.jetpack.io/devbox/internal/vercheck"
3436

3537
"go.jetpack.io/devbox/internal/boxcli/usererr"
3638
"go.jetpack.io/devbox/internal/cmdutil"
@@ -51,9 +53,9 @@ import (
5153
const (
5254

5355
// shellHistoryFile keeps the history of commands invoked inside devbox shell
54-
shellHistoryFile = ".devbox/shell_history"
55-
56-
arbitraryCmdFilename = ".cmd"
56+
shellHistoryFile = ".devbox/shell_history"
57+
processComposeTargetVersion = "v0.85.0"
58+
arbitraryCmdFilename = ".cmd"
5759
)
5860

5961
type Devbox struct {
@@ -746,7 +748,7 @@ func (d *Devbox) StartProcessManager(
746748
processComposePath, err := utilityLookPath("process-compose")
747749
if err != nil {
748750
fmt.Fprintln(d.stderr, "Installing process-compose. This may take a minute but will only happen once.")
749-
if err = d.addDevboxUtilityPackage(ctx, "github:F1bonacc1/process-compose/v0.43.1"); err != nil {
751+
if err = d.addDevboxUtilityPackage(ctx, "github:F1bonacc1/process-compose/"+processComposeTargetVersion); err != nil {
750752
return err
751753
}
752754

@@ -757,6 +759,28 @@ func (d *Devbox) StartProcessManager(
757759
return err
758760
}
759761
}
762+
re := regexp.MustCompile(`(?m)Version:\s*(v\d*\.\d*\.\d*)`)
763+
pcVersionString, err := exec.Command(processComposePath, "version").Output()
764+
if err != nil {
765+
fmt.Fprintln(d.stderr, "failed to get process-compose version")
766+
return err
767+
}
768+
769+
pcVersion := re.FindStringSubmatch(strings.TrimSpace(string(pcVersionString)))[1]
770+
771+
if vercheck.SemverCompare(pcVersion, processComposeTargetVersion) < 0 {
772+
fmt.Fprintln(d.stderr, "Upgrading process-compose to "+processComposeTargetVersion+"...")
773+
oldProcessComposePkg := "github:F1bonacc1/process-compose/" + pcVersion + "#defaultPackage." + nix.System()
774+
newProcessComposePkg := "github:F1bonacc1/process-compose/" + processComposeTargetVersion
775+
// Find the old process Compose package
776+
if err := d.removeDevboxUtilityPackage(oldProcessComposePkg); err != nil {
777+
return err
778+
}
779+
780+
if err = d.addDevboxUtilityPackage(ctx, newProcessComposePkg); err != nil {
781+
return err
782+
}
783+
}
760784

761785
// Start the process manager
762786

internal/devbox/util.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ package devbox
55

66
import (
77
"context"
8+
"fmt"
89
"io/fs"
910
"os"
1011
"path/filepath"
1112

1213
"github.com/pkg/errors"
1314
"go.jetpack.io/devbox/internal/devpkg"
15+
"go.jetpack.io/devbox/internal/nix"
1416
"go.jetpack.io/devbox/internal/nix/nixprofile"
1517

1618
"go.jetpack.io/devbox/internal/xdg"
@@ -32,14 +34,38 @@ func (d *Devbox) addDevboxUtilityPackage(ctx context.Context, pkgName string) er
3234
return err
3335
}
3436

35-
return nixprofile.ProfileInstall(ctx, &nixprofile.ProfileInstallArgs{
37+
return nix.ProfileInstall(ctx, &nix.ProfileInstallArgs{
3638
Installable: installable,
37-
PackageName: pkgName,
3839
ProfilePath: profilePath,
3940
Writer: d.stderr,
4041
})
4142
}
4243

44+
func (d *Devbox) removeDevboxUtilityPackage(pkgName string) error {
45+
pkg := devpkg.PackageFromStringWithDefaults(pkgName, d.lockfile)
46+
installable, err := pkg.Installable()
47+
if err != nil {
48+
return err
49+
}
50+
51+
utilityProfilePath, err := utilityNixProfilePath()
52+
if err != nil {
53+
return err
54+
}
55+
56+
profile, err := nixprofile.ProfileListItems(d.stderr, utilityProfilePath)
57+
if err != nil {
58+
return err
59+
}
60+
61+
for i, profileItem := range profile {
62+
if profileItem.MatchesUnlockedReference(installable) {
63+
return nix.ProfileRemove(utilityProfilePath, fmt.Sprint(i))
64+
}
65+
}
66+
return nil
67+
}
68+
4369
func utilityLookPath(binName string) (string, error) {
4470
binPath, err := utilityBinPath()
4571
if err != nil {

internal/nix/nixprofile/item.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func (i *NixProfileListItem) Matches(pkg *devpkg.Package, locker lock.Locker) bo
7575
return pkg.Equals(devpkg.PackageFromStringWithDefaults(i.unlockedReference, locker))
7676
}
7777

78+
func (i *NixProfileListItem) MatchesUnlockedReference(installable string) bool {
79+
return i.unlockedReference == installable
80+
}
81+
7882
func (i *NixProfileListItem) addedByStorePath() bool {
7983
return i.unlockedReference == ""
8084
}

internal/nix/nixprofile/profile.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ package nixprofile
55

66
import (
77
"bufio"
8-
"context"
98
"encoding/json"
10-
"fmt"
119
"io"
1210
"strconv"
1311
"strings"
1412

15-
"github.com/fatih/color"
1613
"github.com/pkg/errors"
1714
"github.com/samber/lo"
1815
"go.jetpack.io/devbox/internal/devpkg"
@@ -210,39 +207,3 @@ func parseNixProfileListItemLegacy(line string) (*NixProfileListItem, error) {
210207
nixStorePaths: nixStorePaths,
211208
}, nil
212209
}
213-
214-
type ProfileInstallArgs struct {
215-
CustomStepMessage string
216-
Installable string
217-
Offline bool
218-
PackageName string
219-
ProfilePath string
220-
Writer io.Writer
221-
}
222-
223-
// ProfileInstall calls nix profile install with default profile
224-
func ProfileInstall(ctx context.Context, args *ProfileInstallArgs) error {
225-
stepMsg := args.PackageName
226-
if args.CustomStepMessage != "" {
227-
stepMsg = args.CustomStepMessage
228-
// Only print this first one if we have a custom message. Otherwise it feels
229-
// repetitive.
230-
fmt.Fprintf(args.Writer, "%s\n", stepMsg)
231-
}
232-
233-
err := nix.ProfileInstall(ctx, &nix.ProfileInstallArgs{
234-
Installable: args.Installable,
235-
Offline: args.Offline,
236-
ProfilePath: args.ProfilePath,
237-
Writer: args.Writer,
238-
})
239-
if err != nil {
240-
fmt.Fprintf(args.Writer, "%s: ", stepMsg)
241-
color.New(color.FgRed).Fprintf(args.Writer, "Fail\n")
242-
return redact.Errorf("error running \"nix profile install\": %w", err)
243-
}
244-
245-
fmt.Fprintf(args.Writer, "%s: ", stepMsg)
246-
color.New(color.FgGreen).Fprintf(args.Writer, "Success\n")
247-
return nil
248-
}

internal/services/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/f1bonacc1/process-compose/src/types"
1515
)
1616

17-
type processStates = types.ProcessStates
17+
type processStates = types.ProcessesState
1818

1919
type Process struct {
2020
Name string

internal/services/manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ func runProcessManagerInForeground(cmd *exec.Cmd, config *globalProcessComposeCo
219219
}
220220

221221
func runProcessManagerInBackground(cmd *exec.Cmd, config *globalProcessComposeConfig, port int, projectDir string) error {
222-
logfile, err := os.OpenFile(processComposeLogfile, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_TRUNC, 0o664)
222+
logdir := filepath.Join(projectDir, processComposeLogfile)
223+
logfile, err := os.OpenFile(logdir, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_TRUNC, 0o664)
223224
if err != nil {
224225
return fmt.Errorf("failed to open process-compose log file: %w", err)
225226
}

0 commit comments

Comments
 (0)