Skip to content

Commit 84959e5

Browse files
authored
Merge pull request #28 from rhyek/feat/service-tags-many-form
Add service tags, run in several services, and SDK parity with the CLI
2 parents 3fc09c4 + b7de5b9 commit 84959e5

115 files changed

Lines changed: 8182 additions & 1211 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
# Changelog
22

3+
## 0.11.0
4+
5+
### Features
6+
7+
- **Services and infra services take `tags`, and `-t, --tag` picks them wherever `-s` does.** See
8+
[docs/config/services.md](docs/config/services.md#tags).
9+
- **`-s` names a service by its name or by a path** on `start`, `service`, `run` and `exec`. See
10+
[docs/guide/commands.md](docs/guide/commands.md#naming-a-service).
11+
- **`run` and `exec` run in several services at once** with `-s` and `-t`. See
12+
[docs/guide/commands.md](docs/guide/commands.md#several-services-at-once).
13+
- **The SDK's `exec()` and `run()` take several services or `tags`, and `startStack()` takes `tags`.**
14+
See [docs/reference/sdk.md](docs/reference/sdk.md#several-services-at-once).
15+
- **The SDK's `attach()` and `wait()` return the stack of a session already running**, wherever it
16+
was started. See [docs/reference/sdk.md](docs/reference/sdk.md#attach-and-wait).
17+
- **The SDK does what the CLI's commands do**: `infra.*`, `service.*`, `stop()`, `status()`,
18+
`events()`, `logs()`, `showConfig()`, `resetProfile()` and `init()`. See
19+
[docs/reference/sdk.md](docs/reference/sdk.md).
20+
- **`infra start`, `restart` and `reset` take `--wait-timeout`.** See
21+
[docs/reference/cli.md](docs/reference/cli.md#stackctl-infra).
22+
23+
### Breaking changes
24+
25+
- **A service's `targetDir` is `dir`, and `resolvedTargetDir` is `resolvedDir`**: rename them in
26+
`stackctl.config.ts` and wherever you read `show-config`, the control API or the exported config.
27+
- **The SDK's `target` option of `exec()`, `run()` and `resolveEnv()` is `service`**: rename it in
28+
your calls.
29+
- **The SDK no longer exports `findService`**: read `config.services[name]` from your config instead.
30+
- **`infra reset` with nothing named resets the profile's whole Compose project**, disabled
31+
services' data included: name the services with `-s` to keep a disabled one's data.
32+
- **`infra reset` and `infra destroy` refuse, before anything runs, a volume or network they
33+
couldn't remove**: act on services that share a volume together, as the message shows, and
34+
remove the container that holds it. See
35+
[docs/config/infra.md](docs/config/infra.md#reset).
36+
- **`infra reset` and `infra destroy` refuse a service that mounts an `external` volume**: clear
37+
its data yourself, then `infra restart -s <service>`.
38+
- **`infra stop` and `infra restart` act on enabled services only**, and refuse a disabled one
39+
named with `-s`: remove a disabled service's container with `infra destroy -s <service>`.
40+
- **A named `infra reset` removes a volume a disabled service also uses**, when no container holds
41+
it: name only the services whose data may go.
42+
- **`infra stop` exits `0` or `1`**, not Compose's own code: check for `1` in scripts.
43+
344
## 0.10.0
445

546
### Features

‎docs/.vitepress/theme/HomeCli.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```bash
2+
# fresh test databases, migrated and seeded
3+
sctl --profile test infra reset
4+
# the frontend, and the backend it waits for
5+
sctl --profile test start --tag browser --detach
6+
# every command from here on runs in the test profile
7+
export STACKCTL_PROFILE=test
8+
sctl exec --tag browser -- \
9+
vitest --config ./vitest.config.e2e.ts
10+
sctl stop
11+
```

‎docs/.vitepress/theme/HomeConfig.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default defineConfig({
2121
port: 3000,
2222
deps: [{ service: 'backend', wait: true }],
2323
urls: [{ label: 'Home page', url: '/' }],
24+
tags: ['browser'],
2425
},
2526
},
2627
infra: {

‎docs/.vitepress/theme/HomeSdk.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
```ts
2+
// scripts/e2e.ts
3+
import { exec, infra, startStack } from 'stackctl';
4+
5+
// fresh test databases, migrated and seeded
6+
await infra.reset({ profile: 'test' });
7+
8+
// the frontend, and the backend it waits for
9+
const stack = await startStack({
10+
profile: 'test',
11+
tags: ['browser'],
12+
});
13+
14+
// the browser tests, with the frontend's environment
15+
await exec({
16+
profile: 'test',
17+
tags: ['browser'],
18+
command: ['vitest', '--config', './vitest.config.e2e.ts'],
19+
});
20+
21+
await stack.stop();
22+
```

‎docs/.vitepress/theme/Layout.vue‎

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<script setup>
22
import { useData, withBase } from 'vitepress';
33
import DefaultTheme, { VPButton } from 'vitepress/theme';
4+
import HomeCli from './HomeCli.md';
45
import HomeConfig from './HomeConfig.md';
6+
import HomeSdk from './HomeSdk.md';
57
import TerminalPlayer from './TerminalPlayer.vue';
68
79
// The home page's frontmatter names the recording, `demo: { src, alt }`, the words beside
8-
// the config example, `config: { title, details, linkText, link }`, and the agent conversation
9-
// with its words, `agents: { title, details, linkText, link, src, alt }`. The config example
10-
// itself is HomeConfig.md, so it is highlighted like any code block.
10+
// the config example, `config: { title, details, linkText, link }`, the words beside the test
11+
// run on the command line and from the SDK, `cli: { … }` and `sdk: { … }` the same, and the agent
12+
// conversation with its words, `agents: { title, details, linkText, link, src, alt }`. Each
13+
// example is a Markdown file (HomeConfig.md, HomeCli.md, HomeSdk.md), so it is highlighted like
14+
// any code block.
1115
const { Layout } = DefaultTheme;
1216
const { frontmatter } = useData();
1317
</script>
@@ -32,6 +36,35 @@ const { frontmatter } = useData();
3236
<HomeConfig />
3337
</div>
3438
</section>
39+
<!-- Text first, so a phone reads the heading before the commands; wide screens swap them. -->
40+
<section v-if="frontmatter.cli" class="home-cli">
41+
<div class="pitch">
42+
<h2>{{ frontmatter.cli.title }}</h2>
43+
<p>{{ frontmatter.cli.details }}</p>
44+
<VPButton
45+
theme="alt"
46+
:text="frontmatter.cli.linkText"
47+
:href="withBase(frontmatter.cli.link)"
48+
/>
49+
</div>
50+
<div class="code vp-doc">
51+
<HomeCli />
52+
</div>
53+
</section>
54+
<section v-if="frontmatter.sdk" class="home-sdk">
55+
<div class="pitch">
56+
<h2>{{ frontmatter.sdk.title }}</h2>
57+
<p>{{ frontmatter.sdk.details }}</p>
58+
<VPButton
59+
theme="alt"
60+
:text="frontmatter.sdk.linkText"
61+
:href="withBase(frontmatter.sdk.link)"
62+
/>
63+
</div>
64+
<div class="code vp-doc">
65+
<HomeSdk />
66+
</div>
67+
</section>
3568
<!-- Text first, so a phone reads the heading before the recording; wide screens swap them. -->
3669
<section v-if="frontmatter.agents" class="home-agents">
3770
<div class="pitch">
@@ -54,6 +87,8 @@ const { frontmatter } = useData();
5487
<style scoped>
5588
.home-demo,
5689
.home-config,
90+
.home-cli,
91+
.home-sdk,
5792
.home-agents {
5893
max-width: 1152px;
5994
margin: 0 auto;
@@ -70,6 +105,8 @@ const { frontmatter } = useData();
70105
}
71106
72107
.home-config,
108+
.home-cli,
109+
.home-sdk,
73110
.home-agents {
74111
display: grid;
75112
gap: 24px;
@@ -100,11 +137,15 @@ const { frontmatter } = useData();
100137
}
101138
102139
/* The code block fills its column, with no margin of its own. */
103-
.home-config .code {
140+
.home-config .code,
141+
.home-cli .code,
142+
.home-sdk .code {
104143
min-width: 0;
105144
}
106145
107-
.home-config .code :deep(div[class*='language-']) {
146+
.home-config .code :deep(div[class*='language-']),
147+
.home-cli .code :deep(div[class*='language-']),
148+
.home-sdk .code :deep(div[class*='language-']) {
108149
margin: 0;
109150
border-radius: 12px;
110151
}
@@ -121,6 +162,8 @@ const { frontmatter } = useData();
121162
@media (min-width: 640px) {
122163
.home-demo,
123164
.home-config,
165+
.home-cli,
166+
.home-sdk,
124167
.home-agents {
125168
padding: 0 48px 56px;
126169
}
@@ -129,6 +172,8 @@ const { frontmatter } = useData();
129172
@media (min-width: 960px) {
130173
.home-demo,
131174
.home-config,
175+
.home-cli,
176+
.home-sdk,
132177
.home-agents {
133178
padding: 0 64px 64px;
134179
}
@@ -143,6 +188,22 @@ const { frontmatter } = useData();
143188
order: -1;
144189
}
145190
191+
/* After the config's words-then-code, the commands on the left and their words on the right. */
192+
.home-cli {
193+
grid-template-columns: 3fr 2fr;
194+
gap: 48px;
195+
}
196+
197+
.home-cli .code {
198+
order: -1;
199+
}
200+
201+
/* Then the words on the left again, the setup on the right. */
202+
.home-sdk {
203+
grid-template-columns: 2fr 3fr;
204+
gap: 48px;
205+
}
206+
146207
.home-config {
147208
grid-template-columns: 2fr 3fr;
148209
gap: 48px;

‎docs/ai/playbook.md‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
description: Recipes for a coding agent - check whether an app is running, find a service's URL, start a stack in the background and wait for it, run tests in the test profile, restart a service, bring back one that is down, run one-off commands, use infra, read logs and onboard a new service.
2+
description: Recipes for a coding agent - check whether an app is running, find a service's URL, start a stack in the background and wait for it, run tests in the test profile, restart a service, bring back one that is down, run one-off commands, run a script across a tag, use infra, read logs and onboard a new service.
33
---
44

55
# Agent playbook
@@ -17,8 +17,8 @@ reference page with the details.
1717
run in. stackctl refuses an agent's command that leaves the profile to the default.
1818
- **Never `kill`, `pkill` or `lsof … | kill` a stackctl process or its port.** Stop a session
1919
you started with `stackctl --profile <profile> stop`, and restart a service with
20-
`stackctl --profile <profile> service restart -s <name>`. A killed session leaves its services
21-
running.
20+
`stackctl --profile <profile> service restart -s <service>`. A killed session leaves its
21+
services running.
2222
- **Check before you start anything.** Starting a session in a profile quits the one already
2323
running in it. stackctl refuses that when a person started it.
2424
- **Never guess a port or hostname.** `stackctl --profile <profile> show-config` prints the
@@ -148,10 +148,10 @@ Don't run the service's command yourself while the session runs it: your copy ta
148148

149149
Read the service's `command` in `stackctl --profile <profile> show-config`:
150150

151-
| `command.watches` | After an edit to its code |
152-
| ----------------- | --------------------------------------------------- |
153-
| `true` | Nothing. Its dev script reloads itself. |
154-
| `false` | `stackctl --profile <profile> service restart -s <name>` |
151+
| `command.watches` | After an edit to its code |
152+
| ----------------- | ----------------------------------------------------------- |
153+
| `true` | Nothing. Its dev script reloads itself. |
154+
| `false` | `stackctl --profile <profile> service restart -s <service>` |
155155

156156
An edit to a `.env` file restarts the affected services on its own, so an unexpected restart
157157
may be an env edit, not a crash. An edit to `stackctl.config.ts` needs the session restarted.
@@ -170,12 +170,30 @@ stackctl --profile development exec ./scripts/report -- node main.ts # a folde
170170
- **A folder that is no service works too**, a script's directory say, with nothing to add to
171171
`stackctl.config.ts`. The command runs there, with the `.env` files of every directory from
172172
the workspace root down to it, its own last, and no `PORT`. See
173-
[Targets](../guide/commands.md#targets).
173+
[Naming a service](../guide/commands.md#naming-a-service).
174174

175175
See [One-off commands](../guide/commands.md). From a script, use
176176
[`exec()`, `run()`](../reference/sdk.md#exec-and-run) or
177177
[`resolveEnv()`](../reference/sdk.md#resolveenv).
178178

179+
## Run a script across a tag
180+
181+
To lint, type-check or test every service of a kind, run the script by its tag:
182+
183+
```bash
184+
stackctl --profile development show-config | jq '.services | map_values(.tags)'
185+
stackctl --profile test run -t backend test
186+
stackctl --profile development run -t backend --ignore-sibling-error lint
187+
```
188+
189+
- **Each line is labelled with its service**, and the summary on stderr names each one `ok`,
190+
`failed` or `stopped`, so read it, not the exit code alone.
191+
- **The first failure stops the others.** Add `--ignore-sibling-error` to see every failure in
192+
one run.
193+
- **A tagged service without the script is skipped**, and says so on stderr.
194+
195+
See [Several services at once](../guide/commands.md#several-services-at-once).
196+
179197
## Infra
180198

181199
```bash

‎docs/config/config-file.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repo.
2828
| Option | What it is |
2929
| ---------------- | -------------------------------------------------------------------------------------------------- |
3030
| `services` | Your application services, keyed by name. See [Services](./services.md). Without it, the config sets the environment of `exec` and `run` alone. |
31-
| `serviceRootDir` | The directory services live under, e.g. `'apps'`: each service is at `<serviceRootDir>/<name>`. **Recommended.** Without it, every service sets `targetDir`. |
31+
| `serviceRootDir` | The directory services live under, e.g. `'apps'`: each service is at `<serviceRootDir>/<name>`. **Recommended.** Without it, every service sets `dir`. |
3232
| `env` | Variables of the config's own, and how `.env` files load. See [Environment](./env.md). |
3333
| `logs` | On-screen timestamps. See [Logs](./logs.md). |
3434
| `infra` | Databases, caches and other Docker Compose services. See [Infra](./infra.md). |

0 commit comments

Comments
 (0)