forked from newrelic/centurion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request newrelic#99 from OpenSourceProjects/dry_run
Offer dry-run capability. Finally getting this merged @frankywahl . Thanks!
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Centurion | ||
class Mock | ||
def initialize(opts) | ||
environment = opts[:current_environment] | ||
@options = opts[environment] | ||
end | ||
|
||
def run | ||
require 'pry-byebug' | ||
|
||
result = hosts.map do |host| | ||
string = "docker -H=tcp://#{host}:2375 run" | ||
|
||
string << environment_vars unless env_vars.empty? | ||
string << ports_vars unless ports_vars.empty? | ||
end.join("\n\n\n ******* \n\n\n") | ||
puts "#{result}" | ||
end | ||
|
||
private | ||
|
||
attr_reader :options | ||
|
||
|
||
def env_vars | ||
options[:env_vars] | ||
end | ||
|
||
def environment_vars | ||
env_vars.reduce('') { |string, (k, v)| " -e #{k.split('"')[0]}='#{v}'#{string}" }.rstrip | ||
end | ||
|
||
def ports | ||
options[:port_bindings] | ||
end | ||
|
||
def hosts | ||
options[:hosts] | ||
end | ||
|
||
def ports_vars | ||
ports.reduce('') do |string, (host_port_protocol, container_port)| | ||
h = host_port_protocol.split('/') | ||
c = container_port.first['HostPort'] | ||
" -p #{h[0]}:#{c}/#{h[1]}#{string}" | ||
end.rstrip | ||
end | ||
end | ||
end |