Generators#110
Conversation
92c7f33 to
a8afd29
Compare
palkan
left a comment
There was a problem hiding this comment.
Looks good 👍
Left a bunch of comments.
A question regarding local installation.
We discussed a little bit different scenario: downloading a binary into the gem's source folder and adding a bin/anycable-go wrapper script to run it.
That would allow users to download binaries on different platforms but run using the same command.
And we can extract downloading into a separate task and allow users to run it separately (rake anycable:download:anycable-go). That could simplify installing anycable-go for local development (and other envs, e.g., CI).
| module Setup | ||
| # Generator to help set up AnyCable in Docker environment | ||
| class DockerGenerator < ::Rails::Generators::Base | ||
| namespace "anycable:setup:docker" |
There was a problem hiding this comment.
Let's put these scripting into anycable:setup:dev:... namespace, 'cause it might be confused with production configuration.
There was a problem hiding this comment.
First of all, no one in their right mind won't execute this generator in production.
Also, almost nothing stops to use these AnyCable Compose services in production when deploying to Docker Swarm.
| say "Docker configs are not standardized." | ||
| say "So, right now, we cannot continue installation process." | ||
| say "🛈 But, you can find an example of workable configs here: " | ||
| say " 👉 https://github.com/evilmartians/evil_chat/tree/feature/anycable" |
There was a problem hiding this comment.
Let's add a docker-compose.yml snippet instead for now:
anycable-ws:
image: anycable/anycable-go:v0.6.4
ports:
- '3334:3334'
environment:
PORT: 3334
REDIS_URL: redis://redis:6379/0
ANYCABLE_RPC_HOST: anycable-rpc:50051
depends_on:
- anycable-rpc
- redis
anycable-rpc:
<<: *backend
command: bundle exec anycable
ports:
- '50051'We will replace it with the link to the documentation later.
| end | ||
|
|
||
| environment(nil, env: :production) do | ||
| 'config.action_cable.url = ENV["CABLE_URL"].presence' |
There was a problem hiding this comment.
Maybe, ENV.fetch("CABLE_URL")? To make it fail on boot if no env configured.
Or even ENV.fetch("CABLE_URL") { raise "Please, add CABLE_URL env variable pointing to your AnyCable-Go server" }
There was a problem hiding this comment.
Before I wanted, but later I realized that I cannot create a Heroku review app, because it disallows to fill in an empty environment variable. And we want use the async adapter with empty url.
|
|
||
| def cable_url | ||
| environment(nil, env: :development) do | ||
| 'config.action_cable.url = ENV.fetch("CABLE_URL", "ws://localhost:3334/cable").presence' |
There was a problem hiding this comment.
Let's add a comment to this line (and the one below): "Specify AnyCable WebSocket server URL to make JS client connect to it"
| end | ||
| end | ||
|
|
||
| def heroku |
There was a problem hiding this comment.
What about https://github.com/anycable/capistrano-anycable?
Maybe, we can add two separate generators: anycable:setup:deployment:heroku and anycable:setup:deployment:capistrano?
And shouldn't it be a part of the base setup generator?
There was a problem hiding this comment.
Sure, we can describe all deployment methods that we know =)
But for the first stage, I choose only two methods. Will do in a separate PR.
part of the base setup generator?
Agree
| end | ||
|
|
||
| def configs | ||
| inside("config") { template "cable.yml" } |
There was a problem hiding this comment.
Can we just change the adapter setting? Everything else is not relevant to AnyCable, let's leave as is.
There was a problem hiding this comment.
We could try, but there is a chance to fail.
It is better to promote our right config, then a developer can view the diff and merge it by a mergetool. This functionality give Thor out of the box.
| say_status :info, "✔ AnyCable-Go WebSocket server has been installed" | ||
| end | ||
|
|
||
| def configs |
There was a problem hiding this comment.
Let's add config/anycable.yml as well.
We already had it in the previous version: https://github.com/anycable/anycable-rails/blob/v0.5.5/lib/generators/anycable/templates/anycable.yml (it contains a lot of useful annotations).
It's a bit outdated (e.g., it doesn't contain access_logs_disabled: false parameter).
There was a problem hiding this comment.
Hm, I don't know about it. Before I need to place it at this PR evilmartians/evil_chat#5 and I need to figure out what to do with hardcoded rpc_host and redis_url options
| say_status :info, "✔ AnyCable-Go WebSocket server has been installed" | ||
| end | ||
|
|
||
| def configs |
There was a problem hiding this comment.
This should be a part of the setup generator, not setup:local.
| inside("config") { template "cable.yml" } | ||
| end | ||
|
|
||
| def cable_url |
There was a problem hiding this comment.
This should be a part of the setup generator, not setup:local.
| say_status :help, "🛈 You can read more Heroky deployment here 👉 https://docs.anycable.io/#/deployment/heroku", :yellow | ||
| end | ||
|
|
||
| def finish |
That was only the proposal. I find it's not a good idea. There is no difference where a user places the binary, but it is better and more transparent for a user when the binary would be placed on the usual bin path. |
a8afd29 to
099fbf3
Compare
099fbf3 to
f54ce56
Compare
|
Slightly refactored after the review. |
7628052 to
8712842
Compare
|
@palkan can you look |
| Dir["#{__dir__}/support/**/*.rb"].each { |f| require f } | ||
|
|
||
| RSpec.configure do |config| | ||
| include ActiveSupport::Testing::Stream |
| source_root File.expand_path("templates", __dir__) | ||
|
|
||
| METHODS = %w[skip local docker].freeze | ||
| SERVER_VERSION = "v0.6.4" |
There was a problem hiding this comment.
We definitely need to not use a server version in a constant. Otherwise, we will forget to change that constant every time after the server was released.
There is a secret url that can get the latest asset from the latest release.
https://github.com/anycable/anycable-go/releases/latest/download/anycable-go-v0.6.4-linux-amd64
The big problem we have is that a binary contains a version in a name. This is not the necessary information. I propose to cut it.
There was a problem hiding this comment.
@palkan What do think? Can we roll out a new release with new naming to have the ability to change the version to the latest here?
There was a problem hiding this comment.
Yeah, that's a good idea. Let's add a ticket to the v1.0 project.
For now, let's leave as is (let's add a TODO: or FIXME: with this comment), so we'll be able to test the generator without waiting for anycable-go fixes.
What is the purpose of this pull request?
We want to add an ability to configure any_cable quickly.
What changes did you make? (overview)
Checklist