Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR includes the necessary changes to deploy the demo app using Kamal 2.
Relevant Changes
Dockerfile
,.dockerignore
, andbin/docker-entrypoint
) based on those generated when creating a new Rails project.kamal init
to generate theconfig/deploy.yml
and.kamal/secrets
files (removed the generated hook samples to keep the PR concise).config/deploy.yml
file, retaining only the most relevant parts.KAMAL_REGISTRY_PASSWORD
andPOSTGRES_PASSWORD
are pulled from the.env
file using dotenv./up
route (default in new apps) toconfig/routes.rb
andconfig.assume_ssl = true
to theconfig/environments/production.rb
file, so Kamal can properly perform health checks on the Rails server.thruster
to the Gemfile, as per the new Rails template when creating a new project.Steps to Deploy
Note
Kamal CLI commands below are prefixed with
dotenv
because I'm using dotenv to parse the.env
file containing the registry and Postgres passwords. If that's not your case, you can omit it..env
file with theKAMAL_REGISTRY_PASSWORD
andPOSTGRES_PASSWORD
values.config/deploy.yml
file with proper host values and names. This demo PR assumes all components are running on the same server for simplicity.dotenv kamal setup
should get you up and running. However, due to this issue, that's not the case at the moment (hopefully, this will be fixed soon). Instead, here’s a workaround:a. Run
dotenv kamal server bootstrap
: This will only install Docker on the server rather than trying to boot all accessories beforekamal-proxy
is running.b. Run
dotenv kamal proxy boot
: Bootskamal-proxy
, which we need to fully set up theanycable-go
accessory.c. Run
dotenv kamal setup
: Sincekamal-proxy
is already running, this will now work, and by the end of the process, the demo app should be live.AnyCable on Kamal 2
This PR includes a few non-obvious details in the Kamal config file that are worth mentioning:
anycable-go
runs as an accessory, but since it needs to handle WebSocket traffic, it must be proxied throughkamal-proxy
. This requires configuring theproxy
section for theanycable-go
accessory, providing a host, SSL, app port, and health check path.anycable-go
needs to communicate with them (via theANYCABLE_RPC_HOST
environment variable), we pass an option to the Docker run command to set a network alias for the container, which is then used for theANYCABLE_RPC_HOST
environment variable. It's worth noting that stable names are being discussed in this issue, so this might not be needed in the future.Final Notes
I struggled a bit to get everything working for a production app of ours. The process still isn't 100% smooth, although it's improving (especially now that accessories proxying is supported). I thought I'd share this as it might be useful for others using AnyCable and looking to adopt Kamal 2.
I tried to keep the PR as concise as possible, but I'm sure there's room for improvement. Let me know if you have any suggestions.