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
9 changes: 8 additions & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ jobs:
env:
GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
KIT_TAG: ${{ steps.release.outputs['kit--tag_name'] }}
run: gh release edit "$KIT_TAG" --repo "${{ github.repository }}" --latest=false
REPO: ${{ github.repository }}
# --latest=false alone leaves the badge where it is, so the newest
# platform release is promoted explicitly.
run: |
gh release edit "$KIT_TAG" --repo "$REPO" --latest=false
tag="$(gh release list --repo "$REPO" --limit 50 --exclude-drafts --exclude-pre-releases --json tagName --jq '[.[].tagName | select(startswith("v"))][0] // empty')"
[ -n "$tag" ] || { echo "no platform release found" >&2; exit 1; }
gh release edit "$tag" --repo "$REPO" --latest

# Off unless the AUTO_RELEASE repo variable is "true". The PR then
# merges itself once CI passes, which tags and publishes the release.
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Go
/bin/
desktop/src-tauri/binaries/
/.tools/
/dist/
*.test
Expand Down
3 changes: 2 additions & 1 deletion VERSIONING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Generated from `CHANGELOG.md` by `node scripts/gen-versions-table.mjs`. Do not e
<!-- versions:begin -->
| Version | Date | Status | Notes |
| --- | --- | --- | --- |
| 1.5.19 | 2026-12-03 | Latest | [Release notes](https://github.com/glincker/levelrail/releases/tag/v1.5.19) |
| 1.5.20 | 2026-12-04 | Latest | [Release notes](https://github.com/glincker/levelrail/releases/tag/v1.5.20) |
| 1.5.19 | 2026-12-03 | | [Release notes](https://github.com/glincker/levelrail/releases/tag/v1.5.19) |
| 1.5.18 | 2026-11-30 | | [Release notes](https://github.com/glincker/levelrail/releases/tag/v1.5.18) |
| 1.5.17 | 2026-11-29 | | [Release notes](https://github.com/glincker/levelrail/releases/tag/v1.5.17) |
| 1.5.16 | 2026-11-29 | | [Release notes](https://github.com/glincker/levelrail/releases/tag/v1.5.16) |
Expand Down
4 changes: 3 additions & 1 deletion cmd/levelrail-cli/apps_exec_interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

"github.com/coder/websocket"
"golang.org/x/term"

"github.com/glincker/levelrail/internal/apiclient"
)

// terminalCredentials is the already-resolved API target an
Expand Down Expand Up @@ -115,7 +117,7 @@ func runAppsExecInteractive(prog, name string, command []string, creds terminalC
if creds.Token != "" {
header.Set("Authorization", "Bearer "+creds.Token)
}
conn, resp, err := websocket.Dial(ctx, target, &websocket.DialOptions{HTTPHeader: header}) //nolint:bodyclose // coder/websocket closes the handshake body itself
conn, resp, err := websocket.Dial(ctx, target, &websocket.DialOptions{HTTPHeader: header, HTTPClient: &http.Client{Transport: apiclient.LocalPinTransport()}}) //nolint:bodyclose // coder/websocket closes the handshake body itself
if err != nil {
return reportTerminalDialError(prog, stderr, resp, err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/levelrail-cli/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func newBuilderHost(store buildernode.CredStore, stdout io.Writer, lookup func(s
return nil, serr
}
s.CPUs, s.MemoryMiB = cpus, mem
if perr := env.choosePorts(&s); perr != nil {
if _, perr := env.choosePorts(context.Background(), &s, lookup); perr != nil {
return nil, perr
}
l, lerr := env.limits(lookup)
Expand Down
11 changes: 10 additions & 1 deletion cmd/levelrail-cli/builder_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"strconv"
"strings"
"time"

"github.com/glincker/levelrail/internal/vmruntime/limadist"
)

// limaExec runs limactl for the builder instance in the shared Lima home.
Expand Down Expand Up @@ -42,7 +44,14 @@ func builderDir() (string, error) {
return filepath.Join(base, "Levelrail", "builder"), nil
}

func lookupLimactl() (string, error) { return exec.LookPath("limactl") }
func lookupLimactl() (string, error) {
dir, err := vmDataDir()
if err != nil {
return exec.LookPath("limactl")
}
p, _, err := limadist.Find(dir, exec.LookPath)
return p, err
}

func hostMemMiB() int {
switch runtime.GOOS {
Expand Down
7 changes: 7 additions & 0 deletions cmd/levelrail-cli/completion_dynamic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ func TestHiddenComplete_FiltersByPrefix(t *testing.T) {
}
// Offline and unauthenticated, a Tab press prints nothing and exits cleanly.
var out bytes.Buffer
var refreshed []string
old := spawnNamesRefresh
spawnNamesRefresh = func(_, kind string) { refreshed = append(refreshed, kind) }
t.Cleanup(func() { spawnNamesRefresh = old })
t.Setenv("HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
if code := runHiddenComplete("levelrail-cli-test-complete", []string{"deploy", ""}, &out, envMap()); code != exitOK || out.Len() != 0 {
t.Errorf("code=%d out=%q, want a silent success", code, out.String())
}
if len(refreshed) > 1 {
t.Errorf("refreshes = %v, want at most one", refreshed)
}
}

func TestCompletionFlagEnums(t *testing.T) {
Expand Down
97 changes: 71 additions & 26 deletions cmd/levelrail-cli/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ const (
)

type devOptions struct {
sub string
port int
dataDir string
noOpen bool
reset bool
bin string
jsonOut bool
helpOnly bool
sub string
port int
httpPort int
httpsPort int
dataDir string
noOpen bool
reset bool
bin string
jsonOut bool
helpOnly bool
}

func parseDevArgs(prog string, args []string, stderr io.Writer) (devOptions, error) {
Expand All @@ -56,7 +58,9 @@ func parseDevArgs(prog string, args []string, stderr io.Writer) (devOptions, err
}
fs := flag.NewFlagSet(prog+" dev", flag.ContinueOnError)
fs.SetOutput(stderr)
fs.IntVar(&o.port, "port", 0, "dashboard port on 127.0.0.1 (default: 8080, or the next free port)")
fs.IntVar(&o.port, "port", 0, "dashboard port on 127.0.0.1 (default: the saved port, else 8080 or the next free one)")
fs.IntVar(&o.httpPort, "http-port", 0, "app HTTP port on 127.0.0.1 (default: the saved port, else 80 or a free one)")
fs.IntVar(&o.httpsPort, "https-port", 0, "app HTTPS port on 127.0.0.1 (default: the saved port, else 443 or a free one)")
fs.StringVar(&o.dataDir, "data-dir", "", "where the local instance keeps its data (default: a per-user directory, env "+envDevDataDir+")")
fs.BoolVar(&o.noOpen, "no-open", false, "do not open the dashboard in a browser")
fs.BoolVar(&o.reset, "reset", false, "delete the local instance's data and start fresh")
Expand All @@ -73,8 +77,10 @@ func parseDevArgs(prog string, args []string, stderr io.Writer) (devOptions, err
if fs.NArg() > 0 {
return o, fmt.Errorf("unexpected argument %q", fs.Arg(0))
}
if o.port < 0 || o.port > 65535 {
return o, fmt.Errorf("--port %d is out of range", o.port)
for name, p := range map[string]int{"--port": o.port, "--http-port": o.httpPort, "--https-port": o.httpsPort} {
if p < 0 || p > localmode.MaxPort {
return o, fmt.Errorf("%s %d is out of range", name, p)
}
}
return o, nil
}
Expand All @@ -90,8 +96,13 @@ an admin sign-in (printed once, kept in the data directory with mode 0600) and
serves deployed apps at <app>.localhost over plain http. Needs Docker running.
Ctrl-C stops it cleanly.

The first start checks which ports are free, shows who holds the others and lets you
choose; the choice is saved. Change it later with "%[1]s ports set --runtime dev".

Flags:
--port N dashboard port (default 8080, or the next free port)
--port N dashboard port (default: saved, else 8080 or the next free port)
--http-port N app HTTP port (default: saved, else 80 or a free port)
--https-port N app HTTPS port (default: saved, else 443 or a free port)
--data-dir DIR data directory (default: per-user, env %[2]s)
--no-open do not open the dashboard in a browser
--reset delete the local instance's data first
Expand Down Expand Up @@ -231,6 +242,12 @@ func devStart(prog string, o devOptions, stdout, stderr io.Writer, lookupEnv fun
_, _ = fmt.Fprintf(stderr, "%s dev: %v\n", prog, err)
return exitValidation
}
// Read before a reset wipes the folder, so the chosen ports survive it.
ports, err := hostPorts.startPorts(context.Background(), o, stdout, lookupEnv)
if err != nil {
_, _ = fmt.Fprintf(stderr, "%s dev: %v\n", prog, err)
return exitValidation
}
if o.reset {
if err := localmode.Wipe(o.dataDir); err != nil {
_, _ = fmt.Fprintf(stderr, "%s dev: reset: %v\n", prog, err)
Expand All @@ -246,15 +263,9 @@ func devStart(prog string, o devOptions, stdout, stderr io.Writer, lookupEnv fun
_, _ = fmt.Fprintf(stderr, "%s dev: warning: could not record data dir for stop: %v\n", prog, err)
}
}
ports, err := localmode.ChoosePorts(o.port, localmode.LoopbackFree)
if err != nil {
_, _ = fmt.Fprintf(stderr, "%s dev: %v\n", prog, err)
return exitValidation
}

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
sup := &devSupervisor{prog: prog, opts: o, bin: bin, sock: sock, ports: ports, stdout: stdout, stderr: stderr}
sup := &devSupervisor{prog: prog, opts: o, bin: bin, sock: sock, ports: ports, probe: hostPorts.probe, stdout: stdout, stderr: stderr}
return sup.run(ctx)
}

Expand All @@ -263,20 +274,28 @@ type devSupervisor struct {
opts devOptions
bin, sock string
ports localmode.Ports
probe func(ctx context.Context, port int) localmode.PortState
change *portSwitch
stdout, stderr io.Writer
}

func (s *devSupervisor) run(ctx context.Context) int {
first := true
localmode.ClearPortExchange(s.opts.dataDir)
for {
admin, created, err := localmode.LoadOrCreateAdmin(s.opts.dataDir, nil)
if err != nil {
_, _ = fmt.Fprintf(s.stderr, "%s dev: %v\n", s.prog, err)
return exitValidation
}
if err := localmode.SavePorts(s.opts.dataDir, s.ports); err != nil {
_, _ = fmt.Fprintf(s.stderr, "%s dev: %v\n", s.prog, err)
return exitValidation
}
code, restart := s.runOnce(ctx, admin, created, first)
first = false
if !restart {
s.finishSwitch(false, "the instance stopped before the change finished")
localmode.ClearState(s.opts.dataDir)
return code
}
Expand All @@ -291,6 +310,7 @@ func (s *devSupervisor) run(ctx context.Context) int {
_, _ = fmt.Fprintf(s.stderr, "%s dev: %v\n", s.prog, err)
return exitValidation
}
s.applySwitch(ctx)
}
}

Expand All @@ -311,7 +331,7 @@ func (s *devSupervisor) runOnce(ctx context.Context, admin localmode.Admin, crea
cmd.WaitDelay = devChildGrace
if err := cmd.Start(); err != nil {
_, _ = fmt.Fprintf(s.stderr, "%s dev: start control plane: %v\n", s.prog, err)
return exitNetwork, false
return exitNetwork, s.switchFailed(err)
}
var waitErr error
exited := make(chan struct{})
Expand All @@ -321,18 +341,19 @@ func (s *devSupervisor) runOnce(ctx context.Context, admin localmode.Admin, crea
if err := waitDevReady(ctx, url, exited); err != nil {
if ctx.Err() == nil {
_, _ = fmt.Fprintf(s.stderr, "%s dev: control plane did not become ready: %v\n%s\nfull log: %s\n", s.prog, err, tailFile(logPath, devLogTailLines), logPath)
_ = cmd.Process.Signal(os.Interrupt)
<-exited
return exitNetwork, false
stopChild(cmd, exited)
return exitNetwork, s.switchFailed(err)
}
<-exited
return exitOK, false
}
st := localmode.State{PID: os.Getpid(), DataDir: s.opts.dataDir, Dashboard: url, HTTPPort: s.ports.HTTP, HTTPSPort: s.ports.HTTPS, Started: time.Now().UTC()}
st := localmode.State{PID: os.Getpid(), DataDir: s.opts.dataDir, Dashboard: url, HTTPPort: s.ports.HTTP, HTTPSPort: s.ports.HTTPS, Started: time.Now().UTC(), PortChange: true}
if err := localmode.WriteState(st); err != nil {
_, _ = fmt.Fprintf(s.stderr, "%s dev: %v\n", s.prog, err)
}
if first || created {
switched := s.change != nil
s.finishSwitch(true, "")
if first || created || switched {
printDevSummary(s.stdout, s.prog, st, admin, created, logPath)
}
if first && !s.opts.noOpen {
Expand All @@ -341,7 +362,9 @@ func (s *devSupervisor) runOnce(ctx context.Context, admin localmode.Admin, crea
}
}

<-exited
if s.waitForExit(ctx, cmd, exited) {
return exitOK, true
}
werr := waitErr
if ctx.Err() != nil {
_, _ = fmt.Fprintln(s.stdout, "stopped")
Expand All @@ -355,6 +378,28 @@ func (s *devSupervisor) runOnce(ctx context.Context, admin localmode.Admin, crea
return exitNetwork, false
}

// waitForExit blocks while the control plane runs; true means it was stopped to change ports.
func (s *devSupervisor) waitForExit(ctx context.Context, cmd *exec.Cmd, exited <-chan struct{}) bool {
tick := time.NewTicker(devReadyPoll)
defer tick.Stop()
for {
select {
case <-exited:
return false
case <-tick.C:
}
if ctx.Err() != nil {
continue
}
if req, ok := localmode.TakePortRequest(s.opts.dataDir); ok {
s.change = &portSwitch{id: req.ID, old: s.ports, next: req.Ports}
_, _ = fmt.Fprintln(s.stdout, "port change requested: restarting")
stopChild(cmd, exited)
return true
}
}
}

func printDevSummary(w io.Writer, prog string, st localmode.State, a localmode.Admin, created bool, logPath string) {
_, _ = fmt.Fprintf(w, "\nLocal instance is running.\n dashboard: %s\n data dir: %s\n apps: %s (plain http on loopback)\n log: %s\n",
st.Dashboard, st.DataDir, localmode.AppURL("<app>.localhost", st.HTTPPort), logPath)
Expand Down
Loading
Loading