Added volume configuration in response to issue coments
This commit is contained in:
35
README.md
35
README.md
@@ -426,21 +426,31 @@ traefik:
|
|||||||
host_port: 8080
|
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
|
```yaml
|
||||||
traefik:
|
traefik:
|
||||||
ports:
|
options:
|
||||||
|
publish:
|
||||||
- 9000
|
- 9000
|
||||||
- 9001
|
- 80
|
||||||
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:
|
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:
|
A more complete example including entrypoints would be:
|
||||||
|
|
||||||
@@ -455,9 +465,12 @@ labels:
|
|||||||
traefik.http.services.myservice.loadbalancer.server.port: 8080
|
traefik.http.services.myservice.loadbalancer.server.port: 8080
|
||||||
|
|
||||||
traefik:
|
traefik:
|
||||||
ports:
|
options:
|
||||||
- 80
|
publish:
|
||||||
- 9000
|
- 80
|
||||||
|
- 9000
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
args:
|
args:
|
||||||
'entrypoints.web.address=:80': true
|
'entrypoints.web.address=:80': true
|
||||||
'entrypoints.otherentrypoint.address=:9000': true
|
'entrypoints.otherentrypoint.address=:9000': true
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
|
|||||||
"--restart", "unless-stopped",
|
"--restart", "unless-stopped",
|
||||||
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
|
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
|
||||||
*published_ports,
|
*published_ports,
|
||||||
"--volume", "/var/run/docker.sock:/var/run/docker.sock",
|
*volumes,
|
||||||
"traefik",
|
"traefik",
|
||||||
"--providers.docker",
|
"--providers.docker",
|
||||||
"--log.level=DEBUG",
|
"--log.level=DEBUG",
|
||||||
@@ -55,13 +55,21 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
|
|||||||
|
|
||||||
private
|
private
|
||||||
def published_ports
|
def published_ports
|
||||||
if args = config.raw_config.dig(:traefik, "ports")
|
if ports = config.raw_config.dig(:traefik, "options", "publish")
|
||||||
args.collect { |value| "--publish #{value}:#{value}" }.compact
|
ports.collect { |value| "--publish #{value}:#{value}" }.compact
|
||||||
else
|
else
|
||||||
["--publish #{port}"]
|
["--publish #{port}"]
|
||||||
end
|
end
|
||||||
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
|
def cmd_option_args
|
||||||
if args = config.traefik["args"]
|
if args = config.traefik["args"]
|
||||||
optionize args, with: "="
|
optionize args, with: "="
|
||||||
|
|||||||
@@ -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\"",
|
"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(" ")
|
new_command.run.join(" ")
|
||||||
|
|
||||||
@config[:traefik]["ports"] = %w[9000 9001]
|
@config[:traefik]["options"] = {"publish" => [9000, 9001]}
|
||||||
assert_equal \
|
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\"",
|
"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(" ")
|
new_command.run.join(" ")
|
||||||
end
|
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
|
test "run without configuration" do
|
||||||
@config.delete(:traefik)
|
@config.delete(:traefik)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user