anycable-rails-core 1.6.1 → 1.6.3
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 +21 -0
- data/MIT-LICENSE +1 -1
- data/README.md +12 -0
- data/lib/anycable/rails/channel/presence.rb +1 -1
- data/lib/anycable/rails/compatibility.rb +1 -0
- data/lib/anycable/rails/version.rb +1 -1
- data/lib/generators/anycable/bin/USAGE +3 -1
- data/lib/generators/anycable/bin/bin_generator.rb +7 -6
- data/lib/generators/anycable/bin/templates/bin/anycable-go.tt +4 -3
- data/lib/generators/anycable/download/download_generator.rb +2 -11
- data/lib/generators/anycable/setup/USAGE +8 -0
- data/lib/generators/anycable/setup/setup_generator.rb +114 -86
- data/lib/generators/anycable/setup/templates/Procfile.dev.tt +1 -1
- data/lib/generators/anycable/setup/templates/bin/dev +0 -3
- data/lib/generators/anycable/with_release_helpers.rb +69 -0
- data/lib/puma/plugin/anycable.rb +171 -0
- data/skills/anycable-rails/SKILL.md +82 -0
- data/skills/anycable-rails/references/deployment.md +187 -0
- data/skills/anycable-rails/references/hotwire.md +269 -0
- data/skills/anycable-rails/references/installation.md +292 -0
- data/skills/anycable-rails/references/live-checks.md +129 -0
- data/skills/anycable-rails/references/personalization.md +114 -0
- data/skills/anycable-rails/references/presence.md +240 -0
- data/skills/anycable-rails/references/realtime-features.md +231 -0
- data/skills/anycable-rails/references/testing.md +145 -0
- data/skills/anycable-rails/references/troubleshooting.md +128 -0
- data/skills/anycable-rails/scenarios/channel.yml +51 -0
- data/skills/anycable-rails/scenarios/signed-stream.yml +38 -0
- metadata +19 -3
- data/lib/generators/anycable/setup/templates/bin/anycable-go.tt +0 -27
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b2e99737d795373a6efe6acdd6340a8208521a1a6d1a1c13b52b8407ebdaf62b
|
|
4
|
+
data.tar.gz: 43f00dc736d3d0f794f9161e4bcf2c4c129c372c6042622f0625bb744fd45114
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1eead9eb29039b654158e54024cc1edea844cc20c88ebe836a2118f3e2d8a45883328cf2e5c4125fb5c7c3222b2aa115b58d4cdf93a3def8375ff61f4ebf8df7
|
|
7
|
+
data.tar.gz: 45737a8fb57db5537c123351ab0906d37b7d658823e24566af03f6561b73e72ae1a8c68df7e7e306af9fd7b11096c4512e31d9dfb0f6ae587406872acb2f3a2e
|
data/CHANGELOG.md
CHANGED
|
@@ -2,8 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
## main
|
|
4
4
|
|
|
5
|
+
## 1.6.3 (2026-11-29)
|
|
6
|
+
|
|
7
|
+
- Fix and improve generators. ([@palkan][])
|
|
8
|
+
|
|
9
|
+
- Add Puma plugin to run AnyCable server in development. ([@palkan][])
|
|
10
|
+
|
|
11
|
+
Add `plugin :anycable if ENV["ANYCABLE_IN_PUMA"]` to `config/puma.rb`. The plugin starts `bin/anycable-go` after Puma boots, keeps it running during Puma restarts, and stops it with Puma. Use `anycable_command`, `anycable_log` and `anycable_pidfile` to change the defaults.
|
|
12
|
+
|
|
13
|
+
- Add an agent skill (`skills/anycable-rails`) for coding agents. ([@palkan][])
|
|
14
|
+
|
|
15
|
+
The skill covers installation and configuration, deployment, troubleshooting (with `wsdirector` scenarios for live checks), and best practices for real-time features. It is shipped with `anycable-rails-core` and installed by [Rails Hyperdrive](https://github.com/rails-hyperdrive/rails-hyperdrive).
|
|
16
|
+
|
|
17
|
+
- Cast the presence ID to a string on leave, matching join. ([@ashwin47][])
|
|
18
|
+
|
|
19
|
+
`#join_presence` already casts the ID via `#to_s`, but `#leave_presence` passed it through untouched, so a non-string `user_presence_id` (e.g. a numeric record id) raised `Invalid argument for string field 'id'` when building the presence response.
|
|
20
|
+
|
|
21
|
+
## 1.6.2 (2026-04-02)
|
|
22
|
+
|
|
5
23
|
- Upgrade setup generator. ([@palkan][])
|
|
6
24
|
|
|
25
|
+
## 1.6.1 (2025-12-18)
|
|
26
|
+
|
|
7
27
|
- Ensure `bin/dist/anycable-go` has execution permission as part of `bin/anycable-go` ([@dmorgan-fa][])
|
|
8
28
|
|
|
9
29
|
## 1.6.0 (2025-03-18)
|
|
@@ -302,3 +322,4 @@ See [Changelog](https://github.com/anycable/anycable-rails/blob/0-6-stable/CHANG
|
|
|
302
322
|
[@sponomarev]: https://github.com/sponomarev
|
|
303
323
|
[@bibendi]: https://github.com/bibendi
|
|
304
324
|
[@lHydra]: http://github.com/lHydra
|
|
325
|
+
[@ashwin47]: https://github.com/ashwin47
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -28,6 +28,18 @@ bundle exec rails g anycable:setup
|
|
|
28
28
|
|
|
29
29
|
Learn more [here](https://docs.anycable.io/rails/getting_started).
|
|
30
30
|
|
|
31
|
+
## Agent skills
|
|
32
|
+
|
|
33
|
+
The gem ships a skill for coding agents in `skills/anycable-rails`. The skill helps agents install and configure AnyCable, troubleshoot connections and broadcasts, and build real-time features. It follows the [skills.sh](https://www.skills.sh) layout, so it works with any agent that reads `SKILL.md`.
|
|
34
|
+
|
|
35
|
+
With [Rails Hyperdrive](https://github.com/rails-hyperdrive/rails-hyperdrive), the skill installs automatically: run `bin/rails hyperdrive:init` the first time, then `bundle install` or `bin/rails hyperdrive:sync` puts it into `.claude/skills/anycable-rails`.
|
|
36
|
+
|
|
37
|
+
Without Rails Hyperdrive, install it from the repository with the [skills.sh](https://www.skills.sh) CLI, or copy `skills/anycable-rails` into your agent's skills directory:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npx skills add anycable/anycable-rails
|
|
41
|
+
```
|
|
42
|
+
|
|
31
43
|
## Contributing
|
|
32
44
|
|
|
33
45
|
Bug reports and pull requests are welcome on GitHub at [https://github.com/anycable/anycable-rails](https://github.com/anycable/anycable-rails).
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "generators/anycable/
|
|
3
|
+
require "generators/anycable/with_release_helpers"
|
|
4
4
|
|
|
5
5
|
module AnyCableRailsGenerators
|
|
6
6
|
# Generates bin/anycable-go binstub
|
|
7
7
|
class BinGenerator < ::Rails::Generators::Base
|
|
8
8
|
namespace "anycable:bin"
|
|
9
9
|
|
|
10
|
+
include WithReleaseHelpers
|
|
11
|
+
|
|
10
12
|
source_root File.expand_path("templates", __dir__)
|
|
11
13
|
|
|
12
14
|
class_option :version,
|
|
13
15
|
type: :string,
|
|
14
16
|
desc: "Specify AnyCable server version (defaults to latest release)",
|
|
15
|
-
|
|
17
|
+
default: "latest"
|
|
16
18
|
|
|
17
19
|
def generate_bin
|
|
18
20
|
inside("bin") do
|
|
@@ -43,10 +45,9 @@ module AnyCableRailsGenerators
|
|
|
43
45
|
return unless version
|
|
44
46
|
return if version.chomp == "latest"
|
|
45
47
|
|
|
46
|
-
# We need a full version for bin/anycable-go script
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
segments.join(".")
|
|
48
|
+
# We need a full version for bin/anycable-go script:
|
|
49
|
+
# a partial one (e.g., "1.6") resolves to the latest patch release
|
|
50
|
+
resolve_version(version)
|
|
50
51
|
end
|
|
51
52
|
end
|
|
52
53
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
|
-
cd $(dirname $0)/..
|
|
3
|
+
cd "$(dirname "$0")/.."
|
|
4
4
|
|
|
5
5
|
# It's recommended to use the exact version of AnyCable here
|
|
6
6
|
version="<%= anycable_go_version %>"
|
|
@@ -10,7 +10,7 @@ if [ ! -f ./bin/dist/anycable-go ]; then
|
|
|
10
10
|
./bin/rails g anycable:download --version=$version --bin-path=./bin/dist
|
|
11
11
|
fi
|
|
12
12
|
|
|
13
|
-
if [ -x ./bin/dist/anycable-go ]; then
|
|
13
|
+
if [ ! -x ./bin/dist/anycable-go ]; then
|
|
14
14
|
echo "Setting execution permission for AnyCable server"
|
|
15
15
|
chmod +x ./bin/dist/anycable-go
|
|
16
16
|
fi
|
|
@@ -24,4 +24,5 @@ if [[ "$version" != "latest" ]]; then
|
|
|
24
24
|
fi
|
|
25
25
|
fi
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
# Replace the shell process, so that signals reach the server
|
|
28
|
+
exec ./bin/dist/anycable-go "$@"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "generators/anycable/with_os_helpers"
|
|
4
|
+
require "generators/anycable/with_release_helpers"
|
|
4
5
|
|
|
5
6
|
module AnyCableRailsGenerators
|
|
6
7
|
# Downloads anycable-go binary
|
|
@@ -8,6 +9,7 @@ module AnyCableRailsGenerators
|
|
|
8
9
|
namespace "anycable:download"
|
|
9
10
|
|
|
10
11
|
include WithOSHelpers
|
|
12
|
+
include WithReleaseHelpers
|
|
11
13
|
|
|
12
14
|
VERSION = "latest"
|
|
13
15
|
|
|
@@ -43,17 +45,6 @@ module AnyCableRailsGenerators
|
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
|
|
46
|
-
def repository_name(version)
|
|
47
|
-
return "anycable/anycable" if version == "latest"
|
|
48
|
-
|
|
49
|
-
major, minor, = Gem::Version.new(version).segments
|
|
50
|
-
if (major >= 1 && minor >= 6) || (major > 1)
|
|
51
|
-
"anycable/anycable"
|
|
52
|
-
else
|
|
53
|
-
"anycable/anycable-go"
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
48
|
def legacy_release_url(version)
|
|
58
49
|
"https://github.com/#{repository_name(version)}/releases/download/v#{version}/" \
|
|
59
50
|
"anycable-go-v#{version}-#{os_name}-#{cpu_name}"
|
|
@@ -3,3 +3,11 @@ Description:
|
|
|
3
3
|
|
|
4
4
|
Example:
|
|
5
5
|
rails generate anycable:setup
|
|
6
|
+
|
|
7
|
+
rails generate anycable:setup --rpc=none --development=puma --version=1.6
|
|
8
|
+
|
|
9
|
+
Development options:
|
|
10
|
+
bin — run bin/anycable-go via Procfile.dev (bin/dev)
|
|
11
|
+
puma — run bin/anycable-go via Puma plugin (ANYCABLE_IN_PUMA=1)
|
|
12
|
+
docker — print a Docker Compose snippet
|
|
13
|
+
skip — do not configure AnyCable server for development
|
|
@@ -9,7 +9,7 @@ module AnyCableRailsGenerators
|
|
|
9
9
|
source_root File.expand_path("templates", __dir__)
|
|
10
10
|
|
|
11
11
|
DOCS_ROOT = "https://docs.anycable.io"
|
|
12
|
-
DEVELOPMENT_METHODS = %w[skip
|
|
12
|
+
DEVELOPMENT_METHODS = %w[skip bin puma docker].freeze
|
|
13
13
|
DEPLOYMENT_METHODS = %w[skip thruster fly heroku anycable_plus].freeze
|
|
14
14
|
RPC_IMPL = %w[none grpc http].freeze
|
|
15
15
|
|
|
@@ -41,7 +41,7 @@ module AnyCableRailsGenerators
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
if hotwire? && !custom_channels?
|
|
44
|
-
|
|
44
|
+
say_status :info, <<~MSG
|
|
45
45
|
⚡️ Hotwire application has been detected, installing AnyCable in a standalone mode.
|
|
46
46
|
MSG
|
|
47
47
|
@rpc_impl = "none"
|
|
@@ -52,6 +52,7 @@ module AnyCableRailsGenerators
|
|
|
52
52
|
answer = RPC_IMPL.index(options[:rpc]) || 99
|
|
53
53
|
|
|
54
54
|
unless RPC_IMPL[answer.to_i]
|
|
55
|
+
say ""
|
|
55
56
|
say <<~MSG
|
|
56
57
|
AnyCable connects to your Rails server to communicate with Action Cable channels either via HTTP or gRPC.
|
|
57
58
|
|
|
@@ -68,15 +69,14 @@ module AnyCableRailsGenerators
|
|
|
68
69
|
say ""
|
|
69
70
|
end
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
answer = ask "Which RPC implementation would you like to use? (1) gRPC, (2) HTTP, (0) None"
|
|
73
|
-
end
|
|
72
|
+
answer = ask "Which RPC implementation would you like to use?", limited_to: %w[grpc http none], default: "grpc"
|
|
74
73
|
|
|
75
|
-
@rpc_impl =
|
|
74
|
+
@rpc_impl = answer
|
|
75
|
+
return
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
# no Hotwire, no custom channels
|
|
79
|
-
|
|
79
|
+
say_status :info, "Looks like you don't have any real-time functionality yet. Let's start with a miminal AnyCable setup!"
|
|
80
80
|
@rpc_impl = "none"
|
|
81
81
|
end
|
|
82
82
|
|
|
@@ -86,28 +86,30 @@ module AnyCableRailsGenerators
|
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
# Fast-track for local development
|
|
89
|
-
if file_exists?("bin/dev") && file_exists?("Procfile.dev")
|
|
90
|
-
@development = "
|
|
89
|
+
if !@development && file_exists?("bin/dev") && file_exists?("Procfile.dev")
|
|
90
|
+
@development = "bin"
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
unless @development
|
|
94
|
+
say ""
|
|
94
95
|
say <<~MSG
|
|
95
96
|
You can run AnyCable server locally (recommended for most cases) or as a Docker container (in case you develop in a containerized environment).
|
|
96
97
|
|
|
97
98
|
For a local installation, we provide a convenient binstub (`bin/anycable-go`) which automatically
|
|
98
|
-
installs AnyCable server for the current platform.
|
|
99
|
+
installs AnyCable server for the current platform. You can run it:
|
|
100
|
+
- via Procfile.dev (bin) — together with other processes using foreman or overmind;
|
|
101
|
+
- via Puma plugin (puma) — AnyCable server starts and stops with your Rails server.
|
|
99
102
|
MSG
|
|
100
103
|
say ""
|
|
101
104
|
|
|
102
|
-
answer =
|
|
105
|
+
answer = ask "Which way to run AnyCable server locally would you prefer?", limited_to: %w[bin puma docker skip], default: default_development_method
|
|
103
106
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
Which way to run AnyCable server locally would you prefer? (1) Binstub, (2) Docker, (0) Skip
|
|
107
|
-
MSG
|
|
108
|
-
end
|
|
107
|
+
@development = answer
|
|
108
|
+
end
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
if @development == "puma" && grpc?
|
|
111
|
+
say_status :warn, "Puma plugin doesn't run the gRPC server. Using Procfile.dev instead", :yellow
|
|
112
|
+
@development = "bin"
|
|
111
113
|
end
|
|
112
114
|
|
|
113
115
|
case @development
|
|
@@ -132,10 +134,10 @@ module AnyCableRailsGenerators
|
|
|
132
134
|
return unless rubocop?
|
|
133
135
|
|
|
134
136
|
say_status :info, "🤖 Running static compatibility checks with RuboCop"
|
|
135
|
-
res = run "bundle exec rubocop -r 'anycable/rails/compatibility/rubocop' --only AnyCable/InstanceVars,AnyCable/PeriodicalTimers,AnyCable/
|
|
137
|
+
res = run "bundle exec rubocop -r 'anycable/rails/compatibility/rubocop' --only AnyCable/InstanceVars,AnyCable/PeriodicalTimers,AnyCable/StreamFrom"
|
|
136
138
|
|
|
137
139
|
unless res
|
|
138
|
-
say_status :help, "⚠️ Please, take a look at the
|
|
140
|
+
say_status :help, "⚠️ Please, take a look at the incompatibilities above and fix them"
|
|
139
141
|
|
|
140
142
|
@todos << "Fix Action Cable compatibility issues (listed above): #{DOCS_ROOT}/rails/compatibility"
|
|
141
143
|
end
|
|
@@ -205,6 +207,10 @@ module AnyCableRailsGenerators
|
|
|
205
207
|
// Prevent frequent resubscriptions during morphing or navigation
|
|
206
208
|
start(cable, { delayedUnsubscribe: true })
|
|
207
209
|
JS
|
|
210
|
+
|
|
211
|
+
@todos << "⚠️ `@hotwired/turbo-rails` has been replaced with `@hotwired/turbo` in app/javascript/application.js.\n" \
|
|
212
|
+
" Links and forms with `data-turbo-method` (e.g., `delete`) now send real PATCH/PUT/DELETE requests (no `_method` param),\n" \
|
|
213
|
+
" and a 302 redirect after them is followed with the same method. Make sure these actions redirect with `status: :see_other`"
|
|
208
214
|
return
|
|
209
215
|
end
|
|
210
216
|
|
|
@@ -243,6 +249,13 @@ module AnyCableRailsGenerators
|
|
|
243
249
|
|
|
244
250
|
private
|
|
245
251
|
|
|
252
|
+
def default_development_method
|
|
253
|
+
return "bin" if grpc? || file_exists?("Procfile.dev")
|
|
254
|
+
return "puma" if file_exists?("config/puma.rb")
|
|
255
|
+
|
|
256
|
+
"bin"
|
|
257
|
+
end
|
|
258
|
+
|
|
246
259
|
def redis?
|
|
247
260
|
!!gemfile_lock&.match?(/^\s+redis\b/)
|
|
248
261
|
end
|
|
@@ -329,80 +342,91 @@ module AnyCableRailsGenerators
|
|
|
329
342
|
|
|
330
343
|
say "Here is an example snippet for Docker Compose:"
|
|
331
344
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
345
|
+
# The server reads settings from the anycable.toml file (mounted into the container);
|
|
346
|
+
# environment variables override the values that are different in Docker
|
|
347
|
+
ws_environment = ["ANYCABLE_HOST: \"0.0.0.0\""]
|
|
348
|
+
ws_environment << "ANYCABLE_RPC_HOST: http://rails:3000/_anycable" if http_rpc?
|
|
349
|
+
ws_environment << "ANYCABLE_RPC_HOST: anycable:50051" if grpc?
|
|
350
|
+
|
|
351
|
+
snippet = <<~YML
|
|
352
|
+
# Your Rails application service
|
|
353
|
+
rails: &rails
|
|
354
|
+
# ...
|
|
355
|
+
ports:
|
|
356
|
+
- '3000:3000'
|
|
357
|
+
environment: &rails_environment
|
|
337
358
|
# ...
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
ANYCABLE_RPC_HOST: anycable:50051
|
|
357
|
-
ANYCABLE_DEBUG: ${ANYCABLE_DEBUG:-true}
|
|
358
|
-
ANYCABLE_SECRET: "anycable-local-secret"
|
|
359
|
+
ANYCABLE_HTTP_BROADCAST_URL: http://ws:8080/_broadcast
|
|
360
|
+
depends_on: &rails_depends_on
|
|
361
|
+
# ...
|
|
362
|
+
ws:
|
|
363
|
+
condition: service_started
|
|
364
|
+
|
|
365
|
+
ws:
|
|
366
|
+
image: anycable/anycable-go:1.6
|
|
367
|
+
ports:
|
|
368
|
+
- '8080:8080'
|
|
369
|
+
volumes:
|
|
370
|
+
- ./anycable.toml:/etc/anycable/anycable.toml:ro
|
|
371
|
+
environment:
|
|
372
|
+
#{ws_environment.join("\n ")}
|
|
373
|
+
YML
|
|
374
|
+
|
|
375
|
+
if grpc?
|
|
376
|
+
snippet += <<~YML
|
|
359
377
|
|
|
360
378
|
anycable:
|
|
361
379
|
<<: *rails
|
|
362
380
|
command: bundle exec anycable
|
|
381
|
+
ports:
|
|
382
|
+
- '50051'
|
|
363
383
|
environment:
|
|
364
384
|
<<: *rails_environment
|
|
365
385
|
ANYCABLE_RPC_HOST: 0.0.0.0:50051
|
|
366
|
-
ports:
|
|
367
|
-
- '50051'
|
|
368
386
|
depends_on:
|
|
369
387
|
<<: *rails_depends_on
|
|
370
|
-
ws:
|
|
371
|
-
condition: service_started
|
|
372
|
-
─────────────────────────────────────────
|
|
373
|
-
YML
|
|
374
|
-
else
|
|
375
|
-
say <<~YML
|
|
376
|
-
─────────────────────────────────────────
|
|
377
|
-
# Your Rails application service
|
|
378
|
-
rails: &rails
|
|
379
|
-
# ...
|
|
380
|
-
ports:
|
|
381
|
-
- '3000:3000'
|
|
382
|
-
environment: &rails_environment
|
|
383
|
-
# ...
|
|
384
|
-
ANYCABLE_HTTP_BROADCAST_URL: http://ws:8090/_broadcast
|
|
385
|
-
depends_on: &rails_depends_on
|
|
386
|
-
#...
|
|
387
|
-
anycable:
|
|
388
|
-
condition: service_started
|
|
389
|
-
|
|
390
|
-
ws:
|
|
391
|
-
image: anycable/anycable-go:1.5
|
|
392
|
-
ports:
|
|
393
|
-
- '8080:8080'
|
|
394
|
-
environment:
|
|
395
|
-
ANYCABLE_HOST: "0.0.0.0"
|
|
396
|
-
ANYCABLE_BROADCAST_ADAPTER: http
|
|
397
|
-
ANYCABLE_RPC_HOST: http://rails:3000/_anycable
|
|
398
|
-
ANYCABLE_DEBUG: ${ANYCABLE_DEBUG:-true}
|
|
399
|
-
ANYCABLE_SECRET: "anycable-local-secret"
|
|
400
|
-
─────────────────────────────────────────
|
|
401
388
|
YML
|
|
402
389
|
end
|
|
390
|
+
|
|
391
|
+
say "─────────────────────────────────────────"
|
|
392
|
+
say snippet
|
|
393
|
+
say "─────────────────────────────────────────"
|
|
394
|
+
|
|
395
|
+
@todos << "Add the AnyCable services to your Docker Compose file (see the snippet above)"
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
def install_for_puma
|
|
399
|
+
unless file_exists?("bin/anycable-go")
|
|
400
|
+
generate "anycable:bin", "--version #{options[:version]}"
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
unless file_exists?("config/puma.rb")
|
|
404
|
+
@todos << "⚠️ Add `plugin :anycable if ENV[\"ANYCABLE_IN_PUMA\"]` to your Puma configuration file"
|
|
405
|
+
return
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
in_root do
|
|
409
|
+
contents = File.read("config/puma.rb")
|
|
410
|
+
next if contents.match?(/^\s*plugin\s+:anycable\b/)
|
|
411
|
+
|
|
412
|
+
plugin = <<~RUBY
|
|
413
|
+
# Run AnyCable server together with Puma (set ANYCABLE_IN_PUMA=1 to enable)
|
|
414
|
+
plugin :anycable if ENV["ANYCABLE_IN_PUMA"]
|
|
415
|
+
RUBY
|
|
416
|
+
|
|
417
|
+
# Put the plugin before Solid Queue: Puma runs the stop hooks in the order of plugins,
|
|
418
|
+
# and the Solid Queue hook may fail and prevent the following ones from running
|
|
419
|
+
if contents.match?(/^\s*plugin\s+:solid_queue\b/)
|
|
420
|
+
inject_into_file "config/puma.rb", "#{plugin}\n", before: /^\s*plugin\s+:solid_queue\b.*$/
|
|
421
|
+
else
|
|
422
|
+
append_file "config/puma.rb", "\n#{plugin}"
|
|
423
|
+
end
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
@todos << "Run your Rails server with ANYCABLE_IN_PUMA=1 to start AnyCable server via Puma plugin (e.g., `ANYCABLE_IN_PUMA=1 bin/rails s`)"
|
|
403
427
|
end
|
|
404
428
|
|
|
405
|
-
def
|
|
429
|
+
def install_for_bin
|
|
406
430
|
unless file_exists?("bin/anycable-go")
|
|
407
431
|
generate "anycable:bin", "--version #{options[:version]}"
|
|
408
432
|
end
|
|
@@ -454,7 +478,7 @@ module AnyCableRailsGenerators
|
|
|
454
478
|
if file_exists?(file_name)
|
|
455
479
|
update_procfile(file_name)
|
|
456
480
|
else
|
|
457
|
-
return if options[:
|
|
481
|
+
return if options[:skip_procfile]
|
|
458
482
|
|
|
459
483
|
template file_name
|
|
460
484
|
end
|
|
@@ -464,13 +488,15 @@ module AnyCableRailsGenerators
|
|
|
464
488
|
in_root do
|
|
465
489
|
contents = File.read(file_name)
|
|
466
490
|
|
|
491
|
+
append_file file_name, "\n", force: true unless contents.empty? || contents.end_with?("\n")
|
|
492
|
+
|
|
467
493
|
if grpc?
|
|
468
494
|
unless contents.match?(/^anycable:\s/)
|
|
469
495
|
append_file file_name, "anycable: bundle exec anycable\n", force: true
|
|
470
496
|
end
|
|
471
497
|
end
|
|
472
498
|
unless contents.match?(/^ws:\s/)
|
|
473
|
-
append_file file_name, "ws: bin/anycable-go --port 8080", force: true
|
|
499
|
+
append_file file_name, "ws: bin/anycable-go --port 8080\n", force: true
|
|
474
500
|
end
|
|
475
501
|
end
|
|
476
502
|
end
|
|
@@ -505,7 +531,10 @@ module AnyCableRailsGenerators
|
|
|
505
531
|
end
|
|
506
532
|
|
|
507
533
|
def inform_jwt_identifiers(path)
|
|
508
|
-
|
|
534
|
+
unless file_exists?("app/channels/application_cable/connection.rb")
|
|
535
|
+
@todos << "To identify users (e.g., for presence or channels), pass identifiers to the #action_cable_with_jwt_meta_tag in #{path} (e.g., `action_cable_with_jwt_meta_tag(user: current_user)`). Read more: 👉 #{DOCS_ROOT}/rails/authentication?id=jwt-authentication"
|
|
536
|
+
return
|
|
537
|
+
end
|
|
509
538
|
|
|
510
539
|
in_root do
|
|
511
540
|
contents = File.read("app/channels/application_cable/connection.rb")
|
|
@@ -519,13 +548,12 @@ module AnyCableRailsGenerators
|
|
|
519
548
|
def install_js_packages
|
|
520
549
|
if file_exists?("config/importmap.rb") && file_exists?("bin/importmap")
|
|
521
550
|
run "bin/importmap pin @hotwired/turbo @anycable/web @anycable/turbo-stream"
|
|
522
|
-
|
|
551
|
+
# @hotwired/turbo-rails is no longer used by the application.js
|
|
552
|
+
gsub_file "config/importmap.rb", /^pin "@hotwired\/turbo-rails".*\n/, ""
|
|
523
553
|
elsif file_exists?("yarn.lock")
|
|
524
554
|
run "yarn add @anycable/web @anycable/turbo-stream"
|
|
525
|
-
|
|
526
|
-
elsif file_exists?("package-json.lock")
|
|
555
|
+
elsif file_exists?("package-lock.json")
|
|
527
556
|
run "npm install @anycable/web @anycable/turbo-stream"
|
|
528
|
-
true
|
|
529
557
|
else
|
|
530
558
|
false
|
|
531
559
|
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module AnyCableRailsGenerators
|
|
4
|
+
# Helpers to work with AnyCable server releases on GitHub
|
|
5
|
+
module WithReleaseHelpers
|
|
6
|
+
# The version to use when we cannot get the list of releases from GitHub
|
|
7
|
+
FALLBACK_VERSION = "1.6.22"
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def repository_name(version)
|
|
12
|
+
return "anycable/anycable" if version == "latest"
|
|
13
|
+
|
|
14
|
+
major, minor, = Gem::Version.new(version).segments
|
|
15
|
+
if (major >= 1 && minor.to_i >= 6) || (major > 1)
|
|
16
|
+
"anycable/anycable"
|
|
17
|
+
else
|
|
18
|
+
"anycable/anycable-go"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Returns the full version for a partial one (e.g., "1.6" -> "1.6.22").
|
|
23
|
+
# Returns the version itself if it's already full.
|
|
24
|
+
def resolve_version(version)
|
|
25
|
+
segments = Gem::Version.new(version).segments
|
|
26
|
+
return version if segments.size >= 3
|
|
27
|
+
|
|
28
|
+
latest = latest_release_version(segments)
|
|
29
|
+
return latest if latest
|
|
30
|
+
|
|
31
|
+
fallback =
|
|
32
|
+
if FALLBACK_VERSION.start_with?("#{segments.join(".")}.")
|
|
33
|
+
FALLBACK_VERSION
|
|
34
|
+
else
|
|
35
|
+
(segments + [0] * (3 - segments.size)).join(".")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
say_status :warn, "Failed to find the latest AnyCable server release for #{version}. Using #{fallback}", :yellow
|
|
39
|
+
fallback
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def latest_release_version(segments)
|
|
43
|
+
prefix = segments.join(".")
|
|
44
|
+
|
|
45
|
+
versions = fetch_release_tags(repository_name(prefix)).filter_map do |tag|
|
|
46
|
+
version = tag.delete_prefix("v")
|
|
47
|
+
next unless version.match?(/\A\d+\.\d+\.\d+\z/)
|
|
48
|
+
next unless version.start_with?("#{prefix}.")
|
|
49
|
+
|
|
50
|
+
Gem::Version.new(version)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
versions.max&.to_s
|
|
54
|
+
rescue => _e
|
|
55
|
+
nil
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# We use Git instead of GitHub API to avoid rate limits
|
|
59
|
+
def fetch_release_tags(repo)
|
|
60
|
+
output = IO.popen(
|
|
61
|
+
["git", "ls-remote", "--tags", "--refs", "https://github.com/#{repo}"],
|
|
62
|
+
err: File::NULL, &:read
|
|
63
|
+
)
|
|
64
|
+
return [] unless $?.success?
|
|
65
|
+
|
|
66
|
+
output.lines.map { _1.split("refs/tags/").last.strip }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|