@zigordev/stack 1.7.1 → 1.8.1
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.
- package/README.md +69 -51
- package/compose.local.yaml +90 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +33 -8
- package/dist/cli.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,25 +4,28 @@ The shared services of the zigordev platform for a laptop: the ingress, the tele
|
|
|
4
4
|
|
|
5
5
|
## What it is
|
|
6
6
|
|
|
7
|
-
Six containers that every product on the laptop shares. Four of them run in production too, from the same file.
|
|
8
|
-
|
|
9
|
-
| Service
|
|
10
|
-
|
|
|
11
|
-
| `traefik`
|
|
12
|
-
| `docker-proxy`
|
|
13
|
-
| `alloy`
|
|
14
|
-
| `kafka`
|
|
15
|
-
| `kafka-setup`
|
|
16
|
-
| `lgtm`
|
|
17
|
-
| `mailpit`
|
|
18
|
-
| `gcx`
|
|
19
|
-
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
| `
|
|
7
|
+
Six containers that every product on the laptop shares, and on the laptop the notifications service with its database. Four of them run in production too, from the same file.
|
|
8
|
+
|
|
9
|
+
| Service | Image | What it does | Runs |
|
|
10
|
+
| --------------------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
|
|
11
|
+
| `traefik` | Traefik 3.7 | The ingress. It sends each address to its container, from the labels that the container carries | Everywhere |
|
|
12
|
+
| `docker-proxy` | wollomatic/socket-proxy 1.14 | A filtered door to Docker. It lets the ingress and the agent read which containers exist, and nothing else | Everywhere |
|
|
13
|
+
| `alloy` | Grafana Alloy 1.22 | The telemetry agent. It receives traces and metrics from every app, reads every container's log lines and the machine's own numbers, and forwards all of it | Everywhere |
|
|
14
|
+
| `kafka` | Apache Kafka 4.4 | The broker for events between services: one node that is broker and controller at once. Every client signs in with SCRAM-SHA-512 as a user of its own, and may do only what a rule allows | Everywhere |
|
|
15
|
+
| `kafka-setup` | Apache Kafka 4.4 | Not a service but a job: it adds Kafka's topics, users and rules from the list `KAFKA_SETUP`, and ends. It never deletes anything | Everywhere, after the broker is healthy |
|
|
16
|
+
| `lgtm` | grafana/otel-lgtm 0.41 | The local Grafana, with its stores for logs, traces and metrics in the same container | Laptop only |
|
|
17
|
+
| `mailpit` | Mailpit 1.34 | The mail catcher. It receives every email an app sends on the laptop, and shows it on a page | Laptop only |
|
|
18
|
+
| `gcx` | Grafana gcx 1.8 | Not a service but a job: it pushes the dashboards and the alert rules to the local Grafana, and ends | Laptop only, on each `up` |
|
|
19
|
+
| `notifications-api` | notifications, its tag `main` | The email service of every product. It reads each app's email requests from Kafka and sends the email to Mailpit | Laptop only, started last by `up` |
|
|
20
|
+
| `notifications-api-migrate` | notifications, its tag `main` | Not a service but a job: it sets up notifications' database, and ends | Laptop only, before the service |
|
|
21
|
+
| `notifications-postgres` | PostgreSQL 18 | notifications' own database, on a network of its own | Laptop only |
|
|
22
|
+
|
|
23
|
+
| File | What it holds |
|
|
24
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `compose.yaml` | The four services that run everywhere, with the agent's config inside, and Kafka's job with its list of topics, users and rules |
|
|
26
|
+
| `compose.local.yaml` | What only the laptop has: the two other services, notifications with its job and its database, the local addresses, the published ports, the settings and Kafka's throwaway passwords |
|
|
27
|
+
| `observability/` | The dashboards and the alert rules as files, which `pnpm build` writes from the code in the repo's `observability/` folder |
|
|
28
|
+
| `bin/` and `src/` | The command `zigordev-stack`, which starts and stops them |
|
|
26
29
|
|
|
27
30
|
```mermaid
|
|
28
31
|
flowchart LR
|
|
@@ -31,8 +34,9 @@ flowchart LR
|
|
|
31
34
|
traefik --> lgtm["lgtm: Grafana"]
|
|
32
35
|
traefik --> mailpit
|
|
33
36
|
app -->|traces and metrics| alloy
|
|
34
|
-
app -->|email| mailpit
|
|
35
37
|
app -->|events, signed in| kafka
|
|
38
|
+
kafka -->|email requests| notifications["notifications, on the laptop"]
|
|
39
|
+
notifications -->|email| mailpit
|
|
36
40
|
alloy -->|logs, traces, metrics| lgtm
|
|
37
41
|
traefik -.->|which containers exist| proxy["docker-proxy"]
|
|
38
42
|
alloy -.->|which containers exist, and their log lines| proxy
|
|
@@ -182,24 +186,35 @@ On the laptop the job reads a second list after `KAFKA_SETUP`: `KAFKA_SETUP_LAPT
|
|
|
182
186
|
|
|
183
187
|
The broker formats its own storage before the image starts it, and makes the users `admin` and `setup` there, because image 4.4.0 ignores the setting that would do that. [Record 0027](../docs/adr/0027-the-broker-formats-its-own-storage-and-one-list-holds-its-topics-users-and-rules.md) says why.
|
|
184
188
|
|
|
189
|
+
### notifications on the laptop
|
|
190
|
+
|
|
191
|
+
Every product's email requests travel over Kafka to the notifications service, which sends the email. So that one command brings everything up, the laptop also runs notifications, from the profile `notifications` in `compose.local.yaml`: the service, its migration job and its own PostgreSQL. It sends every email to Mailpit. In production notifications is a deploy target of its own, from its own repo.
|
|
192
|
+
|
|
193
|
+
- `zigordev-stack up` starts it last, after Kafka's job has made the topics and users, because a consumer that finds a topic missing never starts.
|
|
194
|
+
- It runs notifications' newest image: its tag `main`, pinned with the digest. Each merge to notifications' `main` moves the tag, and Renovate then proposes the new digest here, after the day's wait, as for every other image. toolkit's record 0052 says why. Its health check names the version `main`.
|
|
195
|
+
- It asks Traefik for no route, and its database publishes no port. It signs in to Kafka as `notifications-api`, with the throwaway password that Kafka's job gives that user.
|
|
196
|
+
- Work on notifications itself runs its own copy, from its repo. `zigordev-stack up --without notifications` stops the shared copy instead of starting it, so the two copies never share the requests.
|
|
197
|
+
- It holds at most 640 MB of memory: 256 MB for the service, 128 MB for the job while it runs, and 256 MB for the database.
|
|
198
|
+
|
|
185
199
|
### The laptop and production
|
|
186
200
|
|
|
187
201
|
The host starts `compose.yaml` with `compose.production.yaml`, through the deploy path of platform: every merge to `main` deploys them as the target `platform`. `docs/cloud-first-deploy.md` in platform says how.
|
|
188
202
|
|
|
189
|
-
| Thing | On the laptop
|
|
190
|
-
| -------------------------------------------- |
|
|
191
|
-
| The four shared services | From `compose.yaml`
|
|
192
|
-
| How a request arrives | Port 80 on the laptop itself, over IPv4 and IPv6
|
|
193
|
-
| How an app outside a container reports | To `127.0.0.1:4318`, the agent's port published on the laptop itself
|
|
194
|
-
| How an app outside a container reaches Kafka | `localhost:9094`, a listener published on the laptop itself
|
|
195
|
-
| Kafka's passwords | Throwaway ones in `compose.local.yaml`
|
|
196
|
-
| Kafka's topics, users and rules | `zigordev-stack up` runs the job `kafka-setup` after the health checks
|
|
197
|
-
| Where the agent sends | To `lgtm`, with a made-up name and password that nothing checks
|
|
198
|
-
| Each container's memory | No file, so the agent reads none
|
|
199
|
-
| The backups' results | No file, so the agent reads none
|
|
200
|
-
| Grafana and the mail catcher | `lgtm` and `mailpit`
|
|
201
|
-
| The
|
|
202
|
-
| The
|
|
203
|
+
| Thing | On the laptop | In production |
|
|
204
|
+
| -------------------------------------------- | --------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
205
|
+
| The four shared services | From `compose.yaml` | The same file |
|
|
206
|
+
| How a request arrives | Port 80 on the laptop itself, over IPv4 and IPv6 | Through Cloudflare's tunnel. `cloudflared`, its connector, runs in production only and hands each request to the ingress |
|
|
207
|
+
| How an app outside a container reports | To `127.0.0.1:4318`, the agent's port published on the laptop itself | Every app runs in a container, so the port is not published |
|
|
208
|
+
| How an app outside a container reaches Kafka | `localhost:9094`, a listener published on the laptop itself | Every app runs in a container, so there is no such listener |
|
|
209
|
+
| Kafka's passwords | Throwaway ones in `compose.local.yaml` | The host's secrets `KAFKA_ADMIN_PASSWORD` and `KAFKA_SETUP_PASSWORD`, which `.env.production.example` names |
|
|
210
|
+
| Kafka's topics, users and rules | `zigordev-stack up` runs the job `kafka-setup` after the health checks | The deploy runs the job after the broker is healthy, as it runs a product's migrate job |
|
|
211
|
+
| Where the agent sends | To `lgtm`, with a made-up name and password that nothing checks | To Grafana Cloud, with the secrets that `.env.production.example` names. Traces and metrics go to `${GRAFANA_OTLP_URL}/otlp`, and logs to `${GRAFANA_LOKI_URL}/loki/api/v1/push`, because the stored addresses carry no path |
|
|
212
|
+
| Each container's memory | No file, so the agent reads none | The host's file `/var/lib/platform/metrics/containers.prom`, which a timer writes every minute |
|
|
213
|
+
| The backups' results | No file, so the agent reads none | The host's files `/var/lib/platform/metrics/backup-dump.prom` and `backup-restore-test.prom`, which the backup script writes after each run |
|
|
214
|
+
| Grafana and the mail catcher | `lgtm` and `mailpit` | Grafana Cloud and Amazon SES |
|
|
215
|
+
| The notifications service | A copy from the profile `notifications`, started last by `up`, sending to Mailpit | Its own deploy target, `notifications`, from its own repo, sending through Amazon SES |
|
|
216
|
+
| The ingress's own pages | At `traefik.localhost` | Off |
|
|
217
|
+
| The proxy's group | 0, which owns the socket on Docker Desktop | The group that owns the socket on the host, which the deploy passes as `DOCKER_SOCKET_GROUP` |
|
|
203
218
|
|
|
204
219
|
## How to use it, with one worked example
|
|
205
220
|
|
|
@@ -211,7 +226,7 @@ pnpm local:down
|
|
|
211
226
|
pnpm local:reset
|
|
212
227
|
```
|
|
213
228
|
|
|
214
|
-
`local:up` builds the dashboard files, starts the services and waits until each one is healthy. It then sets up Kafka's topics, users and rules, pushes the dashboards and the alert rules, and prints the four addresses. `local:down` stops them and keeps their data. `local:reset` stops them, deletes their data and starts them again.
|
|
229
|
+
`local:up` builds the dashboard files, starts the services and waits until each one is healthy. It then sets up Kafka's topics, users and rules, pushes the dashboards and the alert rules, starts notifications, and prints the four addresses. `local:down` stops them and keeps their data. `local:reset` stops them, deletes their data and starts them again.
|
|
215
230
|
|
|
216
231
|
| Address | What opens |
|
|
217
232
|
| -------------------------- | --------------------------------------------------------------------- |
|
|
@@ -254,11 +269,12 @@ pnpm add --save-dev @zigordev/stack
|
|
|
254
269
|
pnpm exec zigordev-stack up
|
|
255
270
|
```
|
|
256
271
|
|
|
257
|
-
| Command
|
|
258
|
-
|
|
|
259
|
-
| `zigordev-stack up`
|
|
260
|
-
| `zigordev-stack
|
|
261
|
-
| `zigordev-stack
|
|
272
|
+
| Command | What it does |
|
|
273
|
+
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
274
|
+
| `zigordev-stack up` | Starts the services, waits until each one is healthy, sets up Kafka's topics, users and rules, pushes the dashboards and the alert rules, and starts notifications. When they run already, it changes nothing |
|
|
275
|
+
| `zigordev-stack up --without notifications` | The same, but it stops the shared copy of notifications instead of starting it. notifications' own repo starts with it |
|
|
276
|
+
| `zigordev-stack down` | Stops them and keeps their data |
|
|
277
|
+
| `zigordev-stack reset` | Stops them, deletes their data and starts them again |
|
|
262
278
|
|
|
263
279
|
The package holds the two compose files, the dashboard and alert files already built, and the command. It has no dependency of its own. It needs Node.js 26 or later, and Docker running.
|
|
264
280
|
|
|
@@ -268,17 +284,18 @@ Every product starts the same project, named `platform`. Two products that hold
|
|
|
268
284
|
|
|
269
285
|
## How to check that it works, and what to do when it does not
|
|
270
286
|
|
|
271
|
-
| Try this
|
|
272
|
-
|
|
|
273
|
-
| `pnpm local:up`
|
|
274
|
-
| `pnpm local:up` a second time
|
|
275
|
-
| Open `http://grafana.localhost`, then Dashboards, then the folder `zigordev`
|
|
276
|
-
| In Grafana, open Alerting, then Alert rules
|
|
277
|
-
| Open `http://grafana.localhost` and `http://mail.localhost`
|
|
278
|
-
| In Grafana's Explore, pick Loki and run `{service_name="traefik"}`
|
|
279
|
-
| Open `http://nothing.localhost`
|
|
280
|
-
| `pnpm exec vitest run stack`
|
|
281
|
-
|
|
|
287
|
+
| Try this | What must happen |
|
|
288
|
+
| --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
289
|
+
| `pnpm local:up` | It prints "kafka-setup: done", and ends with "The shared services are up:" and the four addresses |
|
|
290
|
+
| `pnpm local:up` a second time | The same, within seconds, and no service is recreated |
|
|
291
|
+
| Open `http://grafana.localhost`, then Dashboards, then the folder `zigordev` | The dashboards App and Platform are there, and Platform shows the machine's numbers |
|
|
292
|
+
| In Grafana, open Alerting, then Alert rules | Nine rules are listed in the folder `zigordev`, each one "Normal" |
|
|
293
|
+
| Open `http://grafana.localhost` and `http://mail.localhost` | Both pages open, with no sign-in |
|
|
294
|
+
| In Grafana's Explore, pick Loki and run `{service_name="traefik"}` | Traefik's own log lines show |
|
|
295
|
+
| Open `http://nothing.localhost` | Traefik answers 404, because no container asked for that address |
|
|
296
|
+
| `pnpm exec vitest run stack` | Every rule on this page that a machine can check passes |
|
|
297
|
+
| `docker exec platform-notifications-api-1 wget -qO- http://127.0.0.1:3000/health` | `"status":"ok"`, with `db`, `provider` and `kafka` each `up` |
|
|
298
|
+
| Open a pull request | The job "Shared services" starts all six and notifications on GitHub's machine, opens the four addresses and stops them. A change that breaks a start cannot merge |
|
|
282
299
|
|
|
283
300
|
| What you see | What it means | What to do |
|
|
284
301
|
| ------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -288,6 +305,7 @@ Every product starts the same project, named `platform`. Two products that hold
|
|
|
288
305
|
| `Bind for 127.0.0.1:9094 failed: port is already allocated` | Another program on the laptop holds port 9094, often another Kafka | Find it with `lsof -nP -iTCP:9094 -sTCP:LISTEN`, and stop it |
|
|
289
306
|
| `local:up` says Kafka's topics and users could not be set up | The job `kafka-setup` could not sign in, or a line of `KAFKA_SETUP` is wrong, or a user's password is not set | The line above "zigordev-stack:" starts with "kafka-setup:" and says which. Each line takes one of the three forms of record 0027 |
|
|
290
307
|
| `local:up` ends with "not every shared service became healthy" | One container did not pass its health check in 5 minutes | The lines above name it. `docker logs platform-<service>-1` shows why |
|
|
308
|
+
| `local:up` says notifications did not become healthy | Its database, its migration job or the service itself failed. A topic or a Kafka user that is missing from `KAFKA_SETUP` stops its consumer | `docker logs platform-notifications-api-1`, or `platform-notifications-api-migrate-1` for the job, shows why |
|
|
291
309
|
| `zigordev-stack up` says "the dashboard files are missing" | The files in `stack/observability/` are built, not committed | `pnpm build`, which `pnpm local:up` does by itself |
|
|
292
310
|
| `local:up` says the dashboards and the alert rules could not be pushed | gcx could not reach Grafana, or Grafana refused a file | The lines above name the file and the reason. `pnpm exec vitest run observability` checks the files' shape |
|
|
293
311
|
| A dashboard or a rule that was removed from the code is still in Grafana | gcx does not delete what the files no longer hold | `pnpm local:reset` empties the local Grafana |
|
package/compose.local.yaml
CHANGED
|
@@ -134,5 +134,95 @@ services:
|
|
|
134
134
|
condition: service_healthy
|
|
135
135
|
networks: [zigordev]
|
|
136
136
|
|
|
137
|
+
notifications-api:
|
|
138
|
+
image: ghcr.io/zigordev/notifications-api:main@sha256:ccc88fdd3c4469660a16034d40bf84f0c61c4dcac29f5009153e553feb25c140
|
|
139
|
+
profiles: [notifications]
|
|
140
|
+
restart: unless-stopped
|
|
141
|
+
user: "1000:1000"
|
|
142
|
+
init: true
|
|
143
|
+
read_only: true
|
|
144
|
+
cap_drop: [ALL]
|
|
145
|
+
security_opt: [no-new-privileges:true]
|
|
146
|
+
stop_grace_period: 30s
|
|
147
|
+
mem_limit: 256m
|
|
148
|
+
cpus: 1
|
|
149
|
+
environment:
|
|
150
|
+
PORT: "3000"
|
|
151
|
+
OTEL_SERVICE_NAME: notifications-api
|
|
152
|
+
OTEL_SERVICE_VERSION: main
|
|
153
|
+
OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=local
|
|
154
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: http://alloy:4318
|
|
155
|
+
DATABASE_URL: postgresql://notifications_api:local-only@notifications-postgres:5432/notifications_api
|
|
156
|
+
KAFKA_BROKERS: kafka:9092
|
|
157
|
+
KAFKA_USERNAME: notifications-api
|
|
158
|
+
KAFKA_PASSWORD: local-only-notifications-api
|
|
159
|
+
SMTP_HOST: mailpit
|
|
160
|
+
SMTP_PORT: "1025"
|
|
161
|
+
SMTP_SECURITY: none
|
|
162
|
+
depends_on:
|
|
163
|
+
notifications-api-migrate:
|
|
164
|
+
condition: service_completed_successfully
|
|
165
|
+
tmpfs:
|
|
166
|
+
- /tmp:uid=1000,gid=1000,size=1m
|
|
167
|
+
healthcheck:
|
|
168
|
+
test: [CMD, wget, -q, -T, "4", -O, /dev/null, http://127.0.0.1:3000/health]
|
|
169
|
+
interval: 10s
|
|
170
|
+
timeout: 5s
|
|
171
|
+
retries: 3
|
|
172
|
+
start_period: 30s
|
|
173
|
+
start_interval: 2s
|
|
174
|
+
networks: [zigordev, notifications]
|
|
175
|
+
|
|
176
|
+
notifications-api-migrate:
|
|
177
|
+
image: ghcr.io/zigordev/notifications-api:main@sha256:ccc88fdd3c4469660a16034d40bf84f0c61c4dcac29f5009153e553feb25c140
|
|
178
|
+
profiles: [notifications]
|
|
179
|
+
command: [node, src/migrate.ts]
|
|
180
|
+
restart: "no"
|
|
181
|
+
user: "1000:1000"
|
|
182
|
+
init: true
|
|
183
|
+
read_only: true
|
|
184
|
+
cap_drop: [ALL]
|
|
185
|
+
security_opt: [no-new-privileges:true]
|
|
186
|
+
stop_grace_period: 10s
|
|
187
|
+
mem_limit: 128m
|
|
188
|
+
cpus: 1
|
|
189
|
+
environment:
|
|
190
|
+
OTEL_SERVICE_NAME: notifications-api-migrate
|
|
191
|
+
OTEL_SERVICE_VERSION: main
|
|
192
|
+
DATABASE_URL: postgresql://notifications_api:local-only@notifications-postgres:5432/notifications_api
|
|
193
|
+
DATABASE_ADMIN_URL: postgresql://postgres:local-only@notifications-postgres:5432/postgres
|
|
194
|
+
labels:
|
|
195
|
+
com.zigordev.job: migrate
|
|
196
|
+
depends_on:
|
|
197
|
+
notifications-postgres:
|
|
198
|
+
condition: service_healthy
|
|
199
|
+
networks: [zigordev, notifications]
|
|
200
|
+
|
|
201
|
+
notifications-postgres:
|
|
202
|
+
image: postgres:18.7-alpine3.24@sha256:0115267ab5a509022df9319c77be365cef335adb71556c75f60f5360ee247e71
|
|
203
|
+
profiles: [notifications]
|
|
204
|
+
restart: unless-stopped
|
|
205
|
+
init: true
|
|
206
|
+
security_opt: [no-new-privileges:true]
|
|
207
|
+
stop_grace_period: 30s
|
|
208
|
+
mem_limit: 256m
|
|
209
|
+
cpus: 1
|
|
210
|
+
environment:
|
|
211
|
+
POSTGRES_PASSWORD: local-only
|
|
212
|
+
volumes:
|
|
213
|
+
- notifications-postgres-data:/var/lib/postgresql
|
|
214
|
+
healthcheck:
|
|
215
|
+
test: [CMD, pg_isready, --username=postgres, --dbname=postgres]
|
|
216
|
+
interval: 10s
|
|
217
|
+
timeout: 5s
|
|
218
|
+
retries: 5
|
|
219
|
+
start_period: 30s
|
|
220
|
+
start_interval: 1s
|
|
221
|
+
networks: [notifications]
|
|
222
|
+
|
|
223
|
+
networks:
|
|
224
|
+
notifications: {}
|
|
225
|
+
|
|
137
226
|
volumes:
|
|
138
227
|
lgtm-data:
|
|
228
|
+
notifications-postgres-data:
|
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;AAEzF,MAAM,WAAW,EAAE;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED,eAAO,MAAM,KAAK,YAAI,cAAc,EAAE,oBAAoB,CAAU,CAAC;AACrE,eAAO,MAAM,SAAS,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;AAEzF,MAAM,WAAW,EAAE;IACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED,eAAO,MAAM,KAAK,YAAI,cAAc,EAAE,oBAAoB,CAAU,CAAC;AACrE,eAAO,MAAM,SAAS,kBAAkB,CAAC;AAKzC,eAAO,MAAM,SAAS,sBACnB,0BAA0B,EAAE,oDAAoD,aAChF,uBAAuB,EAAE,0CAA0C,aACnE,0BAA0B,EAAE,8BAA8B,aAC1D,wBAAwB,EAAE,+CAA+C,EAClE,CAAC;AAiGX,wBAAgB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,MAAM,CAuB5D"}
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
export const files = ['compose.yaml', 'compose.local.yaml'];
|
|
3
3
|
export const resources = 'observability';
|
|
4
|
+
const mail = ['--profile', 'notifications'];
|
|
5
|
+
const mailServices = ['notifications-api', 'notifications-postgres'];
|
|
4
6
|
export const addresses = [
|
|
5
7
|
['http://grafana.localhost', 'Grafana: the logs, traces and metrics of every app'],
|
|
6
8
|
['http://mail.localhost', 'Mailpit: every email sent on this laptop'],
|
|
@@ -8,14 +10,17 @@ export const addresses = [
|
|
|
8
10
|
['http://alloy.localhost', 'Alloy: what it receives and where it sends it'],
|
|
9
11
|
];
|
|
10
12
|
const usage = [
|
|
11
|
-
'Usage: zigordev-stack up',
|
|
13
|
+
'Usage: zigordev-stack up [--without notifications]',
|
|
12
14
|
' zigordev-stack down',
|
|
13
15
|
' zigordev-stack reset',
|
|
14
16
|
'',
|
|
15
17
|
'up Starts the shared services and waits until each one is healthy.',
|
|
16
|
-
" It then sets up Kafka's topics and users,
|
|
17
|
-
' and the alert rules to the local Grafana
|
|
18
|
+
" It then sets up Kafka's topics and users, pushes the dashboards",
|
|
19
|
+
' and the alert rules to the local Grafana, and starts notifications,',
|
|
20
|
+
" which delivers every app's email to Mailpit.",
|
|
18
21
|
' When the services are running already, it changes nothing.',
|
|
22
|
+
' --without notifications stops the shared copy of notifications',
|
|
23
|
+
' instead, for work on notifications itself.',
|
|
19
24
|
'down Stops them and keeps their data.',
|
|
20
25
|
'reset Stops them, deletes their data and starts them again.',
|
|
21
26
|
'',
|
|
@@ -23,7 +28,7 @@ const usage = [
|
|
|
23
28
|
function compose(io, ...args) {
|
|
24
29
|
return io.interact('docker', ['compose', ...files.flatMap((file) => ['--file', file]), ...args], io.folder);
|
|
25
30
|
}
|
|
26
|
-
function up(io) {
|
|
31
|
+
function up(io, withMail) {
|
|
27
32
|
if (!io.has(join(io.folder, resources, 'folder.json'))) {
|
|
28
33
|
io.write(`zigordev-stack: the dashboard files are missing from ${join(io.folder, resources)}. In the platform repo, \`pnpm build\` writes them\n`);
|
|
29
34
|
return 1;
|
|
@@ -43,6 +48,20 @@ function up(io) {
|
|
|
43
48
|
io.write('zigordev-stack: the services are up, but the dashboards and the alert rules could not be pushed. The lines above say why\n');
|
|
44
49
|
return pushed;
|
|
45
50
|
}
|
|
51
|
+
if (withMail) {
|
|
52
|
+
const mailing = compose(io, ...mail, 'up', '--detach', '--wait', '--wait-timeout', '300', 'notifications-api');
|
|
53
|
+
if (mailing !== 0) {
|
|
54
|
+
io.write('zigordev-stack: the services are up, but notifications did not become healthy. The lines above say why\n');
|
|
55
|
+
return mailing;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const stopped = compose(io, ...mail, 'stop', ...mailServices);
|
|
60
|
+
if (stopped !== 0) {
|
|
61
|
+
io.write('zigordev-stack: the services are up, but the shared copy of notifications could not be stopped. The lines above say why\n');
|
|
62
|
+
return stopped;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
46
65
|
const width = Math.max(...addresses.map(([address]) => address.length)) + 2;
|
|
47
66
|
io.write([
|
|
48
67
|
'The shared services are up:',
|
|
@@ -52,17 +71,23 @@ function up(io) {
|
|
|
52
71
|
return 0;
|
|
53
72
|
}
|
|
54
73
|
function reset(io) {
|
|
55
|
-
const code = compose(io, 'down', '--volumes');
|
|
56
|
-
return code === 0 ? up(io) : code;
|
|
74
|
+
const code = compose(io, ...mail, 'down', '--volumes');
|
|
75
|
+
return code === 0 ? up(io, true) : code;
|
|
57
76
|
}
|
|
58
77
|
export function main(args, io) {
|
|
59
78
|
const [command, ...rest] = args;
|
|
79
|
+
if (command === 'up' &&
|
|
80
|
+
rest.length === 2 &&
|
|
81
|
+
rest[0] === '--without' &&
|
|
82
|
+
rest[1] === 'notifications') {
|
|
83
|
+
return up(io, false);
|
|
84
|
+
}
|
|
60
85
|
if (rest.length === 0) {
|
|
61
86
|
if (command === 'up') {
|
|
62
|
-
return up(io);
|
|
87
|
+
return up(io, true);
|
|
63
88
|
}
|
|
64
89
|
if (command === 'down') {
|
|
65
|
-
return compose(io, 'down');
|
|
90
|
+
return compose(io, ...mail, 'down');
|
|
66
91
|
}
|
|
67
92
|
if (command === 'reset') {
|
|
68
93
|
return reset(io);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,W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AC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,IAAuB,EAAE,EAAM;IAClD,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAChC,IACE,OAAO,KAAK,IAAI;QAChB,IAAI,CAAC,MAAM,KAAK,CAAC;QACjB,IAAI,CAAC,CAAC,CAAC,KAAK,WAAW;QACvB,IAAI,CAAC,CAAC,CAAC,KAAK,eAAe,EAC3B,CAAC;QACD,OAAO,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,OAAO,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACtB,CAAC;QACD,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;YACvB,OAAO,OAAO,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC;QACD,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IACD,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zigordev/stack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "The shared services of the zigordev platform for a laptop: the ingress, the telemetry agent, a local Grafana and a mail catcher, as compose files with one command that starts them",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"observability"
|
|
19
19
|
],
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@types/node": "26.6.
|
|
21
|
+
"@types/node": "26.6.10",
|
|
22
22
|
"typescript": "7.0.2",
|
|
23
23
|
"vitest": "5.1.1"
|
|
24
24
|
},
|