You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR includes the necessary changes to deploy the demo app using Kamal 2.
Relevant Changes
Added Docker files (Dockerfile, .dockerignore, and bin/docker-entrypoint) based on those generated when creating a new Rails project.
Kamal setup:
Ran kamal init to generate the config/deploy.yml and .kamal/secrets files (removed the generated hook samples to keep the PR concise).
Cleaned up the config/deploy.yml file, retaining only the most relevant parts.
KAMAL_REGISTRY_PASSWORD and POSTGRES_PASSWORD are pulled from the .env file using dotenv.
Added the /up route (default in new apps) to config/routes.rb and config.assume_ssl = true to the config/environments/production.rb file, so Kamal can properly perform health checks on the Rails server.
Added 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.
Create an .env file with the KAMAL_REGISTRY_PASSWORD and POSTGRES_PASSWORD values.
Configure the config/deploy.yml file with proper host values and names. This demo PR assumes all components are running on the same server for simplicity.
Then, dotenv kamal setup should get you up and running.
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 through kamal-proxy. This requires configuring the proxy section for the anycable-go accessory, providing a host, SSL, app port, and health check path.
Servers containers in Kamal's terminology are generated with an unpredictable name. Since anycable-go needs to communicate with them (via the ANYCABLE_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 the ANYCABLE_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. No longer an issue since Kamal v2.5.
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.
I was referring specifically to point 3 in my "Steps to deploy" list — sorry, I could have been clearer. Ideally, after filling the configuration details for Kamal, we should only need to run the kamal setup command to get everything up and running. However, that wasn't the case by the time I opened this PR, due to this issue. The issue has been fixed in the meantime, and included in the v2.5 release, so I believe everything should work fine in that version of Kamal. 🎉
I won't have time to actually test/deploy the sample in the upcoming days to confirm, but let me know in case you're able to validate this. 👍
Thanks a lot @pjpires! (Sorry it took so long to say that). We finally got some time to invest into Kamal deployment, and this PR helped a lot. (We've created a new one with slightly different approach on configuration and with multi-gRPC support: #39). The official documentation is coming soon.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 initto generate theconfig/deploy.ymland.kamal/secretsfiles (removed the generated hook samples to keep the PR concise).config/deploy.ymlfile, retaining only the most relevant parts.KAMAL_REGISTRY_PASSWORDandPOSTGRES_PASSWORDare pulled from the.envfile using dotenv./uproute (default in new apps) toconfig/routes.rbandconfig.assume_ssl = trueto theconfig/environments/production.rbfile, so Kamal can properly perform health checks on the Rails server.thrusterto the Gemfile, as per the new Rails template when creating a new project.Steps to Deploy
Note
Kamal CLI commands below are prefixed with
dotenvbecause I'm using dotenv to parse the.envfile containing the registry and Postgres passwords. If that's not your case, you can omit it..envfile with theKAMAL_REGISTRY_PASSWORDandPOSTGRES_PASSWORDvalues.config/deploy.ymlfile with proper host values and names. This demo PR assumes all components are running on the same server for simplicity.dotenv kamal setupshould get you up and running.AnyCable on Kamal 2
This PR includes a few non-obvious details in the Kamal config file that are worth mentioning:
anycable-goruns as an accessory, but since it needs to handle WebSocket traffic, it must be proxied throughkamal-proxy. This requires configuring theproxysection for theanycable-goaccessory, providing a host, SSL, app port, and health check path.anycable-goneeds to communicate with them (via theANYCABLE_RPC_HOSTenvironment 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_HOSTenvironment 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.No longer an issue since Kamal v2.5.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.