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

Allow Kamal to run without traefik #580

Merged
merged 3 commits into from
Nov 16, 2023
Merged

Conversation

yoelcabo
Copy link
Contributor

@yoelcabo yoelcabo commented Nov 12, 2023

Related discussion: #345

I know Kamal is designed for deploying web applications, as DHH was mentioning here: #191 (comment)

That said, the code change is small, and I think there is a valid use case for not having a web role:

Our use case

We are slowly migrating out of Heroku/AWS. Our first step was migrating some background workers.

If a worker is unreliable, jobs will be picked by "someone else", but if a web container is unreliable, it can cause serious downtime. That's why we are keeping the web in Heroku for now, but the workers are slowly being moved to Hetzner with Kamal.

A workaround for us was running a web container that was never accessed. However, this makes the configuration confusing, creates unnecessary connections to the database and makes the deployment slower.

@yoelcabo yoelcabo changed the title Allow Kamal to run without a web role Allow Kamal to run without traefik or web role Nov 12, 2023
Copy link
Collaborator

@djmb djmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yoelcabo!

I agree with your reasoning for this change. I've asked for a couple of changes. I think you'll also need to make a few changes to get this working again after #577 was merged.

@@ -3,6 +3,7 @@ class Kamal::Cli::Healthcheck < Kamal::Cli::Base

desc "perform", "Health check current app version"
def perform
return unless KAMAL.primary_role.running_traefik?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we raise an exception here instead and protect the callers with if statements? If someone managed to call this without a web role, I think it would be better to fail then to silently pass the check.

@@ -2,6 +2,7 @@ class Kamal::Commands::Healthcheck < Kamal::Commands::Base

def run
web = config.role(:web)
return unless web.present?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again could we raise here instead of returning?

@yoelcabo
Copy link
Contributor Author

yoelcabo commented Nov 14, 2023

Thanks a lot for the feedback 🙏 @djmb

I've addressed your comments and resolved the conflicts.

Due to #577 there are some important changes in my PR:

cc @mdkent

Regarding your comment on the running_traefik? check. This is my change:

  • The check happens now in the deploy command instead. If traefik is disabled in the primary, the healthcheck is not performed.
  • I added a raise for whenever someone invokes kamal healthcheck perform manually.
  • I removed the check on the command builder because it doesn't seem a possible code path.

@@ -3,6 +3,7 @@ class Kamal::Cli::Healthcheck < Kamal::Cli::Base

desc "perform", "Health check current app version"
def perform
raise "The primary host is not configured to run Traefik" unless KAMAL.config.role(KAMAL.config.primary_role).running_traefik?
Copy link
Contributor Author

@yoelcabo yoelcabo Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KAMAL.config.role(KAMAL.config.primary_role) might be too verbose.

In my original changes, KAMAL.config.primary_role was an instance of Role.

However, with #577, KAMAL.config.primary_web_role was introduced as a String.

I didn't want to change that to make the review simpler and focusing on what matters. However, if you think a cleanup might be interesting, I can submit another PR afterwards

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yoelcabo - yes if you could raise another PR to convert KAMAL.config.primary_role to a Role that would be great. I'll merge this PR now 🙏

@yoelcabo yoelcabo changed the title Allow Kamal to run without traefik or web role Allow Kamal to run without traefik Nov 14, 2023
@djmb djmb merged commit 610d9de into basecamp:main Nov 16, 2023
6 checks passed
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.

2 participants