Top Level Namespace

Includes:
GLI::App

Defined Under Namespace

Modules: Conjur, DebugMixin

Instance Method Summary collapse

Instance Method Details

#add_network_config(container_config, cmd_options) ⇒ Object



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/conjur/debify.rb', line 334

def add_network_config(container_config, cmd_options)
  host_config = container_config['HostConfig']
  has_links = cmd_options[:link] && !cmd_options[:link].empty?
  net_name = cmd_options[:net]
  if net_name
    host_config['NetworkMode'] = net_name
    if has_links
      container_config['NetworkingConfig'] ||= {}
      container_config['NetworkingConfig'].deep_merge!(
        'EndpointsConfig' => {
          net_name => {
            'Links' => cmd_options[:link].collect(&method(:shorten_source_id))
          }
        }
      )
    end
  elsif has_links
    # Don't shorten source ids here
    host_config['Links'] = cmd_options[:link]
  end
end

#container_command(container, *args) ⇒ Object



296
297
298
299
300
# File 'lib/conjur/debify.rb', line 296

def container_command container, *args
  stdout, stderr, exitcode = container.exec args, &DebugMixin::DOCKER
  exit_now! "Command failed : #{args.join(' ')}", exitcode unless exitcode == 0
  stdout
end

#detect_versionObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/conjur/debify.rb', line 77

def detect_version
  if File.exists?("VERSION") && !(base_commit = `git log --pretty='%h' VERSION | head -n 1`.strip).empty?
    base_version = File.read("VERSION").strip
    commits_since = `git log #{base_commit}..HEAD --pretty='%h'`.split("\n").size
    hash = `git rev-parse --short HEAD`.strip
    [ [ base_version, commits_since ].join('.'), hash ].join("-")
  else
    `git describe --long --tags --abbrev=7 --match 'v*.*.*' | sed -e 's/^v//'`.strip.tap do |version|
      raise "No Git version (tag) for project" if version.empty?
    end
  end
end

#git_filesObject



90
91
92
# File 'lib/conjur/debify.rb', line 90

def git_files
  (`git ls-files -z`.split("\x0") + ['Gemfile.lock']).uniq
end

#login_to_registry(appliance_image_id) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/conjur/debify.rb', line 94

def (appliance_image_id)
  config_file = File.expand_path('~/.docker/config.json')
  if File.exist? config_file
    json_config = JSON.parse(File.read(config_file))
    registry = appliance_image_id.split('/')[0]

    json_auth = json_config['auths'][registry]['auth']
    if json_auth
      username, password = Base64.decode64(json_auth).split(':')
      Docker.authenticate! username: username, password: password, serveraddress: registry
    end
  end
end

#network_options(cmd) ⇒ Object



309
310
311
312
313
314
315
# File 'lib/conjur/debify.rb', line 309

def network_options(cmd)
  cmd.desc "Specify link for test container"
  cmd.flag [ :l, :link ], :multiple => true
  
  cmd.desc 'Attach to the specified network'
  cmd.flag [ :n, :net ]
end

#short_id(id) ⇒ Object



317
318
319
320
321
322
323
324
# File 'lib/conjur/debify.rb', line 317

def short_id(id)
  if id =~ /\A[0-9a-f]{64}\z/ # 64 hex digits, docker only allows lower case letters in ids
    $stderr.puts "Warning: found full container id, using short id instead (#{id[0..11]} for #{id})"
    id[0..11]
  else
    id
  end
end

#shorten_source_id(link) ⇒ Object

If the source of the link is a full container id, use the short id instead. (Docker doesn’t add full container ids as network aliases, only short ids).



329
330
331
332
# File 'lib/conjur/debify.rb', line 329

def shorten_source_id(link)
  src,dest = link.split(':')
  src && dest ? "#{short_id(src)}:#{dest}" : link
end

#wait_for_conjur(appliance_image, container) ⇒ Object



302
303
304
305
306
307
# File 'lib/conjur/debify.rb', line 302

def wait_for_conjur appliance_image, container
  container_command container, '/opt/conjur/evoke/bin/wait_for_conjur'
rescue
  $stderr.puts container.logs
  raise
end