lib/packaging/util/ship.rb in packaging-0.102.0 vs lib/packaging/util/ship.rb in packaging-0.103.0
- old
+ new
@@ -1,22 +1,16 @@
# Module for shipping all packages to places
-
-require 'English'
require 'tmpdir'
-
module Pkg::Util::Ship
module_function
- def collect_packages(pkg_exts, excludes = [])
+ def collect_packages(pkg_exts, excludes = []) # rubocop:disable Metrics/MethodLength
pkgs = pkg_exts.map { |ext| Dir.glob(ext) }.flatten
return [] if pkgs.empty?
-
- if excludes
- excludes.each do |exclude|
- pkgs.delete_if { |p| p.match(exclude) }
- end
- end
+ 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
@@ -63,57 +57,53 @@
# @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
def ship_pkgs(pkg_exts, staging_server, remote_path, opts = {})
options = {
excludes: [],
chattr: true,
platform_independent: false,
- nonfinal: false
- }.merge(opts)
+ 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]
- )
+ 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})?"
- return false unless Pkg::Util.ask_yes_or_no
+ if Pkg::Util.ask_yes_or_no
+ extra_flags = ['--ignore-existing', '--delay-updates']
+ extra_flags << '--dry-run' if ENV['DRYRUN']
- extra_flags = %w(--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
+ )
- 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]
+ 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
- return true
end
def ship_rpms(local_staging_directory, remote_path, opts = {})
things_to_ship = [
"#{local_staging_directory}/**/*.rpm",
@@ -131,149 +121,106 @@
"#{local_staging_directory}/**/*.changes"
]
ship_pkgs(things_to_ship, Pkg::Config.apt_signing_server, remote_path, opts)
end
-
-
def ship_svr4(local_staging_directory, remote_path, opts = {})
ship_pkgs(["#{local_staging_directory}/**/*.pkg.gz"], Pkg::Config.svr4_host, remote_path, opts)
end
def ship_p5p(local_staging_directory, remote_path, opts = {})
ship_pkgs(["#{local_staging_directory}/**/*.p5p"], Pkg::Config.p5p_host, remote_path, opts)
end
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
- )
+ packages_have_shipped = ship_pkgs(["#{local_staging_directory}/**/*.dmg"],
+ Pkg::Config.dmg_staging_server, remote_path, opts)
- return unless 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'
- )
+ 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
def ship_swix(local_staging_directory, remote_path, opts = {})
- ship_pkgs(
- ["#{local_staging_directory}/**/*.swix"],
- Pkg::Config.swix_staging_server,
- remote_path,
- opts
- )
+ ship_pkgs(["#{local_staging_directory}/**/*.swix"], Pkg::Config.swix_staging_server, remote_path, opts)
end
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
- )
- return unless packages_have_shipped
+ packages_have_shipped = ship_pkgs(["#{local_staging_directory}/**/*.msi"], Pkg::Config.msi_staging_server, remote_path, opts)
- # 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'
- )
+ 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
def ship_gem(local_staging_directory, remote_path, opts = {})
ship_pkgs(["#{local_staging_directory}/*.gem*"], Pkg::Config.gem_host, remote_path, opts)
end
def ship_tar(local_staging_directory, remote_path, opts = {})
- ship_pkgs(
- ["#{local_staging_directory}/*.tar.gz*"],
- Pkg::Config.tar_staging_server,
- remote_path,
- opts
- )
+ ship_pkgs(["#{local_staging_directory}/*.tar.gz*"], Pkg::Config.tar_staging_server, remote_path, opts)
end
def rolling_repo_link_command(platform_tag, repo_path, nonfinal = false)
- base_path, link_path = Pkg::Paths.artifacts_base_path_and_link_path(
- platform_tag,
- repo_path,
- nonfinal
- )
+ base_path, link_path = Pkg::Paths.artifacts_base_path_and_link_path(platform_tag, repo_path, nonfinal)
if link_path.nil?
puts "No link target set, not creating rolling repo link for #{base_path}"
return nil
end
+
+ cmd = <<-CMD
+ if [ ! -d #{base_path} ] ; then
+ echo "Link target '#{base_path}' does not exist; skipping"
+ exit 0
+ fi
+ # If it's a link but pointing to the wrong place, remove the link
+ # This is likely to happen around the transition times, like puppet5 -> puppet6
+ if [ -L #{link_path} ] && [ ! #{base_path} -ef #{link_path} ] ; then
+ rm #{link_path}
+ # This is the link you're looking for, nothing to see here
+ elif [ -L #{link_path} ] ; then
+ exit 0
+ # Don't want to delete it if it isn't a link, that could be destructive
+ # So, fail!
+ elif [ -e #{link_path} ] ; then
+ echo "#{link_path} exists but isn't a link, I don't know what to do with this" >&2
+ exit 1
+ fi
+ ln -s #{base_path} #{link_path}
+ CMD
end
def create_rolling_repo_link(platform_tag, staging_server, repo_path, nonfinal = false)
command = rolling_repo_link_command(platform_tag, repo_path, nonfinal)
Pkg::Util::Net.remote_execute(staging_server, command) unless command.nil?
- rescue StandardError => e
+ rescue => e
fail "Failed to create rolling repo link for '#{platform_tag}'.\n#{e}\n#{e.backtrace}"
end
# create all of the rolling repo links in one step
def create_rolling_repo_links(nonfinal = false)
yum_path = Pkg::Paths.remote_repo_base(nonfinal: nonfinal, package_format: 'rpm')
dmg_path = Pkg::Paths.remote_repo_base(nonfinal: nonfinal, package_format: 'dmg')
swix_path = Pkg::Paths.remote_repo_base(nonfinal: nonfinal, package_format: 'swix')
msi_path = Pkg::Paths.remote_repo_base(nonfinal: nonfinal, package_format: 'msi')
- create_rolling_repo_link(
- Pkg::Platforms.generic_platform_tag('el'),
- Pkg::Config.yum_staging_server,
- yum_path,
- nonfinal
- )
+ create_rolling_repo_link(Pkg::Platforms.generic_platform_tag('el'), Pkg::Config.yum_staging_server, yum_path, nonfinal)
+ create_rolling_repo_link(Pkg::Platforms.generic_platform_tag('osx'), Pkg::Config.dmg_staging_server, dmg_path, nonfinal)
+ create_rolling_repo_link(Pkg::Platforms.generic_platform_tag('eos'), Pkg::Config.swix_staging_server, swix_path, nonfinal)
+ create_rolling_repo_link(Pkg::Platforms.generic_platform_tag('windows'), Pkg::Config.msi_staging_server, msi_path, nonfinal)
- create_rolling_repo_link(
- Pkg::Platforms.generic_platform_tag('osx'),
- Pkg::Config.dmg_staging_server,
- dmg_path,
- nonfinal
- )
-
- create_rolling_repo_link(
- Pkg::Platforms.generic_platform_tag('eos'),
- Pkg::Config.swix_staging_server,
- swix_path,
- nonfinal
- )
-
- create_rolling_repo_link(
- Pkg::Platforms.generic_platform_tag('windows'),
- Pkg::Config.msi_staging_server,
- msi_path,
- nonfinal
- )
-
# We need to iterate through all the supported platforms here because of
# how deb repos are set up. Each codename will have its own link from the
# current versioned repo (e.g. puppet5) to the rolling repo. The one thing
# we don't care about is architecture, so we just grab the first supported
# architecture for the code name we're working with at the moment. [written
@@ -282,15 +229,10 @@
apt_path = Pkg::Config.apt_repo_staging_path
if nonfinal
apt_path = Pkg::Config.nonfinal_apt_repo_staging_path
end
Pkg::Platforms.codenames.each do |codename|
- create_rolling_repo_link(
- Pkg::Platforms.codename_to_tags(codename)[0],
- Pkg::Config.apt_signing_server,
- apt_path,
- nonfinal
- )
+ create_rolling_repo_link(Pkg::Platforms.codename_to_tags(codename)[0], Pkg::Config.apt_signing_server, apt_path, nonfinal)
end
end
def update_release_package_symlinks(local_staging_directory, nonfinal = false)
local_packages = collect_packages(["#{local_staging_directory}/**/*.rpm", "#{local_staging_directory}/**/*.deb"])