Top Level Namespace

Includes:
GLI::App

Defined Under Namespace

Modules: Conjur, DebugMixin

Constant Summary collapse

DEFAULT_FILE_TYPE =
"deb"

Instance Method Summary collapse

Instance Method Details

#add_network_config(container_config, cmd_options) ⇒ Object



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/conjur/debify.rb', line 411

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



373
374
375
376
377
# File 'lib/conjur/debify.rb', line 373

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

#copy_packages_from_container(container, package_name, dev_package_name) ⇒ Object



208
209
210
211
212
213
214
215
216
217
# File 'lib/conjur/debify.rb', line 208

def copy_packages_from_container(container, package_name, dev_package_name)
  Conjur::Debify::Utils.copy_from_container container, "/src/#{package_name}"
  puts "#{package_name}"
  begin
    Conjur::Debify::Utils.copy_from_container container, "/dev-pkg/#{dev_package_name}"
    puts "#{dev_package_name}"
  rescue Docker::Error::NotFoundError
    warn "#{dev_package_name} not found. The package might not have any development dependencies."
  end
end

#detect_versionObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/conjur/debify.rb', line 80

def detect_version
  if File.exist?("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



93
94
95
96
97
98
99
100
101
# File 'lib/conjur/debify.rb', line 93

def git_files
  files = (`git ls-files -z`.split("\x0") + ['Gemfile.lock', 'VERSION']).uniq
  # Since submodule directories are listed, but are not files, we remove them.
  # Currently, `conjur-project-config` is the only submodule in Conjur, and it
  # can safely be removed because it's a developer-only tool.  If we add another
  # submodule in the future needed for production, we'll need to update this
  # code.  But YAGNI for now.
  files.select { |f| File.file?(f) }
end

#login_to_registry(appliance_image_id) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/conjur/debify.rb', line 103

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



386
387
388
389
390
391
392
# File 'lib/conjur/debify.rb', line 386

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



394
395
396
397
398
399
400
401
# File 'lib/conjur/debify.rb', line 394

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).



406
407
408
409
# File 'lib/conjur/debify.rb', line 406

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

#wait_for_conjur(appliance_image, container) ⇒ Object



379
380
381
382
383
384
# File 'lib/conjur/debify.rb', line 379

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