kamal icon indicating copy to clipboard operation
kamal copied to clipboard

path-based proxy

Open shiny opened this issue 9 months ago • 3 comments

Kamal-proxy now supports path-based proxying (see commit https://github.com/basecamp/kamal-proxy/commit/dd1adc7cee4241054f4f086af5471cb49d905d0e). I’m wondering when this feature will be available in Kamal? Currently, when I set a path-prefix for a proxy, I get the following error:

ERROR (Kamal::ConfigurationError): proxy: unknown key: path-prefix

I'm really looking forward to it

shiny avatar Mar 16 '25 10:03 shiny

Related to https://github.com/basecamp/kamal-proxy/issues/48

ACPK avatar Apr 07 '25 19:04 ACPK

@shiny @ACPK Is there any update on this?

mahendhar9 avatar Apr 18 '25 16:04 mahendhar9

This seems like a required feature

without this, multi container apps, e.g. api + bff, become annoying to setup, because as far as I can see, this would require deploying your own nginx/caddy as the service, and then your actual applications as "accessories", which dont have the benefits (rolling updates, etc) of services

shainegordon avatar Apr 23 '25 09:04 shainegordon

Workaround: As long as path-prefix isn't supported natively in kamal as proxy option (it seems that 2.6.0 doesn't support it yet), you can just workaround this by using a post-deploy hook that executes another kamal-proxy deploy with the path-prefix option. It could look like that (kamal-proxy >=0.9.0 required):

.kamal/hooks/post-deploy

#!/usr/bin/env bash
set -euo pipefail

# Get the container hash for the running application
CONTAINER_HASH=$(ssh my-server-01 "docker ps --filter name=myapp --format '{{.ID}}'")

# Deploy new route with container hash
ssh my-server-01 "docker exec kamal-proxy /usr/local/bin/kamal-proxy deploy myapp \
  --target ${CONTAINER_HASH}:3000 \
  --host myapp.dev \
  --health-check-path=/ \
  --path-prefix=/app"

brgmn avatar May 13 '25 16:05 brgmn

@brgmn @shainegordon

@shiny @ACPK Is there any update on this?

I’ve opened a pull request that adds support for this feature: #1551. It includes notes on how to use it before it’s merged into main.

ACPK avatar May 13 '25 23:05 ACPK

@ACPK Thanks for your PR! Looks good and I'm looking forward to it!

For other people using my post-deploy workaround - you can't use the same host for multiple deployments (kamal proxy fails with a resource error then). So I use a fake host for the second (subpath) deployment like "myapp-fake.dev" and it get's replaced by the post-deploy hook (same host but with new path-prefix option set).

brgmn avatar May 14 '25 05:05 brgmn

@brgmn @shainegordon

@shiny @ACPK Is there any update on this?

I’ve opened a pull request that adds support for this feature: #1551. It includes notes on how to use it before it’s merged into main.

awesome

Will this work with ssl: false in both services?

e.g we deploy to AWS EC2, and use an ALB and Cloudfront, so we don't want/need kamal to manage SSL certificates

shainegordon avatar May 14 '25 09:05 shainegordon

@shainegordon Yes, the app using the path based prefix relies on the other app for whether ssl is used.

ACPK avatar May 14 '25 12:05 ACPK

How does PR https://github.com/basecamp/kamal/pull/1551 get merged and released?

Seems like a very safe change, that will enable a lot more Kamal adoption. We've got at least 3 stacks that I want to migrate

I suppose for now I can follow your testing instructions, and build a temp Gemfile in our CI/CD pipeline (I'm not actually a ruby developer, just find this tool very appealing)

shainegordon avatar May 18 '25 16:05 shainegordon

Closed by https://github.com/basecamp/kamal/pull/1551

djmb avatar Jun 18 '25 07:06 djmb