cabby-rails 0.5.1 → 0.5.2
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/CHANGELOG.md +24 -0
- data/README.md +51 -13
- data/lib/cabby/config.rb +10 -5
- data/lib/cabby/rails/version.rb +2 -2
- data/lib/cabby/server_binary.rb +2 -2
- data/lib/generators/cabby/setup/setup_generator.rb +23 -10
- data/lib/generators/cabby/setup/templates/bin/cabby +1 -1
- data/lib/generators/cabby/setup/templates/{cabby.yml → cabby.yml.tt} +9 -1
- data/skills/cabby-rails/SKILL.md +2 -2
- data/skills/cabby-rails/references/channels.md +9 -5
- data/skills/cabby-rails/references/check.md +4 -2
- data/skills/cabby-rails/references/deploy.md +23 -6
- data/skills/cabby-rails/references/frontend.md +14 -0
- data/skills/cabby-rails/references/setup.md +15 -10
- data/skills/cabby-rails/references/troubleshooting.md +6 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9c34106912635b979e4cde04e8adc730149911eac9c1008d290aa06beb99c2a2
|
|
4
|
+
data.tar.gz: 14a7b073ab3013bdfafb25fd842a85ed1fc4a54e86cb5559e7ff28b69b3ce925
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0febae1bd65319ef05b887ad502f8329587fde22d48d709fcee69405e33da1b6e2f143b0932022b59e5a86da74f89877b990c8c0147bb1fc2a0737b46f81569b
|
|
7
|
+
data.tar.gz: 82f00e9f96f89db65c940271e2c04d6cb77bc48941ed0b7cd62d8f6e2a3d34f5ab6e0a0bb960a63b9a015bce8e0f92416f706e672b690fc98d40c477edd7105d
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.2 (2026-12-02)
|
|
4
|
+
|
|
5
|
+
`bin/cabby` installs Cabby 0.6.0, and `cabby:setup` gives Turbo Streams a key of their own.
|
|
6
|
+
|
|
7
|
+
- `bin/cabby` and the Docker image that `cabby:setup` suggests are Cabby 0.6.0, which changes
|
|
8
|
+
some defaults: the README's "Upgrading to Cabby 0.6" says what a Rails app may have to change.
|
|
9
|
+
A partial pin takes the latest release of its minor version: `"0.6"` takes the latest 0.6.x.
|
|
10
|
+
- `cabby:setup`, in apps with Turbo: `config/cabby.yml` reads `turbo_streams_secret` from
|
|
11
|
+
`CABBY_TURBO_STREAMS_SECRET` (or the credentials), the server command adds
|
|
12
|
+
`--turbo_streams_secret=$CABBY_TURBO_STREAMS_SECRET`, the Docker Compose snippet gives the
|
|
13
|
+
variable to the app and the server alike, and the next steps export it. With one key, a page's
|
|
14
|
+
Turbo Streams name is also a `$pubsub` signed name, which gives presence on its stream, and
|
|
15
|
+
Cabby 0.6 warns about it at startup. Apps set up before keep working; the README says how to
|
|
16
|
+
switch.
|
|
17
|
+
- `none` for `streams_secret` or `turbo_streams_secret` turns that key off, with no fallback to
|
|
18
|
+
`secret`, as Cabby does: with `turbo_streams_secret: none` the gem gives Turbo no key (it gave
|
|
19
|
+
it the secret), and with `streams_secret: none` `Cabby.sign_stream` raises
|
|
20
|
+
`Cabby::ConfigurationError`.
|
|
21
|
+
- README and skill: whispers reach only the subscriptions that take whispers on their stream
|
|
22
|
+
(`--whisper_compat_0_5` while 0.5 and 0.6 servers run side by side), and an upgrade table for
|
|
23
|
+
the Turbo Streams key, server-generated session ids, Redis certificates checked over TLS, the
|
|
24
|
+
pending size limit for SSE, Durable Streams and Pusher clients, and NATS reconnects without a
|
|
25
|
+
limit.
|
|
26
|
+
|
|
3
27
|
## 0.5.1 (2026-11-30)
|
|
4
28
|
|
|
5
29
|
The bundled browser client is `@cabby/web` 0.4.1, and `bin/cabby` installs Cabby 0.5.11.
|
data/README.md
CHANGED
|
@@ -48,24 +48,24 @@ In development, `cabby:setup` sets the server up the way the app runs:
|
|
|
48
48
|
|---|---|---|
|
|
49
49
|
| `bin` | a `cabby:` line in `Procfile.dev`, `bin/cabby` | `bin/dev`; `foreman start -f Procfile.dev` when `bin/dev` does not run `Procfile.dev` (the generator says which) |
|
|
50
50
|
| `puma` | `plugin :cabby` in `config/puma.rb`, `bin/cabby` | `CABBY_IN_PUMA=1 bin/rails server` |
|
|
51
|
-
| `docker` | nothing: prints a Docker Compose snippet (`ghcr.io/danig2k/cabby:0.
|
|
51
|
+
| `docker` | nothing: prints a Docker Compose snippet (`ghcr.io/danig2k/cabby:0.6.0`) | `docker compose up` |
|
|
52
52
|
| `skip` | nothing: prints the command | `cabby ...` |
|
|
53
53
|
|
|
54
54
|
Without the option it takes `bin` when the app has a `Procfile.dev`, else `puma` when it has a
|
|
55
55
|
`config/puma.rb`, else `skip`; it asks only on a terminal. The command it writes:
|
|
56
56
|
|
|
57
57
|
```sh
|
|
58
|
-
bin/cabby --rpc_host=http://localhost:3000/_cabby --secret=$CABBY_SECRET --broadcast_adapter=http --turbo_streams --port=8080
|
|
58
|
+
bin/cabby --rpc_host=http://localhost:3000/_cabby --secret=$CABBY_SECRET --broadcast_adapter=http --turbo_streams --turbo_streams_secret=$CABBY_TURBO_STREAMS_SECRET --port=8080
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
`--turbo_streams`
|
|
62
|
-
which the server reads.
|
|
61
|
+
`--turbo_streams` and `--turbo_streams_secret` come with Turbo ([below](#turbo)); `--port=8080`
|
|
62
|
+
because `bin/dev` gives each process a `PORT`, which the server reads.
|
|
63
63
|
|
|
64
64
|
**`bin/cabby`** runs the server with every argument it gets. Its first run downloads the server
|
|
65
|
-
release this gem was tested with (0.
|
|
65
|
+
release this gem was tested with (0.6.0) into `bin/dist/` (git-ignored), checked against the
|
|
66
66
|
release's `SHA256SUMS`; later runs start offline. To pin another version, edit the line in
|
|
67
|
-
`bin/cabby`: `"0.
|
|
68
|
-
the release's files on GitHub, with no API call and so no rate limit; `"0.
|
|
67
|
+
`bin/cabby`: `"0.6.0"`, or `"0.6"` for the latest 0.6.x. A full version is downloaded from
|
|
68
|
+
the release's files on GitHub, with no API call and so no rate limit; `"0.6"` lists the
|
|
69
69
|
repository's tags with `git ls-remote`. `CABBY_RELEASES_URL` replaces the repository address
|
|
70
70
|
with a mirror that serves the same `releases/download/v<version>/<file>` paths. Prebuilt servers
|
|
71
71
|
exist for Linux (x86_64, arm64, glibc) and macOS on Apple silicon; elsewhere, [install the
|
|
@@ -88,8 +88,9 @@ export CABBY_SECRET=$(bin/rails secret) # or the credentials, see config/
|
|
|
88
88
|
cabby --rpc_host=http://localhost:3000/_cabby --secret=$CABBY_SECRET
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
`connect`; list any other header it
|
|
91
|
+
With Turbo, add `--turbo_streams --turbo_streams_secret=$CABBY_TURBO_STREAMS_SECRET` (see
|
|
92
|
+
[below](#turbo)). Cabby forwards the `Cookie` header to `connect`; list any other header it
|
|
93
|
+
reads: `--headers=cookie,x-tenant`.
|
|
93
94
|
|
|
94
95
|
Without a secret the endpoint answers only in development and test; outside development and
|
|
95
96
|
test it refuses every call (and says so in the log).
|
|
@@ -127,7 +128,9 @@ variable, so does the gem, with the server's default.
|
|
|
127
128
|
| `jwt_ttl` | `CABBY_JWT_TTL` | `3600` (seconds a token is valid) |
|
|
128
129
|
| `rpc_max_body_size` | `CABBY_RPC_MAX_BODY_SIZE` | 16 MiB |
|
|
129
130
|
|
|
130
|
-
|
|
131
|
+
As on the server, `secret: none` counts as unset, and `none` for another secret or key turns
|
|
132
|
+
it off with no fallback to `secret`: with `turbo_streams_secret: none` the gem gives Turbo no
|
|
133
|
+
key, and Cabby (0.6 and later, with `--turbo_streams`) rejects every Turbo Streams name.
|
|
131
134
|
|
|
132
135
|
## Broadcasting
|
|
133
136
|
|
|
@@ -253,7 +256,23 @@ instead ([below](#turbo-streams-on-the-browser-client)).
|
|
|
253
256
|
With a secret configured, the gem gives Turbo the key the server's `--turbo_streams` verifies
|
|
254
257
|
with (`turbo_streams_secret`, else `streams_secret`, else `secret`, as the server falls back).
|
|
255
258
|
Run Cabby with `--turbo_streams` and it confirms Turbo subscriptions itself, without calling the
|
|
256
|
-
app.
|
|
259
|
+
app.
|
|
260
|
+
|
|
261
|
+
Give Turbo a key of its own, the same `CABBY_TURBO_STREAMS_SECRET` for the app and the server.
|
|
262
|
+
With the secret's key, a page's Turbo Streams name is also a `$pubsub` signed name, which lets
|
|
263
|
+
its viewer join the stream's presence, and Cabby 0.6 logs at startup:
|
|
264
|
+
|
|
265
|
+
```text
|
|
266
|
+
WRN Turbo Streams signed names are also accepted by $pubsub (the same key verifies them), where they give presence on their stream; set --turbo_streams_secret to a key of its own
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
`cabby:setup` sets it up that way. An app set up before 0.5.2 keeps working as it is. To
|
|
270
|
+
switch, give the app and the server the same new `CABBY_TURBO_STREAMS_SECRET` (`bin/rails
|
|
271
|
+
secret`) where they get `CABBY_SECRET`: the gem and the server both read the variable (a key
|
|
272
|
+
kept in the credentials goes in `config/cabby.yml` as `turbo_streams_secret`, as `cabby:setup`
|
|
273
|
+
writes it). Pages rendered before the switch subscribe again once reloaded.
|
|
274
|
+
|
|
275
|
+
Set `turbo_streams: false` to leave Turbo's key alone. A key the app sets itself
|
|
257
276
|
(`config.turbo.signed_stream_verifier_key`) is kept; then give Cabby that key with
|
|
258
277
|
`--turbo_streams_secret`, or run it without `--turbo_streams`: if the app sets
|
|
259
278
|
`Turbo.signed_stream_verifier_key` after boot, the server's key no longer matches and Cabby
|
|
@@ -444,7 +463,7 @@ Presence and whispers need no setup in the channel; presence needs a broker
|
|
|
444
463
|
```ruby
|
|
445
464
|
class ChatChannel < ApplicationCable::Channel
|
|
446
465
|
def subscribed
|
|
447
|
-
stream_from "chat_#{params[:room]}", whisper: true # whispers
|
|
466
|
+
stream_from "chat_#{params[:room]}", whisper: true # takes whispers, and sends them to the others
|
|
448
467
|
join_presence # on the first stream of this call
|
|
449
468
|
end
|
|
450
469
|
|
|
@@ -467,6 +486,10 @@ end
|
|
|
467
486
|
`@rails/actioncable` it drops one after the same time.
|
|
468
487
|
- One whisper stream per subscription: the last `whisper: true` wins, and stopping that stream
|
|
469
488
|
stops the whispers. Without `whisper: true` Cabby drops them.
|
|
489
|
+
- A whisper reaches only the subscriptions that take whispers on its stream (`whisper: true`, or
|
|
490
|
+
`$pubsub` with `--streams_whisper`), never its sender. A Turbo Streams subscription to the same
|
|
491
|
+
stream, or a channel streaming from it without `whisper: true`, does not receive it (Cabby 0.6;
|
|
492
|
+
0.5 sent it to every subscriber).
|
|
470
493
|
|
|
471
494
|
What does not work in this model, each call having a new instance:
|
|
472
495
|
|
|
@@ -503,11 +526,26 @@ Such code then raises `Cabby::CompatibilityError` where it runs, on Cabby and in
|
|
|
503
526
|
`ActionCable::Channel::TestCase` tests, where a channel also stops keeping its instance variables
|
|
504
527
|
from one call to the next. Code that works is left alone.
|
|
505
528
|
|
|
529
|
+
## Upgrading to Cabby 0.6
|
|
530
|
+
|
|
531
|
+
Since cabby-rails 0.5.2, `bin/cabby` and the suggested image are Cabby 0.6.0. What a Rails app
|
|
532
|
+
may have to change ([all of it](https://docs.cabbyhq.com/upgrading-to-0-6)):
|
|
533
|
+
|
|
534
|
+
| If the app | Then |
|
|
535
|
+
|---|---|
|
|
536
|
+
| Reads whispers in a channel that streams from the stream without `whisper: true` | Add `whisper: true` there: a whisper now reaches only the subscriptions that take whispers |
|
|
537
|
+
| Runs 0.5 and 0.6 servers side by side while upgrading | `--whisper_compat_0_5` on the 0.6 servers until the last 0.5 one is gone |
|
|
538
|
+
| Signs Turbo Streams names with the secret | A key of its own, `CABBY_TURBO_STREAMS_SECRET` ([Turbo](#turbo)), or a warning at each start |
|
|
539
|
+
| Relies on a proxy's `X-Request-ID` being the session id (`Cabby::Rails.current_sid`, `sid=` in the logs) | `--request_id_as_session_id`: the server now generates every session id |
|
|
540
|
+
| Connects Cabby to Redis over TLS with a self-signed or private CA certificate | `--redis_tls_ca_cert_path`, or `--redis_tls_verify=false`: the server now checks the certificate |
|
|
541
|
+
| Has SSE, Durable Streams or Pusher clients that fall more than 1 MiB behind | A larger `--ws_max_pending_size`: they are now disconnected as slow, as Action Cable clients are |
|
|
542
|
+
| Limits NATS reconnects in a server configuration file (`[nats]`; a 0.5 `--print-config` wrote 5) | Remove the limit: the server now keeps reconnecting, and with one it exits once the attempts run out |
|
|
543
|
+
|
|
506
544
|
## Deploying
|
|
507
545
|
|
|
508
546
|
Run two processes: the app, and `cabby` next to it.
|
|
509
547
|
|
|
510
|
-
- Same `CABBY_SECRET` for both
|
|
548
|
+
- Same `CABBY_SECRET` for both, and with Turbo the same `CABBY_TURBO_STREAMS_SECRET`.
|
|
511
549
|
- `cabby --rpc_host=http://<app, internal address>/_cabby --secret=$CABBY_SECRET`, plus
|
|
512
550
|
`--turbo_streams` with Turbo and the `--broadcast_adapter` you use.
|
|
513
551
|
- `CABBY_URL=wss://<the public address of cabby>/cable` in the app, so pages point at Cabby.
|
data/lib/cabby/config.rb
CHANGED
|
@@ -96,10 +96,11 @@ module Cabby
|
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
# The keys the server verifies signed stream names with: --streams_secret, else the
|
|
99
|
-
# application secret; Turbo's: --turbo_streams_secret, else that same key.
|
|
100
|
-
|
|
99
|
+
# application secret; Turbo's: --turbo_streams_secret, else that same key. "none" turns a
|
|
100
|
+
# key off, with no fallback, as on the server.
|
|
101
|
+
def streams_key = explicit_or_derived(:streams_secret) { |secret| secret }
|
|
101
102
|
|
|
102
|
-
def turbo_streams_key = turbo_streams_secret
|
|
103
|
+
def turbo_streams_key = explicit_or(:turbo_streams_secret) { streams_key }
|
|
103
104
|
|
|
104
105
|
private
|
|
105
106
|
|
|
@@ -111,13 +112,17 @@ module Cabby
|
|
|
111
112
|
end
|
|
112
113
|
end
|
|
113
114
|
|
|
114
|
-
|
|
115
|
+
# The explicit setting; nil when it is "none"; else what the block gives.
|
|
116
|
+
def explicit_or(explicit)
|
|
115
117
|
return setting(explicit) if setting(explicit)
|
|
116
118
|
return if raw(explicit).to_s.strip == NONE
|
|
117
119
|
|
|
118
|
-
yield
|
|
120
|
+
yield
|
|
119
121
|
end
|
|
120
122
|
|
|
123
|
+
# The explicit setting, else one derived from the application secret.
|
|
124
|
+
def explicit_or_derived(explicit) = explicit_or(explicit) { yield secret if secret }
|
|
125
|
+
|
|
121
126
|
def setting(name)
|
|
122
127
|
_, default, kind = SETTINGS.fetch(name)
|
|
123
128
|
value = raw(name)
|
data/lib/cabby/rails/version.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module Cabby
|
|
2
2
|
module Rails
|
|
3
|
-
VERSION = "0.5.
|
|
3
|
+
VERSION = "0.5.2".freeze
|
|
4
4
|
# The Cabby server this release was tested with: what bin/cabby installs unless it pins
|
|
5
5
|
# another, and the Docker image cabby:setup suggests.
|
|
6
|
-
SERVER_VERSION = "0.
|
|
6
|
+
SERVER_VERSION = "0.6.0".freeze
|
|
7
7
|
end
|
|
8
8
|
end
|
data/lib/cabby/server_binary.rb
CHANGED
|
@@ -10,8 +10,8 @@ module Cabby
|
|
|
10
10
|
# The prebuilt Cabby server in a directory (bin/dist for bin/cabby): installed from Cabby's
|
|
11
11
|
# GitHub releases when missing or of another version than the pinned one, and verified
|
|
12
12
|
# against the release's SHA256SUMS first. A full version is downloaded from fixed addresses;
|
|
13
|
-
# a pinned "0.
|
|
14
|
-
# satisfied by any installed 0.
|
|
13
|
+
# a pinned "0.6" takes the latest 0.6.x tag of the repository (git ls-remote) and is
|
|
14
|
+
# satisfied by any installed 0.6.x. No API, so no rate limit. The Ruby standard library
|
|
15
15
|
# alone: bin/cabby loads this file, not Rails.
|
|
16
16
|
class ServerBinary
|
|
17
17
|
class Error < StandardError; end
|
|
@@ -22,6 +22,8 @@ module Cabby
|
|
|
22
22
|
PUMA_START = "CABBY_IN_PUMA=1 bin/rails server".freeze
|
|
23
23
|
GITIGNORE = "/bin/dist/\n".freeze
|
|
24
24
|
OWN_GITIGNORE = %r{^/?bin/dist/?$}
|
|
25
|
+
# The variables the app (config/cabby.yml) and the server read the same keys from, by setting.
|
|
26
|
+
KEYS = { secret: "CABBY_SECRET", turbo_streams_secret: "CABBY_TURBO_STREAMS_SECRET" }.freeze
|
|
25
27
|
# A Procfile process that runs the server.
|
|
26
28
|
PROCFILE_SERVER = /^[\w-]+:.*\bcabby\b/
|
|
27
29
|
PUMA_PLUGIN = /^\s*plugin\s+:cabby\b/
|
|
@@ -34,7 +36,7 @@ module Cabby
|
|
|
34
36
|
"Default: from the app's Procfile.dev or config/puma.rb, asked on a terminal"
|
|
35
37
|
|
|
36
38
|
def create_config
|
|
37
|
-
|
|
39
|
+
template "cabby.yml.tt", "config/cabby.yml", skip: true
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
def use_the_cabby_adapter
|
|
@@ -86,9 +88,7 @@ module Cabby
|
|
|
86
88
|
say <<~TEXT
|
|
87
89
|
Next:
|
|
88
90
|
|
|
89
|
-
1.
|
|
90
|
-
export CABBY_SECRET=$(bin/rails secret)
|
|
91
|
-
(or put it in the credentials as cabby: { secret: ... }; config/cabby.yml reads either).
|
|
91
|
+
1. #{keys_instructions.gsub("\n", "\n ")}
|
|
92
92
|
|
|
93
93
|
2. #{start_instructions.gsub("\n", "\n ")}
|
|
94
94
|
|
|
@@ -119,6 +119,18 @@ module Cabby
|
|
|
119
119
|
|
|
120
120
|
def interactive? = $stdin.tty? && $stdout.tty?
|
|
121
121
|
|
|
122
|
+
# The secret, and with Turbo a key of its own for Turbo Streams names: with the secret's, a
|
|
123
|
+
# Turbo Streams name would also be a $pubsub signed name, and the server warns at startup.
|
|
124
|
+
def shared_keys = turbo_loaded? ? KEYS : KEYS.slice(:secret)
|
|
125
|
+
|
|
126
|
+
def keys_instructions
|
|
127
|
+
exports = shared_keys.values.map { |variable| " export #{variable}=$(bin/rails secret)" }
|
|
128
|
+
keys = shared_keys.keys.map { |key| "#{key}: ..." }.join(", ")
|
|
129
|
+
what, pronoun = shared_keys.one? ? %w[secret it] : %w[keys them]
|
|
130
|
+
["Give the app and the server the same #{what}, for example:", *exports,
|
|
131
|
+
"(or put #{pronoun} in the credentials as cabby: { #{keys} };", "config/cabby.yml reads either)."].join("\n")
|
|
132
|
+
end
|
|
133
|
+
|
|
122
134
|
def client_suggestion
|
|
123
135
|
return "The browser client @cabby/web in a module of the app" unless turbo_loaded?
|
|
124
136
|
|
|
@@ -180,12 +192,13 @@ module Cabby
|
|
|
180
192
|
end
|
|
181
193
|
end
|
|
182
194
|
|
|
183
|
-
# The server's settings this app needs in development, by flag name.
|
|
195
|
+
# The server's settings this app needs in development, by flag name. The server confirms
|
|
196
|
+
# Turbo Stream subscriptions itself, with the key the gem gives Turbo.
|
|
184
197
|
def server_settings(rpc_host)
|
|
185
|
-
settings = { rpc_host: rpc_host, secret: "
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
settings
|
|
198
|
+
settings = { rpc_host: rpc_host, secret: "$#{KEYS[:secret]}", broadcast_adapter: "http" }
|
|
199
|
+
return settings unless turbo_loaded?
|
|
200
|
+
|
|
201
|
+
settings.merge(turbo_streams: true, turbo_streams_secret: "$#{KEYS[:turbo_streams_secret]}")
|
|
189
202
|
end
|
|
190
203
|
|
|
191
204
|
# On port 8080 whatever PORT says: bin/dev gives each process a PORT, and the server reads it.
|
|
@@ -208,7 +221,7 @@ module Cabby
|
|
|
208
221
|
services:
|
|
209
222
|
web: # the app, on port 3000
|
|
210
223
|
environment:
|
|
211
|
-
|
|
224
|
+
#{shared_keys.values.map { |variable| " #{variable}: $#{variable}" }.join("\n")}
|
|
212
225
|
CABBY_BROADCAST_URL: http://cabby:8090/_broadcast
|
|
213
226
|
RAILS_DEVELOPMENT_HOSTS: web # the server calls the app as web:3000
|
|
214
227
|
cabby:
|
|
@@ -7,7 +7,7 @@ require "bundler/setup"
|
|
|
7
7
|
require "cabby/server_binary"
|
|
8
8
|
|
|
9
9
|
# The version the installed cabby-rails was tested with. To pin another, write it here:
|
|
10
|
-
# "0.
|
|
10
|
+
# "0.6.0", or "0.6" for the latest 0.6.x release.
|
|
11
11
|
version = Cabby::Rails::SERVER_VERSION
|
|
12
12
|
|
|
13
13
|
Cabby::ServerBinary.exec(File.expand_path("dist", __dir__), version, ARGV)
|
|
@@ -5,7 +5,15 @@ default: &default
|
|
|
5
5
|
# The secret the app shares with the server (cabby --secret). It never goes in this file:
|
|
6
6
|
# it comes from CABBY_SECRET or from the credentials (bin/rails credentials:edit, then
|
|
7
7
|
# cabby: { secret: ... }).
|
|
8
|
-
secret:
|
|
8
|
+
secret: <%%= ENV.fetch("CABBY_SECRET") { Rails.application.credentials.dig(:cabby, :secret) } %>
|
|
9
|
+
<% if turbo_loaded? -%>
|
|
10
|
+
|
|
11
|
+
# The key Turbo Streams names are signed with, apart from the secret (cabby
|
|
12
|
+
# --turbo_streams_secret): with the secret's, a page's Turbo Streams name would also subscribe
|
|
13
|
+
# through $pubsub, with presence on its stream. From CABBY_TURBO_STREAMS_SECRET or the
|
|
14
|
+
# credentials (cabby: { turbo_streams_secret: ... }), the same value as the server's.
|
|
15
|
+
turbo_streams_secret: <%%= ENV.fetch("CABBY_TURBO_STREAMS_SECRET") { Rails.application.credentials.dig(:cabby, :turbo_streams_secret) } %>
|
|
16
|
+
<% end -%>
|
|
9
17
|
|
|
10
18
|
# How the app sends broadcasts to the server: http, postgres, redisx, redis or nats.
|
|
11
19
|
# broadcast_adapter: http
|
data/skills/cabby-rails/SKILL.md
CHANGED
|
@@ -31,8 +31,8 @@ channels: Cabby calls the app over HTTP (`POST /_cabby/connect`, `/_cabby/comman
|
|
|
31
31
|
- A connection or channel instance lasts one call. A value a later call needs goes in
|
|
32
32
|
`state_attr_accessor`, not in an instance variable.
|
|
33
33
|
- Broadcast what the clients should receive: stream callbacks and custom coders do not run.
|
|
34
|
-
- The app and the server get the same secret (`CABBY_SECRET`)
|
|
35
|
-
`config/cabby.yml` itself.
|
|
34
|
+
- The app and the server get the same secret (`CABBY_SECRET`) and, with Turbo, the same key for
|
|
35
|
+
Turbo Streams names (`CABBY_TURBO_STREAMS_SECRET`). Neither goes in `config/cabby.yml` itself.
|
|
36
36
|
- Server settings are flags on the `cabby` command (or their `CABBY_*` variables);
|
|
37
37
|
`bin/cabby --help` lists them all. App settings are in `config/cabby.yml`.
|
|
38
38
|
- After a change, run the check in [references/check.md](references/check.md).
|
|
@@ -13,7 +13,7 @@ class ChatChannel < ApplicationCable::Channel
|
|
|
13
13
|
|
|
14
14
|
def subscribed
|
|
15
15
|
self.room = params[:room]
|
|
16
|
-
stream_from "chat_#{room}", whisper: true #
|
|
16
|
+
stream_from "chat_#{room}", whisper: true # takes whispers, and sends them to the others
|
|
17
17
|
join_presence # on the first stream this call started
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -118,10 +118,14 @@ kept per server node.
|
|
|
118
118
|
{"command":"whisper","identifier":"{\"channel\":\"ChatChannel\",\"room\":\"lobby\"}","data":{"typing":true}}
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
(`subscription.whisper({ typing: true })` in `@cabby/web`) and the
|
|
122
|
-
receive `"message":{"typing":true}`. Cabby does not call the app for a
|
|
123
|
-
back to its sender, and works with or without a broker.
|
|
121
|
+
(`subscription.whisper({ typing: true })` in `@cabby/web`) and the other subscriptions that take
|
|
122
|
+
whispers on that stream receive `"message":{"typing":true}`. Cabby does not call the app for a
|
|
123
|
+
whisper, does not send it back to its sender, and works with or without a broker.
|
|
124
124
|
|
|
125
125
|
- One whisper stream per subscription: the last `whisper: true` wins, and stopping that stream
|
|
126
126
|
stops the whispers.
|
|
127
|
-
- Without `whisper: true`, Cabby drops the subscription's whispers
|
|
127
|
+
- Without `whisper: true`, Cabby drops the subscription's whispers, and the subscription receives
|
|
128
|
+
none: a channel streaming from the stream without it, or a Turbo Streams subscription to the
|
|
129
|
+
same stream, gets no whispers (Cabby 0.6 and later; 0.5 sent them to every subscriber).
|
|
130
|
+
- While 0.5 and 0.6 servers run side by side during an upgrade, start the 0.6 ones with
|
|
131
|
+
`--whisper_compat_0_5`, and remove it once the last 0.5 server is gone.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Check that it works (development)
|
|
2
2
|
|
|
3
|
-
Run from the app's root, in one shell, with the
|
|
4
|
-
`bin/rails runner` must all see the same `CABBY_SECRET
|
|
3
|
+
Run from the app's root, in one shell, with the keys exported there: the app, the server and
|
|
4
|
+
`bin/rails runner` must all see the same `CABBY_SECRET` (and, with Turbo,
|
|
5
|
+
`CABBY_TURBO_STREAMS_SECRET`).
|
|
5
6
|
|
|
6
7
|
## 1. The server
|
|
7
8
|
|
|
@@ -15,6 +16,7 @@ With `plugin :cabby` (`--development=puma`), in the background, output to a file
|
|
|
15
16
|
|
|
16
17
|
```sh
|
|
17
18
|
export CABBY_SECRET=... # the app's secret
|
|
19
|
+
export CABBY_TURBO_STREAMS_SECRET=... # with Turbo: the app's Turbo Streams key
|
|
18
20
|
CABBY_IN_PUMA=1 bin/rails server > tmp/cabby-check.log 2>&1 &
|
|
19
21
|
until curl -s -o /dev/null http://localhost:8080/health; do sleep 0.5; done
|
|
20
22
|
curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8080/health # 200
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# Deploying
|
|
2
2
|
|
|
3
3
|
Two processes: the app, and the Cabby server next to it. `bin/cabby` and `plugin :cabby` are for
|
|
4
|
-
development; in production run the Docker image `ghcr.io/danig2k/cabby:0.
|
|
4
|
+
development; in production run the Docker image `ghcr.io/danig2k/cabby:0.6.0` (the version
|
|
5
5
|
`Cabby::Rails::SERVER_VERSION` names) or an installed `cabby`.
|
|
6
6
|
|
|
7
7
|
| | What to set |
|
|
8
8
|
|---|---|
|
|
9
|
-
| Secret | The same `CABBY_SECRET` in the app and the server |
|
|
9
|
+
| Secret | The same `CABBY_SECRET` in the app and the server; with Turbo, the same `CABBY_TURBO_STREAMS_SECRET` too |
|
|
10
10
|
| RPC | The server's `--rpc_host` (`CABBY_RPC_HOST`): `<the app's URL>/_cabby`, reachable from the server |
|
|
11
11
|
| WebSocket URL | The app's `url` setting or `CABBY_URL`: `wss://<Cabby's public host>/cable` |
|
|
12
12
|
| Broadcasts | The server's `--broadcast_adapter` matching the app's `broadcast_adapter`; with HTTP, `--http_broadcast_port` keeps them off the public port, and the app's `broadcast_url` points at it |
|
|
13
|
-
| Turbo | `--turbo_streams` (`CABBY_TURBO_STREAMS: true`) when the app uses Turbo |
|
|
13
|
+
| Turbo | `--turbo_streams` (`CABBY_TURBO_STREAMS: true`) when the app uses Turbo, with `CABBY_TURBO_STREAMS_SECRET` |
|
|
14
14
|
| Origins | `--allowed_origins` (`CABBY_ALLOWED_ORIGINS`): the hosts of the pages that connect |
|
|
15
15
|
| History, presence | `--broker` when clients should catch up after a reconnect, or for presence |
|
|
16
16
|
| Health check | `GET /health` on the server's port: `200` |
|
|
@@ -25,12 +25,13 @@ Outside development and test, the app refuses every RPC call when it has no secr
|
|
|
25
25
|
service: myapp
|
|
26
26
|
|
|
27
27
|
env:
|
|
28
|
-
secret:
|
|
29
|
-
- CABBY_SECRET
|
|
28
|
+
secret: # the app's containers
|
|
29
|
+
- CABBY_SECRET
|
|
30
|
+
- CABBY_TURBO_STREAMS_SECRET # with Turbo
|
|
30
31
|
|
|
31
32
|
accessories:
|
|
32
33
|
cabby:
|
|
33
|
-
image: ghcr.io/danig2k/cabby:0.
|
|
34
|
+
image: ghcr.io/danig2k/cabby:0.6.0
|
|
34
35
|
host: 192.168.0.1 # a host of the web role, or one of its own
|
|
35
36
|
port: "8080:8080" # WebSocket /cable and /health; put TLS in front
|
|
36
37
|
env:
|
|
@@ -42,11 +43,13 @@ accessories:
|
|
|
42
43
|
CABBY_TURBO_STREAMS: true
|
|
43
44
|
secret:
|
|
44
45
|
- CABBY_SECRET
|
|
46
|
+
- CABBY_TURBO_STREAMS_SECRET # the same as the app's
|
|
45
47
|
```
|
|
46
48
|
|
|
47
49
|
```sh
|
|
48
50
|
# .kamal/secrets
|
|
49
51
|
CABBY_SECRET=$CABBY_SECRET
|
|
52
|
+
CABBY_TURBO_STREAMS_SECRET=$CABBY_TURBO_STREAMS_SECRET
|
|
50
53
|
```
|
|
51
54
|
|
|
52
55
|
```yaml
|
|
@@ -81,4 +84,18 @@ INF Accept broadcast requests at http://0.0.0.0:8090/_broadcast (authorization r
|
|
|
81
84
|
INF Handle WebSocket connections at http://0.0.0.0:8080/cable
|
|
82
85
|
```
|
|
83
86
|
|
|
87
|
+
## From Cabby 0.5 to 0.6
|
|
88
|
+
|
|
89
|
+
| If the app | Then |
|
|
90
|
+
|---|---|
|
|
91
|
+
| Reads whispers in a channel that streams from the stream without `whisper: true` | Add `whisper: true` there ([channels.md](channels.md#whispers)) |
|
|
92
|
+
| Runs 0.5 and 0.6 servers side by side while upgrading | `--whisper_compat_0_5` on the 0.6 servers until the last 0.5 one is gone |
|
|
93
|
+
| Signs Turbo Streams names with the secret | `CABBY_TURBO_STREAMS_SECRET` for the app and the server ([frontend.md](frontend.md#turbo-streams)) |
|
|
94
|
+
| Relies on a proxy's `X-Request-ID` being the session id | `--request_id_as_session_id`: the server now generates every session id |
|
|
95
|
+
| Connects Cabby to Redis over TLS with a self-signed or private CA certificate | `--redis_tls_ca_cert_path`, or `--redis_tls_verify=false` |
|
|
96
|
+
| Has SSE, Durable Streams or Pusher clients that fall more than 1 MiB behind | A larger `--ws_max_pending_size`, or they are disconnected as slow |
|
|
97
|
+
| Limits NATS reconnects in a server configuration file (`[nats]`) | Remove the limit: the server keeps reconnecting by default, and with one it exits once the attempts run out |
|
|
98
|
+
|
|
99
|
+
All of it: <https://docs.cabbyhq.com/upgrading-to-0-6>.
|
|
100
|
+
|
|
84
101
|
More hosts (Docker Compose, Fly.io, proxies, open file limits): <https://docs.cabbyhq.com/deploy>.
|
|
@@ -10,6 +10,20 @@ with (`turbo_streams_secret`, else `streams_secret`, else `secret`). Run the ser
|
|
|
10
10
|
`--turbo_streams` (the generator adds it when Turbo is loaded) and Cabby confirms Turbo
|
|
11
11
|
subscriptions itself, with no call to the app.
|
|
12
12
|
|
|
13
|
+
Turbo gets a key of its own: the same `CABBY_TURBO_STREAMS_SECRET` for the app (the gem reads
|
|
14
|
+
it, and `config/cabby.yml` from `cabby:setup` names it) and the server (it reads it too;
|
|
15
|
+
`cabby:setup` also passes `--turbo_streams_secret=$CABBY_TURBO_STREAMS_SECRET`). With the
|
|
16
|
+
secret's key a Turbo Streams name is also a `$pubsub` signed name, which gives its viewer the
|
|
17
|
+
stream's presence, and the server logs at startup:
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
WRN Turbo Streams signed names are also accepted by $pubsub (the same key verifies them), where they give presence on their stream; set --turbo_streams_secret to a key of its own
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
An app set up before cabby-rails 0.5.2 has no such key and keeps working; to switch, give the app
|
|
24
|
+
and the server the same new `CABBY_TURBO_STREAMS_SECRET` where they get `CABBY_SECRET`. Pages
|
|
25
|
+
rendered before the switch subscribe again once reloaded.
|
|
26
|
+
|
|
13
27
|
| The app | Then |
|
|
14
28
|
|---|---|
|
|
15
29
|
| Sets `config.turbo.signed_stream_verifier_key` itself | The gem keeps it: give the server that key with `--turbo_streams_secret`, or run it without `--turbo_streams` |
|
|
@@ -13,7 +13,7 @@ Running it again changes nothing (each file reports `identical`).
|
|
|
13
13
|
|
|
14
14
|
| File | Change |
|
|
15
15
|
|---|---|
|
|
16
|
-
| `config/cabby.yml` | Created; an existing one is kept |
|
|
16
|
+
| `config/cabby.yml` | Created (with Turbo, `turbo_streams_secret` too); an existing one is kept |
|
|
17
17
|
| `config/cable.yml` | `adapter: cabby` for development and production; the replaced adapter's settings commented out under a note; `test` left alone. Created when missing (`test: adapter: test`) |
|
|
18
18
|
| `config/routes.rb` | `mount Cabby::Rails::RPC => "/_cabby"` |
|
|
19
19
|
| `config/importmap.rb` | `pin "@cabby/web", to: "cabby-web.min.js"`. Without import maps it prints the `npm install` command instead ([frontend.md](frontend.md)) |
|
|
@@ -21,7 +21,7 @@ Running it again changes nothing (each file reports `identical`).
|
|
|
21
21
|
| `Procfile.dev` | With `bin`: a `cabby:` line (the file is created with `web: bin/rails server` when missing) |
|
|
22
22
|
| `config/puma.rb` | With `puma`: the plugin block below, before Solid Queue's plugin |
|
|
23
23
|
|
|
24
|
-
It ends with what is left to do: the
|
|
24
|
+
It ends with what is left to do: the keys, and how to start the server. It then points to
|
|
25
25
|
`bin/rails g cabby:client`, which sets up the browser client and runs `turbo_stream_from` on it
|
|
26
26
|
([frontend.md](frontend.md)).
|
|
27
27
|
|
|
@@ -37,10 +37,11 @@ It ends with what is left to do: the secret, and how to start the server. It the
|
|
|
37
37
|
On a terminal it asks; without one (a script, an agent's shell) it takes the default. Pass the
|
|
38
38
|
option to choose.
|
|
39
39
|
|
|
40
|
-
The command it writes, with `--turbo_streams` only when Turbo is
|
|
40
|
+
The command it writes, with `--turbo_streams` and `--turbo_streams_secret` only when Turbo is
|
|
41
|
+
loaded:
|
|
41
42
|
|
|
42
43
|
```sh
|
|
43
|
-
bin/cabby --rpc_host=http://localhost:3000/_cabby --secret=$CABBY_SECRET --broadcast_adapter=http --turbo_streams --port=8080
|
|
44
|
+
bin/cabby --rpc_host=http://localhost:3000/_cabby --secret=$CABBY_SECRET --broadcast_adapter=http --turbo_streams --turbo_streams_secret=$CABBY_TURBO_STREAMS_SECRET --port=8080
|
|
44
45
|
```
|
|
45
46
|
|
|
46
47
|
- `--port=8080`: the server also reads `PORT`, which `bin/dev` sets for each process.
|
|
@@ -54,8 +55,8 @@ Runs the server with every argument it gets. The first run downloads the server
|
|
|
54
55
|
gem was tested with (`Cabby::Rails::SERVER_VERSION`) into `bin/dist/`, checked against the
|
|
55
56
|
release's `SHA256SUMS`; later runs start offline.
|
|
56
57
|
|
|
57
|
-
- Another version: edit the `version = ...` line in `bin/cabby`: a full version (`"0.
|
|
58
|
-
`"0.
|
|
58
|
+
- Another version: edit the `version = ...` line in `bin/cabby`: a full version (`"0.6.0"`), or
|
|
59
|
+
`"0.6"` for the latest 0.6.x (listed with `git ls-remote`).
|
|
59
60
|
- `CABBY_RELEASES_URL`: a mirror serving the same `releases/download/v<version>/<file>` paths.
|
|
60
61
|
- Prebuilt servers: Linux x86_64 and arm64 (glibc), macOS on Apple silicon. Elsewhere it stops
|
|
61
62
|
with a message pointing at <https://docs.cabbyhq.com/install>; run `cabby` instead.
|
|
@@ -70,7 +71,7 @@ What `--development=puma` adds to `config/puma.rb`:
|
|
|
70
71
|
# Run the Cabby server with Puma in development: CABBY_IN_PUMA=1 bin/rails server
|
|
71
72
|
if ENV["CABBY_IN_PUMA"]
|
|
72
73
|
plugin :cabby
|
|
73
|
-
cabby_command "bin/cabby --rpc_host=http://localhost:3000/_cabby --secret=$CABBY_SECRET --broadcast_adapter=http --turbo_streams --port=8080"
|
|
74
|
+
cabby_command "bin/cabby --rpc_host=http://localhost:3000/_cabby --secret=$CABBY_SECRET --broadcast_adapter=http --turbo_streams --turbo_streams_secret=$CABBY_TURBO_STREAMS_SECRET --port=8080"
|
|
74
75
|
end
|
|
75
76
|
```
|
|
76
77
|
|
|
@@ -88,22 +89,26 @@ initializer over both. A key the gem does not know stops the boot with
|
|
|
88
89
|
`Cabby::ConfigurationError`. Every setting, its variable and its default: the README's
|
|
89
90
|
"Configuration" section.
|
|
90
91
|
|
|
91
|
-
The generated file reads the secret
|
|
92
|
+
The generated file reads the secret, and with Turbo the key for Turbo Streams names, from the
|
|
93
|
+
environment or the credentials, never a literal:
|
|
92
94
|
|
|
93
95
|
```yaml
|
|
94
96
|
default: &default
|
|
95
97
|
secret: <%= ENV.fetch("CABBY_SECRET") { Rails.application.credentials.dig(:cabby, :secret) } %>
|
|
98
|
+
turbo_streams_secret: <%= ENV.fetch("CABBY_TURBO_STREAMS_SECRET") { Rails.application.credentials.dig(:cabby, :turbo_streams_secret) } %>
|
|
96
99
|
```
|
|
97
100
|
|
|
98
101
|
```sh
|
|
99
|
-
export CABBY_SECRET=$(bin/rails secret)
|
|
102
|
+
export CABBY_SECRET=$(bin/rails secret) # once; the same value for the app and the server
|
|
103
|
+
export CABBY_TURBO_STREAMS_SECRET=$(bin/rails secret) # with Turbo; another value, shared the same way
|
|
100
104
|
```
|
|
101
105
|
|
|
102
106
|
`bin/rails secret` prints a new value each time: generate it once and give that value to every
|
|
103
107
|
process (the app, `bin/rails runner`, the server). From the one secret the gem and the server
|
|
104
108
|
derive the RPC bearer (`http_rpc_secret`), the broadcast key (`broadcast_key`), the key for
|
|
105
109
|
signed stream names (`streams_secret`) and the key for tokens (`jwt_secret`); set those only to
|
|
106
|
-
give them values of their own.
|
|
110
|
+
give them values of their own. `secret: none` counts as unset; `none` for one of the others
|
|
111
|
+
turns that key off, with no fallback to the secret.
|
|
107
112
|
|
|
108
113
|
Without a secret the `/_cabby` endpoint answers only in development and test; elsewhere it
|
|
109
114
|
refuses every call and logs why ([troubleshooting.md](troubleshooting.md)).
|
|
@@ -70,7 +70,8 @@ DBG subscription failed ... error="verification failed"
|
|
|
70
70
|
|
|
71
71
|
The name was signed with another key than the server's. For a signed stream: the app's
|
|
72
72
|
`streams_secret` / `secret` and the server's `--streams_secret` / `--secret` differ. For Turbo
|
|
73
|
-
with `--turbo_streams`:
|
|
73
|
+
with `--turbo_streams`: the app and the server see different `CABBY_TURBO_STREAMS_SECRET` values
|
|
74
|
+
(or only one of them has it), or see the key table in [frontend.md](frontend.md).
|
|
74
75
|
|
|
75
76
|
### No confirmation and no rejection
|
|
76
77
|
|
|
@@ -168,7 +169,8 @@ broadcasts are not affected.
|
|
|
168
169
|
## Presence and whispers
|
|
169
170
|
|
|
170
171
|
- No presence events: the server needs a broker ([channels.md](channels.md)).
|
|
171
|
-
- Whispers do not reach the others: the subscription has no `whisper: true` stream
|
|
172
|
+
- Whispers do not reach the others: the sending subscription has no `whisper: true` stream, or
|
|
173
|
+
the receiving one does not take whispers on that stream (it needs `whisper: true` too).
|
|
172
174
|
|
|
173
175
|
```cabby-log
|
|
174
176
|
DBG whisper stream not found
|
|
@@ -185,3 +187,5 @@ broadcasts are not affected.
|
|
|
185
187
|
| `bin/cabby` | `bin/cabby: there is no prebuilt Cabby server for ...` | Install the server another way and run `cabby` |
|
|
186
188
|
| `bin/cabby` | `bin/cabby: could not download ...` | The first run needs the network (or the mirror in `CABBY_RELEASES_URL`) |
|
|
187
189
|
| Server | `ERR failed to connect to Redis` | The command lacks `--broadcast_adapter=http`, so the server also reads Redis |
|
|
190
|
+
| Server | `ERR failed to connect to Redis ... error="invalid peer certificate: ..."` | Cabby checks the certificate of a `rediss://` server: give its CA with `--redis_tls_ca_cert_path`, or `--redis_tls_verify=false` |
|
|
191
|
+
| Server | `WRN Turbo Streams signed names are also accepted by $pubsub ...` | Turbo Streams names are signed with the secret: give Turbo a key of its own ([frontend.md](frontend.md)) |
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cabby-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniele Pestilli
|
|
@@ -158,7 +158,7 @@ files:
|
|
|
158
158
|
- lib/generators/cabby/helpers.rb
|
|
159
159
|
- lib/generators/cabby/setup/setup_generator.rb
|
|
160
160
|
- lib/generators/cabby/setup/templates/bin/cabby
|
|
161
|
-
- lib/generators/cabby/setup/templates/cabby.yml
|
|
161
|
+
- lib/generators/cabby/setup/templates/cabby.yml.tt
|
|
162
162
|
- lib/generators/cabby/setup/templates/cable.yml
|
|
163
163
|
- lib/puma/plugin/cabby.rb
|
|
164
164
|
- skills/cabby-rails/SKILL.md
|