Created
November 19, 2014 06:09
-
-
Save geetfun/ed7d07769191acc8e9d6 to your computer and use it in GitHub Desktop.
Ruby shell script to generate nginx.conf from docker containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream propertypub { | |
<% ip_addresses_for_web_containers.each do |ip_address| %> | |
server <%= ip_address %>:80; | |
<% end %> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'erb' | |
containers = `docker ps` | |
containers_array = containers.split | |
containers = containers_array.select { |string| string.include?('app_web_') } | |
ip_addresses_for_web_containers = [] | |
if !containers.empty? | |
containers.each do |c| | |
ip_address = `docker inspect #{c} | grep IPAddress | cut -d '"' -f 4` | |
ip_address = ip_address.delete("\n") | |
ip_addresses_for_web_containers << ip_address | |
end | |
end | |
conf_template = File.read("nginx.conf.erb") | |
erb = ERB.new(conf_template) | |
conf = erb.result(binding) | |
File.open("nginx.conf", "w") do |file| | |
file.puts(conf) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment