Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kamal 2 #37

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Kamal 2 #37

wants to merge 6 commits into from

Conversation

pjpires
Copy link

@pjpires pjpires commented Jan 3, 2025

Description

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.

  1. Create an .env file with the KAMAL_REGISTRY_PASSWORD and POSTGRES_PASSWORD values.
  2. 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.
  3. Ideally, 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 before kamal-proxy is running.
    b. Run dotenv kamal proxy boot: Boots kamal-proxy, which we need to fully set up the anycable-go accessory.
    c. Run dotenv kamal setup: Since kamal-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:

  1. 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.
  2. 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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant