Skip to content

Instantly share code, notes, and snippets.

@jmlagace
Last active April 12, 2018 16:38
Show Gist options
  • Save jmlagace/930f9166228613a234e6333705881ad4 to your computer and use it in GitHub Desktop.
Save jmlagace/930f9166228613a234e6333705881ad4 to your computer and use it in GitHub Desktop.
The ports allowing a docker swarm to communicate (to use only behind a firewall)
#!/bin/bash
ufw allow 2376/tcp
ufw allow 2377/tcp
ufw allow 7946
ufw allow 4789/udp
#
# Simple configuration for a TCP proxy
#
global
daemon
maxconn 256
resolvers dns
nameserver public-0 127.0.0.11:53
hold valid 5s
defaults
mode tcp
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
<% @entries.each do |entry| %>
frontend in-<%= entry[:publicport] %>
bind *:<%= entry[:publicport] %>
default_backend out-<%= entry[:publicport] %>
backend out-<%= entry[:publicport] %>
server server <%= entry[:privatehost] %>:<%= entry[:privateport] %> maxconn 100 resolvers dns init-addr libc,none check
<% end %>
#
# Generate configuration file using an array and a template
#
require 'erb'
class Config
def initialize(configFile, templateFile)
@configFile = configFile
@template = ERB.new(File.read(templateFile))
end
def render
@entries = []
File.open(@configFile) { |f|
f.readlines.each {|lines|
entry = lines.split("\t")
@entries << {
privatehost: entry[0].strip,
privateport: entry[1].strip,
publicport: entry[2].strip
}
}
}
@template.result(binding())
end
end
puts Config.new("rawconfig.txt","haproxy.cfg.template.erb").render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment