module Pkg::Util::Ship

Public Instance Methods

collect_packages(pkg_exts, excludes = []) click to toggle source
# File lib/packaging/util/ship.rb, line 6
def collect_packages(pkg_exts, excludes = []) # rubocop:disable Metrics/MethodLength
  pkgs = pkg_exts.map { |ext| Dir.glob(ext) }.flatten
  return [] if pkgs.empty?
  excludes.each do |exclude|
    pkgs.delete_if { |p| p.match(exclude) }
  end if excludes
  if pkgs.empty?
    $stdout.puts "No packages with (#{pkg_exts.join(', ')}) extensions found staged in 'pkg'"
    $stdout.puts "Maybe your excludes argument (#{excludes}) is too restrictive?"
  end
  pkgs
end
reorganize_packages(pkgs, tmp, platform_independent = false, nonfinal = false) click to toggle source

Takes a set of packages and reorganizes them into the final repo structure before they are shipping out to their final destination.

This assumes the working directory is a temporary directory that will later be cleaned up

If this is platform_independent the packages will not get reorganized, just copied under the tmp directory for more consistent workflows

# File lib/packaging/util/ship.rb, line 27
def reorganize_packages(pkgs, tmp, platform_independent = false, nonfinal = false)
  new_pkgs = []
  pkgs.each do |pkg|
    if platform_independent
      path = 'pkg'
    else
      platform_tag = Pkg::Paths.tag_from_artifact_path(pkg)
      path = Pkg::Paths.artifacts_path(platform_tag, 'pkg', nonfinal)
    end
    FileUtils.mkdir_p File.join(tmp, path)
    FileUtils.cp pkg, File.join(tmp, path)
    new_pkgs << File.join(path, File.basename(pkg))
  end
  new_pkgs
end
ship_debs(local_staging_directory, remote_path, opts = {}) click to toggle source
# File lib/packaging/util/ship.rb, line 115
def ship_debs(local_staging_directory, remote_path, opts = {})
  things_to_ship = [
    "#{local_staging_directory}/**/*.debian.tar.gz",
    "#{local_staging_directory}/**/*.orig.tar.gz",
    "#{local_staging_directory}/**/*.dsc",
    "#{local_staging_directory}/**/*.deb",
    "#{local_staging_directory}/**/*.changes"
  ]
  ship_pkgs(things_to_ship, Pkg::Config.apt_signing_server, remote_path, opts)
end
ship_dmg(local_staging_directory, remote_path, opts = {}) click to toggle source
# File lib/packaging/util/ship.rb, line 134
def ship_dmg(local_staging_directory, remote_path, opts = {})
  packages_have_shipped = ship_pkgs(["#{local_staging_directory}/**/*.dmg"],
                                    Pkg::Config.dmg_staging_server, remote_path, opts)

  if packages_have_shipped
    Pkg::Platforms.platform_tags_for_package_format('dmg').each do |platform_tag|
      # Create the latest symlink for the current supported repo
      Pkg::Util::Net.remote_create_latest_symlink(
        Pkg::Config.project,
        Pkg::Paths.artifacts_path(platform_tag, remote_path, opts[:nonfinal]),
        'dmg'
      )
    end
  end
end
ship_gem(local_staging_directory, remote_path, opts = {}) click to toggle source
# File lib/packaging/util/ship.rb, line 164
def ship_gem(local_staging_directory, remote_path, opts = {})
  ship_pkgs(["#{local_staging_directory}/*.gem*"], Pkg::Config.gem_host, remote_path, opts)
end
ship_msi(local_staging_directory, remote_path, opts = {}) click to toggle source
# File lib/packaging/util/ship.rb, line 154
def ship_msi(local_staging_directory, remote_path, opts = {})
  packages_have_shipped = ship_pkgs(["#{local_staging_directory}/**/*.msi"], Pkg::Config.msi_staging_server, remote_path, opts)

  if packages_have_shipped
    # Create the symlinks for the latest supported repo
    Pkg::Util::Net.remote_create_latest_symlink(Pkg::Config.project, Pkg::Paths.artifacts_path(Pkg::Platforms.generic_platform_tag('windows'), remote_path, opts[:nonfinal]), 'msi', arch: 'x64')
    Pkg::Util::Net.remote_create_latest_symlink(Pkg::Config.project, Pkg::Paths.artifacts_path(Pkg::Platforms.generic_platform_tag('windows'), remote_path, opts[:nonfinal]), 'msi', arch: 'x86')
  end
end
ship_p5p(local_staging_directory, remote_path, opts = {}) click to toggle source
# File lib/packaging/util/ship.rb, line 130
def ship_p5p(local_staging_directory, remote_path, opts = {})
  ship_pkgs(["#{local_staging_directory}/**/*.p5p"], Pkg::Config.p5p_host, remote_path, opts)
end
ship_pkgs(pkg_exts, staging_server, remote_path, opts = {}) click to toggle source

Take local packages and restructure them to the desired final path before shipping to the staging server @param [Array] pkg_exts the file globs for the files you want to ship

For example, something like ['pkg/**/*.rpm', 'pkg/**/*.deb'] to ship
the rpms and debs

@param [String] staging_server The hostname to ship the packages to @param [String] remote_path The base path to ship the packages to on the

staging_server, for example '/opt/downloads/windows' or
'/opt/repository/yum'

@param [Hash] opts Additional options that can be used when shipping

packages

@option opts [Array] :excludes File globs to exclude packages from shipping @option opts [Boolean] :chattr Whether or not to make the files immutable

after shipping. Defaults to true.

@option opts [Boolean] :platform_independent Whether or not the path the

packages ship to has platform-dependent information in it. Defaults to
false (most paths will be platform dependent), but set to true for gems
and tarballs since those just land directly under /opt/downloads/<project>

rubocop:disable Metrics/MethodLength, Metrics/AbcSize

# File lib/packaging/util/ship.rb, line 63
def ship_pkgs(pkg_exts, staging_server, remote_path, opts = {})
  options = {
    excludes: [],
    chattr: true,
    platform_independent: false,
    nonfinal: false }.merge(opts)

  # First find the packages to be shipped. We must find them before moving
  # to our temporary staging directory
  local_packages = collect_packages(pkg_exts, options[:excludes])
  return false if local_packages.empty?

  tmpdir = Dir.mktmpdir
  staged_pkgs = reorganize_packages(local_packages, tmpdir, options[:platform_independent], options[:nonfinal])

  puts staged_pkgs.sort
  puts "Do you want to ship the above files to (#{staging_server})?"
  if Pkg::Util.ask_yes_or_no
    extra_flags = ['--ignore-existing', '--delay-updates']
    extra_flags << '--dry-run' if ENV['DRYRUN']

    staged_pkgs.each do |pkg|
      Pkg::Util::Execution.retry_on_fail(times: 3) do
        sub_string = 'pkg'
        remote_pkg = pkg.sub(sub_string, remote_path)
        remote_basepath = File.dirname(remote_pkg)
        Pkg::Util::Net.remote_execute(staging_server, "mkdir -p #{remote_basepath}")
        Pkg::Util::Net.rsync_to(
          File.join(tmpdir, pkg),
          staging_server,
          remote_basepath,
          extra_flags: extra_flags
        )

        Pkg::Util::Net.remote_set_ownership(staging_server, 'root', 'release', [remote_basepath, remote_pkg])
        Pkg::Util::Net.remote_set_permissions(staging_server, '775', [remote_basepath])
        Pkg::Util::Net.remote_set_permissions(staging_server, '0664', [remote_pkg])
        Pkg::Util::Net.remote_set_immutable(staging_server, [remote_pkg]) if options[:chattr]
      end
    end
    return true
  end
end
ship_rpms(local_staging_directory, remote_path, opts = {}) click to toggle source
# File lib/packaging/util/ship.rb, line 107
def ship_rpms(local_staging_directory, remote_path, opts = {})
  things_to_ship = [
    "#{local_staging_directory}/**/*.rpm",
    "#{local_staging_directory}/**/*.srpm"
  ]
  ship_pkgs(things_to_ship, Pkg::Config.yum_staging_server, remote_path, opts)
end
ship_svr4(local_staging_directory, remote_path, opts = {}) click to toggle source
# File lib/packaging/util/ship.rb, line 126
def ship_svr4(local_staging_directory, remote_path, opts = {})
  ship_pkgs(["#{local_staging_directory}/**/*.pkg.gz"], Pkg::Config.svr4_host, remote_path, opts)
end
ship_swix(local_staging_directory, remote_path, opts = {}) click to toggle source
# File lib/packaging/util/ship.rb, line 150
def ship_swix(local_staging_directory, remote_path, opts = {})
  ship_pkgs(["#{local_staging_directory}/**/*.swix"], Pkg::Config.swix_staging_server, remote_path, opts)
end
ship_tar(local_staging_directory, remote_path, opts = {}) click to toggle source
# File lib/packaging/util/ship.rb, line 168
def ship_tar(local_staging_directory, remote_path, opts = {})
  ship_pkgs(["#{local_staging_directory}/*.tar.gz*"], Pkg::Config.tar_staging_server, remote_path, opts)
end
test_ship(vm, ship_task) click to toggle source
# File lib/packaging/util/ship.rb, line 272
def test_ship(vm, ship_task)
  command = 'getent group release || groupadd release'
  Pkg::Util::Net.remote_execute(vm, command)
  hosts_to_override = %w(
    APT_HOST
    DMG_HOST
    GEM_HOST
    IPS_HOST
    MSI_HOST
    P5P_HOST
    SVR4_HOST
    SWIX_HOST
    TAR_HOST
    YUM_HOST
    APT_SIGNING_SERVER
    APT_STAGING_SERVER
    DMG_STAGING_SERVER
    MSI_STAGING_SERVER
    SWIX_STAGING_SERVER
    TAR_STAGING_SERVER
    YUM_STAGING_SERVER
    STAGING_SERVER
  )
  hosts_to_override.each do |host|
    ENV[host] = vm
  end
  Rake::Task[ship_task].invoke
end