workspaces 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/DESIGN.md +23 -21
- data/README.md +103 -8
- data/lib/workspaces/child_env.rb +6 -2
- data/lib/workspaces/cli.rb +18 -4
- data/lib/workspaces/config.rb +4 -0
- data/lib/workspaces/coordinator.rb +28 -0
- data/lib/workspaces/dashboard/app.js +21 -5
- data/lib/workspaces/dashboard/card.html.erb +42 -0
- data/lib/workspaces/dashboard/environment.js +196 -54
- data/lib/workspaces/dashboard/styles.css +172 -85
- data/lib/workspaces/dashboard/template.html.erb +17 -5
- data/lib/workspaces/dashboard_view.rb +165 -27
- data/lib/workspaces/environment_overrides.rb +103 -4
- data/lib/workspaces/front_door.rb +130 -9
- data/lib/workspaces/presentation.rb +1 -1
- data/lib/workspaces/registry.rb +26 -0
- data/lib/workspaces/vault/file_vault.rb +174 -0
- data/lib/workspaces/vault.rb +137 -0
- data/lib/workspaces/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1663319f23323ff66ace4b0744db8bd152448d78ed38d164299bf3c8e641ef8d
|
|
4
|
+
data.tar.gz: 44dea1893b4fc1299a7bb2c064b302e556b3574baebd2b7215fad8747c6b80c6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c00c46b1ac312ae72bb239d74da78fe7c8b4094e0a04d6ae0ebf44232df1050c63f0d5c8a15232daef42d7b9ba526ca71cf86c70731728878db936d98a8b939d
|
|
7
|
+
data.tar.gz: d285c6a6d3f77f94da739295120d7538babc59de94c37fa538eeb0e49c6be6eaefaefe72e2524b9ad448a41032e676fa57f445d359adf15a0bdeba55046ccecc
|
data/DESIGN.md
CHANGED
|
@@ -8,26 +8,22 @@ GET is read-only. All creation and lifecycle controls submit same-origin POST fo
|
|
|
8
8
|
|
|
9
9
|
## Visual direction
|
|
10
10
|
|
|
11
|
-
Restrained tooling UI:
|
|
11
|
+
Restrained tooling UI: a near-black page, one slightly lighter card surface with a hairline border and no shadow, a compact spacing rhythm, clear status affordances, and no decorative animation. Every text pairing is at least 4.5:1 against its surface.
|
|
12
12
|
|
|
13
13
|
## Tokens used
|
|
14
14
|
|
|
15
15
|
### Color
|
|
16
16
|
|
|
17
|
-
- `--bg`:
|
|
18
|
-
- `--
|
|
19
|
-
- `--
|
|
20
|
-
- `--text
|
|
21
|
-
- `--
|
|
22
|
-
- `--accent`: active status and primary action
|
|
23
|
-
- `--success`: completed/ready states
|
|
24
|
-
- `--danger`: failed/error states
|
|
25
|
-
- `--warning`: retry/connection warning text
|
|
17
|
+
- `--bg` `#0b0f17`: page. `--bg-elevated` `#141a26`: card surface. `--border` `#2a3447`: card edge. `--divider` `#252e41`: row dividers. `--border-strong` `#3f4b63`: the table header rule.
|
|
18
|
+
- `--control-border`: the edge of inputs, outline buttons and tabs. Currently `#3f4b63`, about 2:1 against the card. WCAG 1.4.11 asks 3:1 for a control's boundary, so this is a known shortfall, kept to match the design handoff; `#5b6b8a` or lighter reaches 3:1. It is one token, so changing it is a one-line edit.
|
|
19
|
+
- Text: `--text-strong` `#f8fafc` (headings, workspace names, input values), `--text` `#e2e8f0` (body), `--text-cell` `#cbd5e1` (table cells, logs), `--muted` `#a8b3c7` (secondary), `--placeholder` `#8a97ad`.
|
|
20
|
+
- `--accent` `#6fa8ff` with `--on-accent` `#06101f` text on buttons; `--accent-hover` `#8dbbff` for link and button hover. `--success`, `--danger` and `--warning` are unchanged.
|
|
21
|
+
- **Status pills** take three custom properties, `--pill-bg`, `--pill-text` and `--pill-dot`, set per `data-status`. Sleeping indigo, idle amber and stopped red come from the handoff. Ready green, preparing cyan, error deeper red and interrupted orange were chosen to the same contrast (text 8:1 or better, dot 3:1 or better). Any other status gets the neutral slate pair.
|
|
26
22
|
|
|
27
23
|
### Radius and depth
|
|
28
24
|
|
|
29
|
-
- `--radius`: 12px panel corners
|
|
30
|
-
- `--shadow`:
|
|
25
|
+
- `--radius`: 12px panel corners. `--radius-control`: 8px for inputs, buttons and tabs. `--control-height`: 44px.
|
|
26
|
+
- `--shadow`: none. Panels are separated by their border alone.
|
|
31
27
|
|
|
32
28
|
### Spacing scale
|
|
33
29
|
|
|
@@ -35,20 +31,25 @@ Restrained tooling UI: dark elevated panels, compact spacing rhythm, clear statu
|
|
|
35
31
|
|
|
36
32
|
### Typography
|
|
37
33
|
|
|
38
|
-
-
|
|
39
|
-
-
|
|
34
|
+
- Interface: Inter (`--font-sans`) at 15px body, 14px labels at 600, h1 32px at 700, panel h2 20px at 600, table column headers 12px at 600 uppercase with 0.06em tracking.
|
|
35
|
+
- Workspace names, input values and logs: JetBrains Mono (`--font-mono`), 14px. Both stacks fall back to system fonts, because nothing is loaded from the network.
|
|
36
|
+
- Timestamps use `font-variant-numeric: tabular-nums`.
|
|
40
37
|
|
|
41
38
|
## Component primitives
|
|
42
39
|
|
|
43
|
-
- **Creation form**: labelled
|
|
44
|
-
- **Workspace inventory**:
|
|
45
|
-
- **Status pill**:
|
|
40
|
+
- **Creation form**: four labelled fields in one wrapping row (`flex: 1 1 220px`, 16px gap), each with a real `<label for>`, then a `type="submit"` button on its own line.
|
|
41
|
+
- **Workspace inventory**: a centered column up to 1180px. The page header carries "N managed worktrees · none running" (or "· K running"), counted from the data. The table sits in an `overflow-x: auto` wrapper with `min-width: 820px`, so a phone scrolls it sideways instead of cramming or hiding columns. Rows have 16px padding; workspace names are monospaced links with no underline until hover. Times read "Oct 27, 10:48", are UTC (the headers say so) and keep the full ISO value in a `title`. A missing start reads "Never" and a missing creation time "Unavailable", in the muted colour.
|
|
42
|
+
- **Status pill**: a dot and one word (13px, 600, fully rounded), never colour alone. A busy workspace adds "(busy)" and pulses its dot, which stops under reduced motion.
|
|
46
43
|
- **Setup progress**: names and ordered states come from repository run steps; failures are highlighted. Restart shows the background launch and later readiness commands.
|
|
47
44
|
- **Actions by state**: idle/stopped offers Start; active operations show progress without lifecycle buttons; failure offers Retry; ready offers Open workspace plus rebuild/restart/stop.
|
|
48
45
|
- **PR source update**: a secondary Update from PR form only for PR-sourced workspaces; it fetches the latest PR head, fast-forwards the checkout, and preserves local edits without rebuilding or restarting. A persistent result message explains when rebuild is needed or when a retained stash needs manual recovery.
|
|
49
46
|
- **Failure panel**: prominently above the log, with escaped error details and a matching retry action.
|
|
50
47
|
- **PR page**: existing workspaces are primary; creating another is a collapsed secondary disclosure. Creation is primary only when none exist.
|
|
51
|
-
- **
|
|
48
|
+
- **Workspace card**: the default page for a workspace (`/workspaces/ID`, and the same card at the visitor's own address on a preview host while the workspace is not serving). One centered card, about 26rem wide: the workspace id with a gear (an icon link to `/workspaces/ID/settings`, labelled "Settings and details"), the headline and a muted sentence, the *Preset: name* badge when the saved settings match a preset, the progress bar with its step line, elapsed time and estimate, then at most one large full-width action. Idle shows a single start form with a preset select; ready shows **Open workspace**; asleep or stopped shows **Wake workspace** or **Start workspace**; failure shows the shortened error with a link to the full log. The card never opens the preview by itself.
|
|
49
|
+
- **Shared with the settings page**: the card reuses the page's element ids and `app.js`, so polling needs no second script. `app.js` tolerates the elements the card lacks (actions, steps, logs, environment).
|
|
50
|
+
- **On a preview host** (`data-base="/__workspaces"`, `data-reload-when-ready="true"`): the card is served from the workspace's own origin, so it is the smallest surface that can work. It polls `/__workspaces/status`, posts only to `/__workspaces/start|prepare|restart|resume`, shows a fixed failure line instead of error text, and reloads the current page once when the workspace is ready. Everything else (settings, environment, secrets, logs, removal) stays on the shared dashboard origin behind its same-origin check.
|
|
51
|
+
- **Settings page**: the full page described below, with a *Back to workspace* link. It is where Update from PR, keep-awake, rebuild, restart, stop, environment editing and deletion live.
|
|
52
|
+
- **Three layers** (the settings page; the card shows only the lead): the workspace page leads with the friendly, the deliberate, then the technical. Each layer is shown or collapsed by lifecycle state, driven by `Presentation::STATES`:
|
|
52
53
|
1. **Lead** (always visible): a plain-language headline, one sentence, and at most one primary action (a large button). The setup steps never appear here.
|
|
53
54
|
2. **Settings** (a `<details>` titled *Change settings*, with a *Preset: name* badge in its header whenever the saved settings exactly match a preset, so the choice is visible while it is closed, or *Choose what to preview* on a brand new workspace): presets first, as buttons, then the environment variables. The one submit button names what it does (Start workspace, Save & restart, Save & start, Save & retry). It starts open only for a new workspace.
|
|
54
55
|
3. **Technical details** (one `<details>`): setup step logs with timings, the web server log, workspace controls (rebuild, restart, stop, update from PR), preview URL, branch and path, and the Danger Zone. It starts collapsed, and opens by itself while setup runs or after a failure so a cause is never hidden.
|
|
@@ -62,6 +63,7 @@ Restrained tooling UI: dark elevated panels, compact spacing rhythm, clear statu
|
|
|
62
63
|
- **Disclosure behavior**: the server renders the initial open state and the polling script re-applies it from `presentation.open`, but only when the state changes. A section the user opened or closed is left alone on later polls. Sections that are not meaningful in a state are hidden, never shown disabled.
|
|
63
64
|
- **Per-step re-run controls**: inside each step's accordion, small subtle **Re-run this step** and **Re-run from here** forms aimed at `/workspaces/ID/resume?only=KEY` and `?from=KEY`. The server decides which appear (`presentation.resume.step_modes`), so the page never offers something that would be refused; they are hidden while a run is in progress and are disabled with the other controls while busy.
|
|
64
65
|
- **Sleeping**: a workspace asleep is its own state (`sleeping`), distinct from stopped and failed. The lead reads "Your workspace is asleep", says files and data are kept and that opening the preview wakes it, and offers one **Wake workspace** button. A ready workspace shows one muted line, "Sleeps after N min without preview traffic", or "Kept awake" when exempt. **Keep awake** / **Allow sleep** are subtle workspace controls. A waking workspace is simply busy.
|
|
66
|
+
- **Environment rows**: the settings form is a list of rows, each a name input, a value input and a **Secret** checkbox, with **Add variable** and a per-row **Remove** (both revealed by script; without it the server-rendered rows still save). Rows post as `env[N][name|value|secret]`. A secret row's value is a password field that is never pre-filled; a stored secret shows its name, the placeholder "Stored. Enter a new value to replace it", and a locked checked checkbox (a hidden field carries it), so it can only be replaced or removed, not exposed. Ticking Secret on a new row switches its value to a password field. Presets replace only the visible rows and are matched against visible rows alone. A note under the rows shows why secrets are unavailable when the vault is not usable, and a line explains that secrets are write-only.
|
|
65
67
|
- **Action buttons**: start, prepare/rebuild, restart server, stop server, retry failed step, and refresh
|
|
66
68
|
- **Open workspace**: success-styled link available when the server is ready
|
|
67
69
|
- **Lifecycle controls**: hidden while busy (see state machine); helper text distinguishes rebuilding from server-only restart
|
|
@@ -88,6 +90,6 @@ Restrained tooling UI: dark elevated panels, compact spacing rhythm, clear statu
|
|
|
88
90
|
|
|
89
91
|
## Responsive behavior
|
|
90
92
|
|
|
91
|
-
- Single-column layout with intrinsic grid sections
|
|
92
|
-
-
|
|
93
|
-
-
|
|
93
|
+
- Single-column layout with intrinsic grid sections; panel padding is 28px and compresses to 20px at <=640px
|
|
94
|
+
- The workspace table is the one deliberate exception to "no horizontal scrolling": it keeps its columns and scrolls inside its own wrapper, rather than stacking rows and hiding the dates
|
|
95
|
+
- Everything else fits a 375px viewport
|
data/README.md
CHANGED
|
@@ -120,7 +120,9 @@ A ready workspace that sees no preview traffic for a while is put to sleep: its
|
|
|
120
120
|
managed process group, and nothing shared such as PostgreSQL or Redis) is stopped, and the
|
|
121
121
|
front door keeps answering on the same preview URL. The worktree, database, dependencies, built
|
|
122
122
|
assets, environment settings and build history are untouched. The first request to a sleeping
|
|
123
|
-
preview wakes it
|
|
123
|
+
preview wakes it. A browser opening a page is shown the waiting card (below) at that address, and
|
|
124
|
+
the card reloads the page once the workspace is ready. Any other request (an API call, an asset, a
|
|
125
|
+
form post) waits for readiness and is then forwarded.
|
|
124
126
|
|
|
125
127
|
```sh
|
|
126
128
|
WORKSPACES_SLEEP_AFTER_MINUTES=30 # default; 15 also works; 0 switches sleeping off
|
|
@@ -154,7 +156,8 @@ What counts as activity:
|
|
|
154
156
|
How waking behaves:
|
|
155
157
|
|
|
156
158
|
- Only an intentionally sleeping workspace wakes. A workspace stopped by hand, failed, or still
|
|
157
|
-
preparing is never started by traffic
|
|
159
|
+
preparing is never started by traffic. A browser opening a page is shown the waiting card; any
|
|
160
|
+
other GET is redirected to the card on the dashboard host, and other methods get `503`.
|
|
158
161
|
- Simultaneous first requests share one wake and start one server. A request is sent upstream
|
|
159
162
|
once, never replayed, and keeps its method and body.
|
|
160
163
|
- A wake runs only the server and readiness steps. If a step before the server changed in
|
|
@@ -194,6 +197,43 @@ provides `WORKSPACE_RUN_ID`). The runner also supplies `WORKSPACE_URL` and
|
|
|
194
197
|
`WORKSPACE_HOST` for applications that need browser-facing URLs and host settings.
|
|
195
198
|
`serve` does **not** start workspace backends; use `start` or `restart` for those.
|
|
196
199
|
|
|
200
|
+
### The workspace card and the settings page
|
|
201
|
+
|
|
202
|
+
`/workspaces/<id>` is one small card in the middle of the screen: a headline, the progress bar
|
|
203
|
+
while something is running, the preset in use, and the single next action. That action is **Open
|
|
204
|
+
workspace** when ready, **Wake workspace** or **Start workspace** when asleep or stopped, and
|
|
205
|
+
**Retry failed step** or **Continue setup** after a failure. A gear links to
|
|
206
|
+
`/workspaces/<id>/settings`, which is the full page: environment variables and secrets, setup
|
|
207
|
+
steps and logs, workspace details, lifecycle controls and removal. A new workspace starts from the
|
|
208
|
+
card by choosing one preset (or the defaults); use the settings page to edit variables first.
|
|
209
|
+
Update from PR lives on the settings page and returns there. Nothing opens the preview for you;
|
|
210
|
+
the card only offers the button.
|
|
211
|
+
|
|
212
|
+
The `/workspaces` list and the PR page are unchanged.
|
|
213
|
+
|
|
214
|
+
#### The waiting card on a preview host
|
|
215
|
+
|
|
216
|
+
When a browser opens a page of a workspace that is not serving (stopped, preparing, failed or
|
|
217
|
+
asleep), the preview host answers `200` with the same card instead of redirecting to the
|
|
218
|
+
dashboard, so the address in the bar is the one the visitor asked for. A sleeping workspace is
|
|
219
|
+
woken at once. The card polls its status and, when the workspace is ready, reloads the page, so the
|
|
220
|
+
visitor lands where they meant to go, query string included.
|
|
221
|
+
|
|
222
|
+
- Only browser navigations see it: a `GET` that accepts `text/html`, is not an `XMLHttpRequest`
|
|
223
|
+
and, when the browser says, has `Sec-Fetch-Mode: navigate`. API calls, assets and other methods
|
|
224
|
+
behave as before.
|
|
225
|
+
- The preview origin also serves the workspace's own app, so the card is deliberately small. Its
|
|
226
|
+
endpoints are `GET /__workspaces/status` and `POST /__workspaces/start|prepare|restart|resume`.
|
|
227
|
+
The prefix is reserved: any other path under it answers `404`, and it is never forwarded to the
|
|
228
|
+
app. Settings, environment, secrets, logs and removal are not reachable from it.
|
|
229
|
+
- The posts accept only the workspace's own preview origin (the `Origin`, or `Referer`, must match
|
|
230
|
+
`ws-<id>…`); the shared dashboard origin and other workspaces are refused. After a post the
|
|
231
|
+
visitor returns to the page they were on.
|
|
232
|
+
- The status payload carries no logs, steps, environment values or error text. A failure reads
|
|
233
|
+
"Setup failed. Open settings for the full log.", with the gear and link going to the shared
|
|
234
|
+
settings page.
|
|
235
|
+
- Polling the card is not preview traffic, so it never keeps a workspace awake.
|
|
236
|
+
|
|
197
237
|
### Re-running part of a run
|
|
198
238
|
|
|
199
239
|
When a run fails, or is interrupted, you do not have to start over. `resume` continues from the
|
|
@@ -242,6 +282,61 @@ temporarily stashed and restored (including staged state). On a restore conflict
|
|
|
242
282
|
the stash is retained for manual recovery. Updating the checkout does not run
|
|
243
283
|
setup or restart the already-running backend; use Rebuild & restart afterward.
|
|
244
284
|
|
|
285
|
+
### Environment variables and secrets
|
|
286
|
+
|
|
287
|
+
A workspace's settings are rows of **name** and **value**, with a **Secret**
|
|
288
|
+
checkbox on each. Add and remove rows as needed; **Save & restart** applies them.
|
|
289
|
+
|
|
290
|
+
A *secret* is an environment variable that is write-only. Its value goes to a
|
|
291
|
+
vault, is handed to the workspace's setup steps and server as an ordinary
|
|
292
|
+
environment variable, and is never shown again: not in the dashboard, the status
|
|
293
|
+
API, the logs (any output that contains it is filtered) or error messages. A saved
|
|
294
|
+
secret appears as its name with an empty, password-style field that says a value is
|
|
295
|
+
stored. Leave that field blank to keep the stored value, type a new one to replace
|
|
296
|
+
it, or remove the row to delete the secret. A stored secret cannot be turned back
|
|
297
|
+
into a visible variable. Names that look like secrets (`*_TOKEN`, `*_SECRET`,
|
|
298
|
+
`*_PASSWORD`, `*_API_KEY`, ...) cannot be saved as visible variables; tick **Secret**.
|
|
299
|
+
Presets only ever change visible variables.
|
|
300
|
+
|
|
301
|
+
Which vault is used is set where `serve` runs, with `WORKSPACES_VAULT` (default
|
|
302
|
+
`file`). The built-in `file` vault keeps one AES-256-GCM encrypted file per workspace
|
|
303
|
+
in `$WORKSPACES_HOME/vault/`, with a key derived per workspace from a master key you
|
|
304
|
+
provide:
|
|
305
|
+
|
|
306
|
+
```sh
|
|
307
|
+
export WORKSPACES_MASTER_KEY="$(openssl rand -base64 32)" # keep this; it cannot be recovered
|
|
308
|
+
bin/workspaces serve --secure
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Without `WORKSPACES_MASTER_KEY` the settings page says secrets are turned off, and
|
|
312
|
+
everything else works as before. With the wrong key a run fails with a plain reason
|
|
313
|
+
rather than starting without its secrets, and saving is refused so stored secrets are
|
|
314
|
+
never overwritten. The master key is read only by the front door: it is removed from
|
|
315
|
+
the environment of every step, server and `exec` command.
|
|
316
|
+
|
|
317
|
+
Removing a workspace (`remove`, or the dashboard's Remove button) deletes its secrets
|
|
318
|
+
too. The file vault is always asked to delete its own files, even if `WORKSPACES_VAULT`
|
|
319
|
+
has since been changed. A secret that cannot be deleted is reported rather than hidden:
|
|
320
|
+
`remove` exits non-zero and lists it under `secrets_left`, and the dashboard says the
|
|
321
|
+
workspace was removed but its secrets were not. Secrets live outside the workspace's
|
|
322
|
+
checkout, in `$WORKSPACES_HOME/vault/<workspace-id>.enc`, with no other record of the
|
|
323
|
+
link, so a workspace deleted some other way (by hand, or `git worktree remove`) leaves
|
|
324
|
+
its file behind. Clean those up with:
|
|
325
|
+
|
|
326
|
+
```sh
|
|
327
|
+
bin/workspaces purge-secrets --dry-run # list secrets whose workspace no longer exists
|
|
328
|
+
bin/workspaces purge-secrets # delete them
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
It refuses to run if the workspaces directory cannot be read, so an unmounted volume is
|
|
332
|
+
never mistaken for "every workspace is gone".
|
|
333
|
+
|
|
334
|
+
Another store can be added behind the same small interface (`available?`/`problem`,
|
|
335
|
+
`read(scope)`, `write(scope, entries)`, `purge(scope)`, and optionally `scopes` to
|
|
336
|
+
list what it holds so `purge-secrets` can find orphans): subclass
|
|
337
|
+
`Workspaces::Vault::Provider` and call `Workspaces::Vault.register('name', YourClass)`
|
|
338
|
+
from a file loaded with `serve --require`, then set `WORKSPACES_VAULT=name`.
|
|
339
|
+
|
|
245
340
|
### Editable environment presets
|
|
246
341
|
|
|
247
342
|
Recipes can define editable environment defaults and named presets in
|
|
@@ -258,20 +353,20 @@ environment_presets:
|
|
|
258
353
|
DEMO_MODE: "false"
|
|
259
354
|
```
|
|
260
355
|
|
|
261
|
-
Each preset maps editable variable names to values. In the workspace
|
|
262
|
-
choosing a preset
|
|
263
|
-
|
|
264
|
-
**Save & restart** to apply the draft. Presets are not applied automatically,
|
|
356
|
+
Each preset maps editable variable names to values. In the workspace settings,
|
|
357
|
+
choosing a preset replaces the visible variable rows rather than merging with
|
|
358
|
+
them (secret rows are left alone). Selection does not save or restart the
|
|
359
|
+
workspace; choose **Save & restart** to apply the draft. Presets are not applied automatically,
|
|
265
360
|
and defining them requires no JavaScript edits. Preset keys must be declared in
|
|
266
361
|
`default_editable_env`; recipes reject undeclared keys and secret-like values.
|
|
267
|
-
Hidden environment values are never exposed in the
|
|
362
|
+
Hidden environment values are never exposed in the settings or preset choices.
|
|
268
363
|
|
|
269
364
|
Use `create --branch main --preset Demo` to save a preset for a new, still-idle
|
|
270
365
|
workspace. `start ID --preset Demo` applies it before preparing a stopped
|
|
271
366
|
workspace; `restart ID --preset 'Demo off'` switches a running workspace and
|
|
272
367
|
restarts its server. `prepare ID --preset Demo` switches and rebuilds. An
|
|
273
368
|
unknown name is rejected without changing saved settings. Selecting a preset
|
|
274
|
-
replaces the editable settings (including custom
|
|
369
|
+
replaces the editable settings (including custom rows) but preserves
|
|
275
370
|
hidden legacy overrides. A running workspace requires `restart --preset` or
|
|
276
371
|
`prepare --preset`, not `start --preset`.
|
|
277
372
|
|
data/lib/workspaces/child_env.rb
CHANGED
|
@@ -2,6 +2,10 @@ module Workspaces
|
|
|
2
2
|
module ChildEnv
|
|
3
3
|
module_function
|
|
4
4
|
|
|
5
|
+
# Held by the front door alone. Anything a step, the server or `exec` starts must never see the
|
|
6
|
+
# key that opens the secret vault, however it was set.
|
|
7
|
+
WITHHELD = %w(WORKSPACES_MASTER_KEY).freeze
|
|
8
|
+
|
|
5
9
|
def for_workspace(workspace_path:, extra_env: {}, parent_env: ENV.to_h)
|
|
6
10
|
env = parent_env.to_h.transform_keys(&:to_s).dup
|
|
7
11
|
if defined?(::Bundler)
|
|
@@ -10,7 +14,7 @@ module Workspaces
|
|
|
10
14
|
clean.key?(name) ? env[name] = clean[name] : env.delete(name)
|
|
11
15
|
end
|
|
12
16
|
end
|
|
13
|
-
env.delete_if { |key, _| bundler_key?(key) }
|
|
17
|
+
env.delete_if { |key, _| bundler_key?(key) || WITHHELD.include?(key) }
|
|
14
18
|
|
|
15
19
|
gemfile = File.join(workspace_path.to_s, 'Gemfile')
|
|
16
20
|
env['BUNDLE_GEMFILE'] = gemfile
|
|
@@ -18,7 +22,7 @@ module Workspaces
|
|
|
18
22
|
|
|
19
23
|
extra_env.to_h.each do |name, value|
|
|
20
24
|
key = name.to_s
|
|
21
|
-
next if bundler_key?(key)
|
|
25
|
+
next if bundler_key?(key) || WITHHELD.include?(key)
|
|
22
26
|
|
|
23
27
|
if value.nil?
|
|
24
28
|
env.delete(key)
|
data/lib/workspaces/cli.rb
CHANGED
|
@@ -17,7 +17,7 @@ module Workspaces
|
|
|
17
17
|
COMMANDS = {
|
|
18
18
|
'serve' => :serve, 'create' => :create, 'list' => :list, 'show' => :show,
|
|
19
19
|
'start' => :lifecycle, 'prepare' => :lifecycle, 'restart' => :lifecycle,
|
|
20
|
-
'stop' => :stop, 'remove' => :remove, 'resume' => :resume, 'keep-awake' => :keep_awake, 'help' => :help
|
|
20
|
+
'stop' => :stop, 'remove' => :remove, 'purge-secrets' => :purge_secrets, 'resume' => :resume, 'keep-awake' => :keep_awake, 'help' => :help
|
|
21
21
|
}.freeze
|
|
22
22
|
def self.run(argv)
|
|
23
23
|
new.run(argv.dup)
|
|
@@ -88,6 +88,7 @@ module Workspaces
|
|
|
88
88
|
parser.on('--from REF') { |value| options[:from] = value }
|
|
89
89
|
parser.on('--json') { options[:json] = true }
|
|
90
90
|
parser.on('--force') { options[:force] = true }
|
|
91
|
+
parser.on('--dry-run') { options[:dry_run] = true }
|
|
91
92
|
parser.on('--off') { options[:off] = true }
|
|
92
93
|
end
|
|
93
94
|
|
|
@@ -207,8 +208,21 @@ module Workspaces
|
|
|
207
208
|
end
|
|
208
209
|
|
|
209
210
|
def remove(id, options)
|
|
210
|
-
registry.remove(id, force: options[:force])
|
|
211
|
-
|
|
211
|
+
leftover = registry.remove(id, force: options[:force])
|
|
212
|
+
leftover = [] unless leftover.is_a?(Array)
|
|
213
|
+
emit({ 'id' => id, 'removed' => true, 'branch_preserved' => true, 'secrets_left' => leftover }, options)
|
|
214
|
+
return if leftover.empty?
|
|
215
|
+
|
|
216
|
+
warn "The workspace was removed, but its secrets could not be: #{leftover.join('; ')}. " \
|
|
217
|
+
'Fix that, then run `workspaces purge-secrets`.'
|
|
218
|
+
raise ArgumentError, 'Secrets were left behind'
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# Deletes stored secrets whose workspace no longer exists. `--dry-run` lists them without deleting.
|
|
222
|
+
def purge_secrets(_id, options)
|
|
223
|
+
result = registry.sweep_orphaned_secrets(dry_run: options[:dry_run])
|
|
224
|
+
emit(result.merge('dry_run' => !!options[:dry_run]), options)
|
|
225
|
+
raise ArgumentError, "Could not remove: #{result['problems'].join('; ')}" unless result['problems'].empty?
|
|
212
226
|
end
|
|
213
227
|
|
|
214
228
|
def execute(argv)
|
|
@@ -243,7 +257,7 @@ module Workspaces
|
|
|
243
257
|
'Usage: bin/workspaces serve [--require FILE] | create (--branch REF | --pr NUMBER | --new-branch NAME [--from REF]) [--preset NAME] [--set NAME=VALUE] [--unset NAME] [--json] | ' \
|
|
244
258
|
'list [--pr NUMBER] [--json] | show/start/prepare/restart ID [--preset NAME] [--set NAME=VALUE] [--unset NAME] [--json] | ' \
|
|
245
259
|
'resume ID [--from STEP | --only STEP] [--json] | stop ID | keep-awake ID [--off] | ' \
|
|
246
|
-
'exec ID -- COMMAND... | remove ID [--force]'
|
|
260
|
+
'exec ID -- COMMAND... | remove ID [--force] | purge-secrets [--dry-run]'
|
|
247
261
|
end
|
|
248
262
|
|
|
249
263
|
def help(*)
|
data/lib/workspaces/config.rb
CHANGED
|
@@ -130,6 +130,10 @@ module Workspaces
|
|
|
130
130
|
"#{public_origin}/workspaces/#{validate_id!(id)}"
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
+
def self.settings_url(id)
|
|
134
|
+
"#{dashboard_url(id)}/settings"
|
|
135
|
+
end
|
|
136
|
+
|
|
133
137
|
def self.validate_preview_subdomain_prefix!(prefix)
|
|
134
138
|
parts = prefix.to_s.split('.', -1)
|
|
135
139
|
raise ArgumentError, 'WORKSPACES_SUBDOMAIN_PREFIX must not be empty' if parts.empty? || parts.any?(&:empty?)
|
|
@@ -63,6 +63,25 @@ module Workspaces
|
|
|
63
63
|
})
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
+
# Saves the settings form (rows of name / value / secret) and starts the workspace, restarting it
|
|
67
|
+
# if it is already up. See EnvironmentOverrides#replace_rows.
|
|
68
|
+
def replace_environment_rows(id, rows:)
|
|
69
|
+
restart = Backend.new(id).running? || sleeping?(id)
|
|
70
|
+
launch(id, restart: restart, force: true,
|
|
71
|
+
prelaunch: lambda { |_workspace|
|
|
72
|
+
defaults = Recipe.new.default_editable_env
|
|
73
|
+
EnvironmentOverrides.new(id).replace_rows(rows, defaults: defaults)
|
|
74
|
+
})
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Applies one named preset (see EnvironmentOverrides#apply_preset) and starts the workspace,
|
|
78
|
+
# restarting it if it is already up.
|
|
79
|
+
def apply_environment_preset(id, name:)
|
|
80
|
+
restart = Backend.new(id).running? || sleeping?(id)
|
|
81
|
+
launch(id, restart: restart, force: true,
|
|
82
|
+
prelaunch: ->(_workspace) { EnvironmentOverrides.new(id).apply_preset(name) })
|
|
83
|
+
end
|
|
84
|
+
|
|
66
85
|
def replace_editable_environment(id, text:)
|
|
67
86
|
restart = Backend.new(id).running? || sleeping?(id)
|
|
68
87
|
launch(id, restart: restart, force: true,
|
|
@@ -259,6 +278,8 @@ module Workspaces
|
|
|
259
278
|
'log_tail' => include_log ? log_tail(id, log) : '', 'log_source' => log, 'port' => entry['port'],
|
|
260
279
|
'environment_keys' => environment_keys(id),
|
|
261
280
|
'editable_environment' => editable_environment(id),
|
|
281
|
+
'secret_names' => secret_names(id),
|
|
282
|
+
'vault' => Vault.status,
|
|
262
283
|
'environment_presets' => environment_presets
|
|
263
284
|
}
|
|
264
285
|
end
|
|
@@ -475,6 +496,13 @@ module Workspaces
|
|
|
475
496
|
[]
|
|
476
497
|
end
|
|
477
498
|
|
|
499
|
+
# Names only. A secret's value is never part of a snapshot, a status response or a page.
|
|
500
|
+
def secret_names(id)
|
|
501
|
+
EnvironmentOverrides.new(id).secret_names
|
|
502
|
+
rescue EnvironmentOverrides::Invalid
|
|
503
|
+
[]
|
|
504
|
+
end
|
|
505
|
+
|
|
478
506
|
def editable_environment(id)
|
|
479
507
|
EnvironmentOverrides.new(id).editable_values(Recipe.new.default_editable_env)
|
|
480
508
|
rescue Recipe::Invalid, EnvironmentOverrides::Invalid
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const root = document.getElementById('workspace');
|
|
4
4
|
if (!root) return;
|
|
5
5
|
const node = (id) => document.getElementById(id);
|
|
6
|
-
const base = '/workspaces/' + root.dataset.id;
|
|
6
|
+
const base = root.dataset.base || '/workspaces/' + root.dataset.id;
|
|
7
7
|
const selectedLog = new URLSearchParams(window.location.search).get('log') === 'backend'
|
|
8
8
|
? 'backend'
|
|
9
9
|
: 'setup';
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
const signature = JSON.stringify(actions);
|
|
31
31
|
if (signature === actionsSignature) return;
|
|
32
32
|
actionsSignature = signature;
|
|
33
|
-
node('actions')
|
|
33
|
+
const holder = node('actions');
|
|
34
|
+
if (!holder) return;
|
|
35
|
+
holder.replaceChildren();
|
|
34
36
|
actions.forEach((action) => {
|
|
35
37
|
if (!allowedActions.includes(action.key)) return;
|
|
36
38
|
const form = document.createElement('form');
|
|
@@ -41,7 +43,7 @@
|
|
|
41
43
|
'button ' + (action.primary ? 'button--primary' : 'button--subtle');
|
|
42
44
|
button.textContent = action.label;
|
|
43
45
|
form.append(button);
|
|
44
|
-
|
|
46
|
+
holder.append(form);
|
|
45
47
|
});
|
|
46
48
|
toggleBusyState(busy);
|
|
47
49
|
}
|
|
@@ -213,7 +215,8 @@
|
|
|
213
215
|
const full = node('full-log');
|
|
214
216
|
if (full) writeLog(full.querySelector('pre'), data.log_tail);
|
|
215
217
|
}
|
|
216
|
-
node('updated')
|
|
218
|
+
const updated = node('updated');
|
|
219
|
+
if (updated) updated.textContent = data.updated_at || '';
|
|
217
220
|
}
|
|
218
221
|
|
|
219
222
|
function update(data) {
|
|
@@ -226,7 +229,8 @@
|
|
|
226
229
|
renderStatus(view);
|
|
227
230
|
renderSections(view);
|
|
228
231
|
if (node('message')) node('message').textContent = data.message || '';
|
|
229
|
-
node('source-update-message')
|
|
232
|
+
const sourceMessage = node('source-update-message');
|
|
233
|
+
if (sourceMessage) sourceMessage.textContent = data.source_update_message || '';
|
|
230
234
|
renderSteps(view, data.step_logs);
|
|
231
235
|
renderActions(view.actions);
|
|
232
236
|
if (window.WorkspaceEnvironment)
|
|
@@ -271,6 +275,9 @@
|
|
|
271
275
|
badge.textContent = view.current_preset ? 'Preset: ' + view.current_preset : '';
|
|
272
276
|
}
|
|
273
277
|
renderLeadAction(view.lead_action);
|
|
278
|
+
root.querySelectorAll('[data-only-state]').forEach((element) => {
|
|
279
|
+
element.hidden = element.dataset.onlyState !== view.state;
|
|
280
|
+
});
|
|
274
281
|
}
|
|
275
282
|
|
|
276
283
|
// The lead action is a lifecycle post (start/retry) or, when ready, the preview link
|
|
@@ -334,8 +341,17 @@
|
|
|
334
341
|
);
|
|
335
342
|
}
|
|
336
343
|
|
|
344
|
+
// A card on a preview host stands in for the page the visitor asked for; reloading brings them to it.
|
|
345
|
+
let reloading = false;
|
|
346
|
+
function reloadWhenReady(view) {
|
|
347
|
+
if (!view.ready || reloading || root.dataset.reloadWhenReady !== 'true') return;
|
|
348
|
+
reloading = true;
|
|
349
|
+
window.location.reload();
|
|
350
|
+
}
|
|
351
|
+
|
|
337
352
|
function renderStatus(view) {
|
|
338
353
|
node('preview').hidden = !view.ready;
|
|
354
|
+
reloadWhenReady(view);
|
|
339
355
|
node('error').textContent = view.error || '';
|
|
340
356
|
node('error-panel').hidden = !view.error;
|
|
341
357
|
if (window.WorkspaceEnvironment)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<main class="card-page" id="workspace" data-id="<%= @id %>" data-base="<%= action_base %>" data-reload-when-ready="<%= @preview ? 'true' : 'false' %>" data-status="<%= field('status') %>" data-started="<%= field('prepare_started_at') %>" data-completed="<%= field('completed_at') %>" data-busy="<%= @presentation['busy'] %>" data-disclosure-state="<%= escape(@presentation['state']) %>">
|
|
2
|
+
<section class="card" aria-labelledby="status">
|
|
3
|
+
<header class="card__header">
|
|
4
|
+
<p class="card__name"><span class="eyebrow">Workspace</span><span class="card__id"><%= @id %></span></p>
|
|
5
|
+
<a class="icon-link" href="<%= escape(settings_href) %>" aria-label="Settings and details" title="Settings and details"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" focusable="false"><path fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" d="M10.52 5.57L10.69 2.69L13.31 2.69L13.48 5.57A6.6 6.6 0 0 1 15.50 6.40L17.66 4.49L19.51 6.34L17.60 8.50A6.6 6.6 0 0 1 18.43 10.52L21.31 10.69L21.31 13.31L18.43 13.48A6.6 6.6 0 0 1 17.60 15.50L19.51 17.66L17.66 19.51L15.50 17.60A6.6 6.6 0 0 1 13.48 18.43L13.31 21.31L10.69 21.31L10.52 18.43A6.6 6.6 0 0 1 8.50 17.60L6.34 19.51L4.49 17.66L6.40 15.50A6.6 6.6 0 0 1 5.57 13.48L2.69 13.31L2.69 10.69L5.57 10.52A6.6 6.6 0 0 1 6.40 8.50L4.49 6.34L6.34 4.49L8.50 6.40A6.6 6.6 0 0 1 10.52 5.57ZM9.20 12.00a2.8 2.8 0 1 0 5.6 0a2.8 2.8 0 1 0 -5.6 0Z"/></svg></a>
|
|
6
|
+
</header>
|
|
7
|
+
<div class="card__text">
|
|
8
|
+
<h1 id="status" role="status"><%= escape(@presentation['headline']) %></h1>
|
|
9
|
+
<p id="summary" class="card__summary"><%= escape(@presentation['summary']) %></p>
|
|
10
|
+
<p><span class="badge" id="environment-preset-badge" <%= 'hidden' unless @presentation['current_preset'] %>><%= escape(preset_badge_text) %></span></p>
|
|
11
|
+
</div>
|
|
12
|
+
<div class="build-progress" id="build-progress" <%= 'hidden' unless @presentation['progress'] %>>
|
|
13
|
+
<div class="progress-bar" id="progress-bar" role="progressbar" aria-label="Setup progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="<%= progress_percent %>" aria-valuetext="<%= escape(progress_valuetext) %>" data-slow="<%= @presentation.dig('progress', 'slow') ? 'true' : 'false' %>"><span class="progress-bar__fill" id="progress-fill" style="inline-size: <%= progress_percent %>%"></span></div>
|
|
14
|
+
<div class="progress-meta">
|
|
15
|
+
<p class="progress-meta__step"><span class="activity-dot" aria-hidden="true"></span><span id="progress-step"><%= escape(progress_step_text) %></span></p>
|
|
16
|
+
<p class="progress-meta__time muted"><span id="progress-percent"><%= progress_percent %>%</span><span aria-hidden="true"> · </span><span id="elapsed"><%= escape(progress_elapsed_text) %></span><span id="progress-eta"><%= escape(progress_eta_suffix) %></span></p>
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
<form method="post" action="<%= start_form_action %>" class="card__start stack stack--snug lead__action" data-only-state="idle" <%= 'hidden' unless @presentation['state'] == 'idle' %>>
|
|
20
|
+
<% unless environment_presets.empty? %>
|
|
21
|
+
<label class="field" for="card-preset">Preset
|
|
22
|
+
<select id="card-preset" name="preset">
|
|
23
|
+
<% environment_presets.each_key do |name| %><option value="<%= escape(name) %>"><%= escape(name) %></option><% end %>
|
|
24
|
+
<option value="">Defaults</option>
|
|
25
|
+
</select>
|
|
26
|
+
</label>
|
|
27
|
+
<% end %>
|
|
28
|
+
<button class="button button--primary button--large"><%= escape(@presentation['environment_submit']) %></button>
|
|
29
|
+
</form>
|
|
30
|
+
<div class="card__actions">
|
|
31
|
+
<a id="preview" class="button button--primary button--large" href="<%= escape(Config.preview_url(@id)) %>" <%= 'hidden' unless @presentation['ready'] %> target="_blank" rel="noopener noreferrer">Open workspace</a>
|
|
32
|
+
<div id="lead-action" class="lead__action"><%= lead_action_form(@presentation['lead_action']) %></div>
|
|
33
|
+
</div>
|
|
34
|
+
<p id="sleep-note" class="muted" <%= 'hidden' if sleep_note.empty? %>><%= escape(sleep_note) %></p>
|
|
35
|
+
<section class="error-panel setup-error" id="error-panel" role="alert" <%= 'hidden' unless @presentation['error'] %>>
|
|
36
|
+
<h2>What went wrong</h2><pre id="error"><%= escape(@presentation['error']) %></pre>
|
|
37
|
+
<a href="<%= escape(settings_href) %>">Open the full log</a>
|
|
38
|
+
</section>
|
|
39
|
+
<p id="connection" role="status"></p>
|
|
40
|
+
</section>
|
|
41
|
+
<noscript><a href="<%= @preview ? '' : "/workspaces/#{@id}" %>">Refresh status</a></noscript>
|
|
42
|
+
</main>
|