From eacdf345406d16e8cd4540866d3c46eb498039bb Mon Sep 17 00:00:00 2001 From: Rasmus <2277443+kjellberg@users.noreply.github.com> Date: Wed, 8 Mar 2023 18:55:04 +0100 Subject: [PATCH 1/3] fix: mrsk deploy fails when traefik config is empty --- lib/mrsk/commands/traefik.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mrsk/commands/traefik.rb b/lib/mrsk/commands/traefik.rb index b8ae8c28..90032e76 100644 --- a/lib/mrsk/commands/traefik.rb +++ b/lib/mrsk/commands/traefik.rb @@ -45,8 +45,9 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base docker :image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=Traefik" end - def port - "#{config.raw_config.traefik.fetch("host_port", "80")}:80" + def port + traefik_port = config.raw_config.dig(:traefik, "host_port") || 80 + "#{traefik_port}:80" end private From 0431bb5f97587f98db323a0ebfa83f7ccfa19d25 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 9 Mar 2023 09:29:56 +0100 Subject: [PATCH 2/3] Extract named constant and method --- lib/mrsk/commands/traefik.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/mrsk/commands/traefik.rb b/lib/mrsk/commands/traefik.rb index 90032e76..b8cbe343 100644 --- a/lib/mrsk/commands/traefik.rb +++ b/lib/mrsk/commands/traefik.rb @@ -1,4 +1,6 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base + CONTAINER_PORT = 80 + def run docker :run, "--name traefik", "--detach", @@ -46,12 +48,15 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base end def port - traefik_port = config.raw_config.dig(:traefik, "host_port") || 80 - "#{traefik_port}:80" + "#{host_port}:#{CONTAINER_PORT}" end private def cmd_args (config.raw_config.dig(:traefik, "args") || { }).collect { |(key, value)| [ "--#{key}", value ] }.flatten end + + def host_port + config.raw_config.dig(:traefik, "host_port") || CONTAINER_PORT + end end From 46bec120c8fdc7b8bdc764fb43848893e235067f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 9 Mar 2023 09:30:09 +0100 Subject: [PATCH 3/3] Test running without special config --- test/commands/traefik_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/commands/traefik_test.rb b/test/commands/traefik_test.rb index ae0d471e..54bc260a 100644 --- a/test/commands/traefik_test.rb +++ b/test/commands/traefik_test.rb @@ -19,6 +19,14 @@ class CommandsTraefikTest < ActiveSupport::TestCase new_command.run.join(" ") end + test "run without configuration" do + @config.delete(:traefik) + + assert_equal \ + "docker run --name traefik --detach --restart unless-stopped --log-opt max-size=10m --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock traefik --providers.docker --log.level=DEBUG", + new_command.run.join(" ") + end + test "traefik start" do assert_equal \ "docker container start traefik",