anycable-rails-core 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bc0b1eac8c453d0054d508826fd33e58b32684c89694fbbc393d2796db8f0c1
4
- data.tar.gz: 82ff10fabf21471a9fdcc14e6d76d294902b89372002734538b66e1e7569ab1d
3
+ metadata.gz: d59e7b74ab037c4e2dfdf18b5fb289fad3f7eac9d1a08df798f656ed35dda95c
4
+ data.tar.gz: a1304fbd9db3f26c92ef5008b196135a2f09a5922bde5137d7e604e652250354
5
5
  SHA512:
6
- metadata.gz: 53cda30136d94edc95e319a0e80bed3ce19716d15dd0e69eae0fc14ffb0c45d58ec0fb466bece171736f4821a7aeeba6ec774c228e8915deb7b2eea01fed1565
7
- data.tar.gz: 2787f8c23179f2283fe9b68982f0e3f0ea8fde5222ef97dba7294464523d8968f57f1c71f166f0d44583047747bbd40433e7603afb07c45f3b58eac98bba3cf4
6
+ metadata.gz: 8a7eebcf805f8c72c300b734fe52a7ce952b60527b8644f004ca7bb3414cc04da49b8ee2ce36d84f6f7d8bf0438450dfdffb019610b091894c3dcf7e65ec4897
7
+ data.tar.gz: 488065254235777ef04b781ef98f1c20c8c12f2f6c268c6044fb683e4a9774f1ae5abbdcbec53199065e57ec8df1df15d13f85c152471a5a54ceb23e6ddbd832
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.4.1 (2023-09-27)
6
+
7
+ - Fix compatibility with Rails 7.1. ([@palkan][])
8
+
9
+ - Upgrade `anycable:setup` generator to support v1.4 features. ([@palkan][])
10
+
11
+ Add `bin/anycable-go` to use `anycable-go` locally. Add `--rpc=http` to configure for using AnyCable with HTTP RPC.
12
+
5
13
  ## 1.4.0 (2023-07-07)
6
14
 
7
15
  - Add HTTP RPC integration. ([@palkan][])
@@ -21,15 +21,23 @@ module AnyCable
21
21
 
22
22
  AnyCable.configure_server do
23
23
  server_logger = AnyCable.logger = ::ActionCable.server.config.logger
24
- AnyCable.logger = ActiveSupport::TaggedLogging.new(server_logger) if server_logger.is_a?(::Logger)
24
+
25
25
  # Broadcast server logs to STDOUT in development
26
26
  if ::Rails.env.development? &&
27
27
  !ActiveSupport::Logger.logger_outputs_to?(::Rails.logger, $stdout)
28
28
  console = ActiveSupport::Logger.new($stdout)
29
29
  console.formatter = ::Rails.logger.formatter if ::Rails.logger.respond_to?(:formatter)
30
30
  console.level = ::Rails.logger.level if ::Rails.logger.respond_to?(:level)
31
- AnyCable.logger.extend(ActiveSupport::Logger.broadcast(console))
31
+
32
+ # Rails 7.1+
33
+ if defined?(ActiveSupport::BroadcastLogger)
34
+ AnyCable.logger = ActiveSupport::BroadcastLogger.new(AnyCable.logger, console)
35
+ else
36
+ AnyCable.logger.extend(ActiveSupport::Logger.broadcast(console))
37
+ end
32
38
  end
39
+
40
+ AnyCable.logger = ActiveSupport::TaggedLogging.new(AnyCable.logger) if server_logger.is_a?(::Logger)
33
41
  end
34
42
 
35
43
  # Add tagging middleware
@@ -2,6 +2,6 @@
2
2
 
3
3
  module AnyCable
4
4
  module Rails
5
- VERSION = "1.4.0"
5
+ VERSION = "1.4.1"
6
6
  end
7
7
  end
@@ -1,2 +1,11 @@
1
1
  Description:
2
2
  Configures your application to work with AnyCable interactively.
3
+
4
+ Example:
5
+ rails generate anycable:setup
6
+
7
+ # You can opt-in to use HTTP RPC
8
+ rails generate anycable:setup --rpc=http
9
+
10
+ # You can specify which version of anycable-go to use
11
+ rails generate anycable:setup --version=1.4
@@ -10,14 +10,15 @@ module AnyCableRailsGenerators
10
10
 
11
11
  DOCS_ROOT = "https://docs.anycable.io"
12
12
  DEVELOPMENT_METHODS = %w[skip local docker].freeze
13
- SERVER_SOURCES = %w[skip brew binary].freeze
13
+ RPC_IMPL = %w[grpc http].freeze
14
14
 
15
15
  class_option :devenv,
16
16
  type: :string,
17
17
  desc: "Select your development environment (options: #{DEVELOPMENT_METHODS.join(", ")})"
18
- class_option :source,
18
+ class_option :rpc,
19
19
  type: :string,
20
- desc: "Choose a way of installing AnyCable-Go server (options: #{SERVER_SOURCES.join(", ")})"
20
+ desc: "Select RPC implementation (options: #{RPC_IMPL.join(", ")})",
21
+ default: "grpc"
21
22
  class_option :skip_heroku,
22
23
  type: :boolean,
23
24
  desc: "Do not copy Heroku configs"
@@ -30,12 +31,6 @@ module AnyCableRailsGenerators
30
31
  class_option :skip_install,
31
32
  type: :boolean,
32
33
  desc: "Do not run bundle install when adding new gems"
33
-
34
- include WithOSHelpers
35
-
36
- class_option :bin_path,
37
- type: :string,
38
- desc: "Where to download AnyCable-Go server binary (default: #{DEFAULT_BIN_PATH})"
39
34
  class_option :version,
40
35
  type: :string,
41
36
  desc: "Specify the AnyCable-Go version (defaults to latest release)"
@@ -99,6 +94,7 @@ module AnyCableRailsGenerators
99
94
 
100
95
  in_root do
101
96
  next unless File.file?("Procfile")
97
+ next if http_rpc?
102
98
 
103
99
  contents = File.read("Procfile")
104
100
  contents.sub!(/^web: (.*)$/, %q(web: [[ "$ANYCABLE_DEPLOYMENT" == "true" ]] && bundle exec anycable --server-command="anycable-go" || \1))
@@ -171,6 +167,10 @@ module AnyCableRailsGenerators
171
167
  !!gemfile_lock&.match?(/^\s+rubocop\b/)
172
168
  end
173
169
 
170
+ def http_rpc?
171
+ options[:rpc] == "http"
172
+ end
173
+
174
174
  def gemfile_lock
175
175
  @gemfile_lock ||= begin
176
176
  res = nil
@@ -192,7 +192,7 @@ module AnyCableRailsGenerators
192
192
  say <<~YML
193
193
  ─────────────────────────────────────────
194
194
  ws:
195
- image: anycable/anycable-go:1.2
195
+ image: anycable/anycable-go:1.4
196
196
  ports:
197
197
  - '8080:8080'
198
198
  environment:
@@ -223,33 +223,25 @@ module AnyCableRailsGenerators
223
223
  end
224
224
 
225
225
  def install_for_local
226
- install_server
227
- template_proc_files
228
- end
229
-
230
- def install_server
231
- answer = SERVER_SOURCES.index(options[:source]) || 99
232
-
233
- until SERVER_SOURCES[answer.to_i]
234
- answer = ask "How do you want to install AnyCable-Go WebSocket server? (1) Homebrew, (2) Download binary, (0) Skip"
226
+ inside("bin") do
227
+ template "anycable-go", chmod: 0o755
235
228
  end
236
229
 
237
- case answer.to_i
238
- when 0
239
- say_status :help, "⚠️ Please, read this guide on how to install AnyCable-Go server 👉 #{DOCS_ROOT}/anycable-go/getting_started", :yellow
240
- return
241
- else
242
- return unless send("install_from_#{SERVER_SOURCES[answer.to_i]}")
230
+ if file_exists?(".gitignore")
231
+ append_file ".gitignore", "bin/dist\n"
243
232
  end
244
233
 
245
- say_status :info, "✅ AnyCable-Go WebSocket server has been successfully installed"
234
+ template_proc_files
246
235
  end
247
236
 
248
237
  def template_proc_files
249
238
  file_name = "Procfile.dev"
250
239
 
251
240
  if file_exists?(file_name)
252
- append_file file_name, "anycable: bundle exec anycable\nws: anycable-go#{anycable_go_options}", force: true
241
+ unless http_rpc?
242
+ append_file file_name, "anycable: bundle exec anycable\n", force: true
243
+ end
244
+ append_file file_name, "ws: bin/anycable-go #{anycable_go_options}", force: true
253
245
  else
254
246
  say_status :help, "💡 We recommend using Hivemind to manage multiple processes in development 👉 https://github.com/DarthSim/hivemind", :yellow
255
247
 
@@ -263,32 +255,11 @@ module AnyCableRailsGenerators
263
255
  end
264
256
  end
265
257
 
266
- def install_from_brew
267
- run "brew install anycable-go", abort_on_failure: true
268
- run "anycable-go -v", abort_on_failure: true
269
- end
270
-
271
- def install_from_binary
272
- bin_path ||= DEFAULT_BIN_PATH if options[:devenv] # User don't want interactive mode
273
- bin_path ||= ask "Please, enter the path to download the AnyCable-Go binary to", default: DEFAULT_BIN_PATH, path: true
274
-
275
- generate "anycable:download", download_options(bin_path: bin_path)
276
-
277
- true
278
- end
279
-
280
- def download_options(**params)
281
- opts = options.merge(params)
282
- [].tap do |args|
283
- args << "--os #{opts[:os]}" if opts[:os]
284
- args << "--cpu #{opts[:cpu]}" if opts[:cpu]
285
- args << "--bin-path=#{opts[:bin_path]}" if opts[:bin_path]
286
- args << "--version #{opts[:version]}" if opts[:version]
287
- end.join(" ")
288
- end
289
-
290
258
  def anycable_go_options
291
- redis? ? " --port=8080" : " --port=8080 --broadcast_adapter=http"
259
+ opts = ["--port=8080"]
260
+ opts << "--broadcast_adapter=http" unless redis?
261
+ opts << "--rpc_impl=http --rpc_host=http://localhost:3000/_anycable" if http_rpc?
262
+ opts.join(" ")
292
263
  end
293
264
 
294
265
  def file_exists?(name)
@@ -296,5 +267,18 @@ module AnyCableRailsGenerators
296
267
  return File.file?(name)
297
268
  end
298
269
  end
270
+
271
+ def anycable_go_version
272
+ @anycable_go_version ||= (normalize_version(options[:version]) || "latest")
273
+ end
274
+
275
+ def normalize_version(version)
276
+ return unless version
277
+
278
+ # We need a full version for bin/anycable-go script
279
+ segments = Gem::Version.new(version).segments
280
+ segments << 0 until segments.size >= 3
281
+ segments.join(".")
282
+ end
299
283
  end
300
284
  end
@@ -1,6 +1,5 @@
1
- server: bundle exec rails s
2
- <%- if webpacker? -%>
3
- assets: bundle exec bin/webpack-dev-server
4
- <%- end -%>
1
+ web: bin/rails s
2
+ <%- unless http_rpc? -%>
5
3
  anycable: bundle exec anycable
6
- ws: anycable-go<%= anycable_go_options %>
4
+ <%- end -%>
5
+ ws: bin/anycable-go <%= anycable_go_options %>
@@ -0,0 +1,22 @@
1
+ #!/bin/bash
2
+
3
+ cd $(dirname $0)/..
4
+
5
+ # It's recommended to use the exact version of AnyCable-Go here
6
+ version="<%= anycable_go_version %>"
7
+
8
+ if [ ! -f ./bin/dist/anycable-go ]; then
9
+ echo "AnyCable-go is not installed, downloading..."
10
+ ./bin/rails g anycable:download --version=$version --bin-path=./bin/dist
11
+ fi
12
+
13
+ curVersion=$(./bin/dist/anycable-go -v)
14
+
15
+ if [[ "$version" != "latest" ]]; then
16
+ if [[ "$curVersion" != "$version"* ]]; then
17
+ echo "AnyCable-go version is not $version, downloading a new one..."
18
+ ./bin/rails g anycable:download --version=$version --bin-path=./bin/dist
19
+ fi
20
+ fi
21
+
22
+ ./bin/dist/anycable-go $@
@@ -32,6 +32,9 @@ default: &default
32
32
  # Localhost is used by default.
33
33
  # redis_url: "redis://localhost:6379/1"
34
34
  <%- end -%>
35
+ <%- if http_rpc? -%>
36
+ http_rpc_mount_path: "/_anycable"
37
+ <%- end -%>
35
38
 
36
39
  development:
37
40
  <<: *default
@@ -41,8 +44,3 @@ test:
41
44
 
42
45
  production:
43
46
  <<: *default
44
- <%- if !redis? && !nats? -%>
45
- # Use Redis or NATS in production
46
- broadcast_adapter: redis
47
- # broadcast_adapter: nats
48
- <%- end -%>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anycable-rails-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-12 00:00:00.000000000 Z
11
+ date: 2023-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anycable-core
@@ -92,6 +92,7 @@ files:
92
92
  - lib/generators/anycable/setup/USAGE
93
93
  - lib/generators/anycable/setup/setup_generator.rb
94
94
  - lib/generators/anycable/setup/templates/Procfile.dev.tt
95
+ - lib/generators/anycable/setup/templates/bin/anycable-go.tt
95
96
  - lib/generators/anycable/setup/templates/config/anycable.yml.tt
96
97
  - lib/generators/anycable/setup/templates/config/cable.yml.tt
97
98
  - lib/generators/anycable/setup/templates/config/initializers/anycable.rb.tt