diff --git a/README.md b/README.md index 56d26116e..eb1f0aabc 100644 --- a/README.md +++ b/README.md @@ -426,6 +426,42 @@ traefik: host_port: 8080 ``` +### Additional entrypoints for traefik + +You can configure additional ports and entrypoints for traefik list so: + +```yaml +traefik: + additional_ports: + - 9000 + - 9001 + args: + entrypoints.myentrypoint.address: ":9000" + entrypoints.otherentrypoint.address: ":9001" +``` + +Be aware, a lot of the out-of-the-box magic of mrsk is provided by traefik defaults so going down this path requires more manual configuration, like so: + +A more complete example including entrypoints would be: + +```yaml +service: myservice + +labels: + traefik.tcp.routers.other.rule: 'HostSNI(`*`)' + traefik.tcp.routers.other.entrypoints: otherentrypoint + traefik.tcp.services.other.loadbalancer.server.port: 9000 + traefik.http.routers.myservice.entrypoints: web + traefik.http.services.myservice.loadbalancer.server.port: 8080 + +traefik: + additional_ports: + - 9000 + args: + 'entrypoints.web.address=:80': true + 'entrypoints.otherentrypoint.address=:9000': true +``` + ### Configuring build args for new images Build arguments that aren't secret can also be configured: diff --git a/lib/mrsk/commands/traefik.rb b/lib/mrsk/commands/traefik.rb index b9ff19c18..acda3cf54 100644 --- a/lib/mrsk/commands/traefik.rb +++ b/lib/mrsk/commands/traefik.rb @@ -9,6 +9,7 @@ def run "--restart", "unless-stopped", "--log-opt", "max-size=#{MAX_LOG_SIZE}", "--publish", port, + *additional_ports, "--volume", "/var/run/docker.sock:/var/run/docker.sock", "traefik", "--providers.docker", @@ -54,6 +55,14 @@ def port end private + def additional_ports + if args = config.raw_config.dig(:traefik, "additional_ports") + args.collect { |value| "--publish #{value}:#{value}" }.compact + else + [] + end + end + def cmd_option_args if args = config.traefik["args"] optionize args, with: "=" diff --git a/test/commands/traefik_test.rb b/test/commands/traefik_test.rb index 5ca51e13b..58d0a5575 100644 --- a/test/commands/traefik_test.rb +++ b/test/commands/traefik_test.rb @@ -19,6 +19,17 @@ class CommandsTraefikTest < ActiveSupport::TestCase new_command.run.join(" ") end + test "run with additional entrypoints" do + 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 --accesslog.format \"json\" --metrics.prometheus.buckets \"0.1,0.3,1.2,5.0\"", + new_command.run.join(" ") + + @config[:traefik]["additional_ports"] = %w[9000 9001] + assert_equal \ + "docker run --name traefik --detach --restart unless-stopped --log-opt max-size=10m --publish 80:80 --publish 9000:9000 --publish 9001:9001 --volume /var/run/docker.sock:/var/run/docker.sock traefik --providers.docker --log.level=DEBUG --accesslog.format \"json\" --metrics.prometheus.buckets \"0.1,0.3,1.2,5.0\"", + new_command.run.join(" ") + end + test "run without configuration" do @config.delete(:traefik)