Skip to content

Commit

Permalink
Added the additional_ports configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
stepbeekio committed Mar 14, 2023
1 parent c282461 commit 43a1b42
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions lib/mrsk/commands/traefik.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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: "="
Expand Down
11 changes: 11 additions & 0 deletions test/commands/traefik_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 43a1b42

Please sign in to comment.