class Object

Constants

DEFAULT_FILE_TYPE

Public Instance Methods

add_network_config(container_config, cmd_options) click to toggle source
# 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
build_test_image(appliance_image_id, project_name, packages) click to toggle source
# File lib/conjur/debify.rb, line 511
      def build_test_image(appliance_image_id, project_name, packages)
        packages = packages.join " "
        dockerfile = <<-DOCKERFILE
FROM #{appliance_image_id}

COPY #{packages} /tmp/

RUN if dpkg --list | grep conjur-#{project_name}; then dpkg --force all --purge conjur-#{project_name}; fi
RUN if [ -f /opt/conjur/etc/#{project_name}.conf ]; then rm /opt/conjur/etc/#{project_name}.conf; fi
RUN cd /tmp; dpkg --install #{packages}

RUN touch /etc/service/conjur/down
        DOCKERFILE
        Dir.mktmpdir do |tmpdir|
          tmpfile = Tempfile.new('Dockerfile', tmpdir)
          File.write(tmpfile, dockerfile)
          dockerfile_name = File.basename(tmpfile.path)
          tar_cmd = "tar -cvzh -C #{tmpdir} #{dockerfile_name} -C #{Dir.pwd} #{packages}"
          tar = open("| #{tar_cmd}")
          begin
            Docker::Image.build_from_tar(tar, :dockerfile => dockerfile_name, &DebugMixin::DOCKER)
          ensure
            tar.close
          end
        end
      end
container_command(container, *args) click to toggle source
# 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) click to toggle source
# 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_version() click to toggle source
# 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_files() click to toggle source
# 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
ignore_file?(f) click to toggle source
# File lib/conjur/debify.rb, line 157
def ignore_file? f
  @ignore_list.find { |ignore| f.index(ignore) == 0 }
end
login_to_registry(appliance_image_id) click to toggle source
# File lib/conjur/debify.rb, line 103
def login_to_registry(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
looks_like_jenkins?() click to toggle source
# File lib/conjur/debify.rb, line 145
def looks_like_jenkins?
  require 'etc'
  Etc.getlogin == 'jenkins' && ENV['BUILD_NUMBER']
end
network_options(cmd) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

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

# 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) click to toggle source
# 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