Added volume configuration in response to issue coments

This commit is contained in:
Stephen van Beek
2023-03-14 19:55:37 +00:00
parent 2cea12c56b
commit 2db1bfde00
3 changed files with 58 additions and 15 deletions

View File

@@ -426,21 +426,31 @@ traefik:
host_port: 8080
```
### Configure entrypoints for traefik
### Configure docker options for traefik
You can override the ports and entrypoints for traefik list so:
We allow users to override the published ports and bound volumes for the traefik container like so:
```yaml
traefik:
ports:
options:
publish:
- 9000
- 9001
args:
entrypoints.myentrypoint.address: ":9000"
entrypoints.otherentrypoint.address: ":9001"
- 80
```
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:
Note, this fully overrides any defaults. If you choose to do this, then you'll like need to start out by copying the
default configuration:
```yaml
traefik:
options:
publish:
- 80
volumes:
- /var/run/docker.sock:/var/run/docker.sock
args:
'entrypoints.web.address=:80': true
```
A more complete example including entrypoints would be:
@@ -455,9 +465,12 @@ labels:
traefik.http.services.myservice.loadbalancer.server.port: 8080
traefik:
ports:
- 80
- 9000
options:
publish:
- 80
- 9000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
args:
'entrypoints.web.address=:80': true
'entrypoints.otherentrypoint.address=:9000': true

View File

@@ -9,7 +9,7 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
"--restart", "unless-stopped",
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
*published_ports,
"--volume", "/var/run/docker.sock:/var/run/docker.sock",
*volumes,
"traefik",
"--providers.docker",
"--log.level=DEBUG",
@@ -55,13 +55,21 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
private
def published_ports
if args = config.raw_config.dig(:traefik, "ports")
args.collect { |value| "--publish #{value}:#{value}" }.compact
if ports = config.raw_config.dig(:traefik, "options", "publish")
ports.collect { |value| "--publish #{value}:#{value}" }.compact
else
["--publish #{port}"]
end
end
def volumes
if volumes = config.raw_config.dig(:traefik, "options", "volumes")
volumes.collect { |value| "--volume #{value}" }.compact
else
["--volume /var/run/docker.sock:/var/run/docker.sock"]
end
end
def cmd_option_args
if args = config.traefik["args"]
optionize args, with: "="

View File

@@ -24,12 +24,34 @@ class CommandsTraefikTest < ActiveSupport::TestCase
"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]["ports"] = %w[9000 9001]
@config[:traefik]["options"] = {"publish" => [9000, 9001]}
assert_equal \
"docker run --name traefik --detach --restart unless-stopped --log-opt max-size=10m --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 with volumes configured" 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]["options"] = {"volumes" => %w[/var/run/docker.sock:/var/run/docker.sock ./letsencrypt/acme.json:/letsencrypt/acme.json] }
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 --volume ./letsencrypt/acme.json:/letsencrypt/acme.json 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 with ports and volumes configured" 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]["options"] = {"volumes" => %w[/var/run/docker.sock:/var/run/docker.sock ./letsencrypt/acme.json:/letsencrypt/acme.json], "publish" => [80, 8080] }
assert_equal \
"docker run --name traefik --detach --restart unless-stopped --log-opt max-size=10m --publish 80:80 --publish 8080:8080 --volume /var/run/docker.sock:/var/run/docker.sock --volume ./letsencrypt/acme.json:/letsencrypt/acme.json 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)