From c2ec04f8c10a3abba173250128912478fad834f9 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Thu, 24 Aug 2023 10:52:10 +0100 Subject: [PATCH] Allow Traefik to run without publishing port Adds the `publish` option which, if set to false, does not pass `--publish` to `docker run` when starting Traefik. This is useful when running Traefik behind a reverse proxy, for example. --- lib/kamal/commands/traefik.rb | 6 +++++- test/commands/traefik_test.rb | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/kamal/commands/traefik.rb b/lib/kamal/commands/traefik.rb index 2d886307..e77a81de 100644 --- a/lib/kamal/commands/traefik.rb +++ b/lib/kamal/commands/traefik.rb @@ -11,7 +11,7 @@ class Kamal::Commands::Traefik < Kamal::Commands::Base docker :run, "--name traefik", "--detach", "--restart", "unless-stopped", - "--publish", port, + *publish_args, "--volume", "/var/run/docker.sock:/var/run/docker.sock", *env_args, *config.logging_args, @@ -64,6 +64,10 @@ class Kamal::Commands::Traefik < Kamal::Commands::Base end private + def publish_args + argumentize "--publish", port unless config.traefik["publish"] == false + end + def label_args argumentize "--label", labels end diff --git a/test/commands/traefik_test.rb b/test/commands/traefik_test.rb index 368e166f..b6b47bfd 100644 --- a/test/commands/traefik_test.rb +++ b/test/commands/traefik_test.rb @@ -25,6 +25,11 @@ class CommandsTraefikTest < ActiveSupport::TestCase assert_equal \ "docker run --name traefik --detach --restart unless-stopped --publish 8080:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"", new_command.run.join(" ") + + @config[:traefik]["publish"] = false + assert_equal \ + "docker run --name traefik --detach --restart unless-stopped --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"", + new_command.run.join(" ") end test "run with ports configured" do