Skip to content

Commit

Permalink
Added volume configuration in response to issue coments
Browse files Browse the repository at this point in the history
  • Loading branch information
stepbeekio committed Mar 14, 2023
1 parent df91325 commit 2cac6d0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
35 changes: 24 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,21 +408,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:

Expand All @@ -437,9 +447,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
Expand Down
14 changes: 11 additions & 3 deletions lib/mrsk/commands/traefik.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def run
"--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",
Expand Down Expand Up @@ -55,13 +55,21 @@ def port

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.raw_config.dig(:traefik, "args")
optionize args
Expand Down
24 changes: 23 additions & 1 deletion test/commands/traefik_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2cac6d0

Please sign in to comment.