packaging 0.88.77 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +128 -74
  3. data/lib/packaging/artifactory.rb +60 -433
  4. data/lib/packaging/config/params.rb +7 -28
  5. data/lib/packaging/config.rb +50 -150
  6. data/lib/packaging/deb/repo.rb +19 -20
  7. data/lib/packaging/gem.rb +83 -41
  8. data/lib/packaging/ips.rb +57 -0
  9. data/lib/packaging/msi.rb +89 -0
  10. data/lib/packaging/nuget.rb +1 -1
  11. data/lib/packaging/osx.rb +36 -0
  12. data/lib/packaging/paths.rb +87 -225
  13. data/lib/packaging/platforms.rb +416 -443
  14. data/lib/packaging/repo.rb +22 -122
  15. data/lib/packaging/retrieve.rb +7 -36
  16. data/lib/packaging/rpm/repo.rb +8 -5
  17. data/lib/packaging/tar.rb +0 -9
  18. data/lib/packaging/util/date.rb +0 -5
  19. data/lib/packaging/util/execution.rb +2 -2
  20. data/lib/packaging/util/git.rb +1 -1
  21. data/lib/packaging/util/gpg.rb +1 -5
  22. data/lib/packaging/util/net.rb +37 -79
  23. data/lib/packaging/util/rake_utils.rb +0 -1
  24. data/lib/packaging/util/ship.rb +13 -142
  25. data/lib/packaging/util/tool.rb +1 -1
  26. data/lib/packaging/util/version.rb +0 -8
  27. data/lib/packaging/util.rb +2 -2
  28. data/lib/packaging.rb +3 -3
  29. data/spec/fixtures/config/params.yaml +2 -0
  30. data/spec/lib/packaging/artifactory_spec.rb +16 -66
  31. data/spec/lib/packaging/config_spec.rb +29 -49
  32. data/spec/lib/packaging/deb/repo_spec.rb +7 -16
  33. data/spec/lib/packaging/paths_spec.rb +56 -321
  34. data/spec/lib/packaging/platforms_spec.rb +21 -46
  35. data/spec/lib/packaging/repo_spec.rb +40 -78
  36. data/spec/lib/packaging/retrieve_spec.rb +8 -47
  37. data/spec/lib/packaging/rpm/repo_spec.rb +4 -4
  38. data/spec/lib/packaging/tar_spec.rb +40 -34
  39. data/spec/lib/packaging/util/git_tag_spec.rb +1 -1
  40. data/spec/lib/packaging/util/gpg_spec.rb +1 -1
  41. data/spec/lib/packaging/util/net_spec.rb +15 -35
  42. data/spec/lib/packaging/util/ship_spec.rb +63 -145
  43. data/spec/spec_helper.rb +14 -0
  44. data/tasks/00_utils.rake +6 -4
  45. data/tasks/apple.rake +0 -2
  46. data/tasks/config.rake +0 -5
  47. data/tasks/education.rake +5 -5
  48. data/tasks/fetch.rake +14 -17
  49. data/tasks/gem.rake +121 -134
  50. data/tasks/jenkins.rake +7 -51
  51. data/tasks/nightly_repos.rake +69 -20
  52. data/tasks/pe_ship.rake +11 -16
  53. data/tasks/retrieve.rake +6 -13
  54. data/tasks/ship.rake +256 -196
  55. data/tasks/sign.rake +135 -63
  56. data/tasks/tar.rake +6 -0
  57. data/templates/packaging.xml.erb +7 -9
  58. data/templates/repo.xml.erb +3 -6
  59. metadata +27 -80
  60. data/lib/packaging/archive.rb +0 -126
  61. data/lib/packaging/artifactory/extensions.rb +0 -94
  62. data/lib/packaging/config/validations.rb +0 -13
  63. data/lib/packaging/metrics.rb +0 -15
  64. data/lib/packaging/sign/deb.rb +0 -9
  65. data/lib/packaging/sign/dmg.rb +0 -41
  66. data/lib/packaging/sign/ips.rb +0 -57
  67. data/lib/packaging/sign/msi.rb +0 -124
  68. data/lib/packaging/sign/rpm.rb +0 -115
  69. data/lib/packaging/sign.rb +0 -8
  70. data/spec/lib/packaging/gem_spec.rb +0 -86
  71. data/spec/lib/packaging/sign_spec.rb +0 -133
  72. data/tasks/archive.rake +0 -69
@@ -1,108 +1,35 @@
1
1
  module Pkg::Repo
2
2
 
3
3
  class << self
4
-
5
- ##
6
- ## Construct a local_target based upon the versioning style
7
- ##
8
- def construct_local_target_path(project, versioning)
9
- case versioning
10
- when 'ref'
11
- return File.join(project, Pkg::Config.ref)
12
- when 'version'
13
- return File.join(project, Pkg::Util::Version.dot_version)
14
- else
15
- fail "Error: Unknown versioning argument: #{versioning}"
16
- end
17
- end
18
-
19
- ##
20
- ## Put a single signed repo into a tarball stored in
21
- ## 'pkg/<local_target>/<archive_name>.tar.gz'
22
- ##
23
- def create_signed_repo_archive(repo_location, archive_name, versioning)
4
+ def create_signed_repo_archive(path_to_repo, name_of_archive, versioning)
24
5
  tar = Pkg::Util::Tool.check_tool('tar')
25
-
26
- local_target = construct_local_target_path(Pkg::Config.project, versioning)
27
-
28
- if Pkg::Util::File.empty_dir?(File.join('pkg', local_target, repo_location))
29
- if ENV['FAIL_ON_MISSING_TARGET'] == "true"
30
- raise "Error: missing packages under #{repo_location}"
6
+ Dir.chdir("pkg") do
7
+ if versioning == 'ref'
8
+ local_target = File.join(Pkg::Config.project, Pkg::Config.ref)
9
+ elsif versioning == 'version'
10
+ local_target = File.join(Pkg::Config.project, Pkg::Util::Version.dot_version)
31
11
  end
32
- warn "Warn: Skipping #{archive_name} because #{repo_location} has no files"
33
- return
34
- end
35
-
36
- Dir.chdir(File.join('pkg', local_target)) do
37
- puts "Info: Archiving #{repo_location} as #{archive_name}"
38
- target_tarball = File.join('repos', "#{archive_name}.tar.gz")
39
- tar_command = "#{tar} --owner=0 --group=0 --create --gzip --file #{target_tarball} #{repo_location}"
40
- stdout, _, _ = Pkg::Util::Execution.capture3(tar_command)
41
- return stdout
42
- end
43
- end
44
-
45
- ##
46
- ## Add a single repo tarball into the 'all' tarball located in
47
- ## 'pkg/<local_target>/<project>-all.tar'
48
- ## Create the 'all' tarball if needed.
49
- ##
50
- def update_tarball_of_all_repos(project, platform, versioning)
51
- tar = Pkg::Util::Tool.check_tool('tar')
52
-
53
- all_repos_tarball_name = "#{project}-all.tar"
54
- archive_name = "#{project}-#{platform['name']}"
55
- local_target = construct_local_target_path(project, versioning)
56
- repo_tarball_name = "#{archive_name}.tar.gz"
57
- repo_tarball_path = File.join('repos', repo_tarball_name)
58
-
59
- Dir.chdir(File.join('pkg', local_target)) do
60
- unless Pkg::Util::File.exist?(repo_tarball_path)
61
- warn "Skipping #{archive_name} because it (#{repo_tarball_path}) contains no files"
62
- next
12
+ Dir.chdir(local_target) do
13
+ if Pkg::Util::File.empty_dir?(path_to_repo)
14
+ if ENV['FAIL_ON_MISSING_TARGET'] == "true"
15
+ raise "ERROR: missing packages under #{path_to_repo}"
16
+ else
17
+ warn "Skipping #{name_of_archive} because #{path_to_repo} has no files"
18
+ end
19
+ else
20
+ puts "Archiving #{path_to_repo} as #{name_of_archive}"
21
+ stdout, _, _ = Pkg::Util::Execution.capture3("#{tar} --owner=0 --group=0 --create --gzip --file #{File.join('repos', "#{name_of_archive}.tar.gz")} #{path_to_repo}")
22
+ stdout
23
+ end
63
24
  end
64
-
65
- tar_action = "--create"
66
- if File.exist?(all_repos_tarball_name)
67
- tar_action = "--update"
68
- end
69
-
70
- tar_command = "#{tar} --owner=0 --group=0 #{tar_action} --file #{all_repos_tarball_name} #{repo_tarball_path}"
71
- stdout, _, _ = Pkg::Util::Execution.capture3(tar_command)
72
- puts stdout
73
25
  end
74
26
  end
75
27
 
76
- ##
77
- ## Invoke gzip to compress the 'all' tarball located in
78
- ## 'pkg/<local_target>/<project>-all.tar'
79
- ##
80
- def compress_tarball_of_all_repos(all_repos_tarball_name)
81
- gzip = Pkg::Util::Tool.check_tool('gzip')
82
-
83
- gzip_command = "#{gzip} --fast #{all_repos_tarball_name}"
84
- stdout, _, _ = Pkg::Util::Execution.capture3(gzip_command)
85
- puts stdout
86
- end
87
-
88
- ##
89
- ## Generate each of the repos listed in <Config.platform_repos>.
90
- ## Update the 'all repos' tarball as we do each one.
91
- ## Compress the 'all repos' tarball when all the repos have been generated
92
- ##
93
28
  def create_all_repo_archives(project, versioning)
94
29
  platforms = Pkg::Config.platform_repos
95
- local_target = construct_local_target_path(project, versioning)
96
- all_repos_tarball_name = "#{project}-all.tar"
97
-
98
30
  platforms.each do |platform|
99
31
  archive_name = "#{project}-#{platform['name']}"
100
32
  create_signed_repo_archive(platform['repo_location'], archive_name, versioning)
101
- update_tarball_of_all_repos(project, platform, versioning)
102
- end
103
-
104
- Dir.chdir(File.join('pkg', local_target)) do
105
- compress_tarball_of_all_repos(all_repos_tarball_name)
106
33
  end
107
34
  end
108
35
 
@@ -110,46 +37,19 @@ module Pkg::Repo
110
37
  cmd = "[ -d #{artifact_directory} ] || exit 1 ; "
111
38
  cmd << "pushd #{artifact_directory} > /dev/null && "
112
39
  cmd << "find . -name '*.#{pkg_ext}' -print0 | xargs --no-run-if-empty -0 -I {} dirname {} "
113
- stdout, _ = Pkg::Util::Net.remote_execute(
114
- Pkg::Config.distribution_server,
115
- cmd,
116
- { capture_output: true }
117
- )
40
+ stdout, stderr = Pkg::Util::Net.remote_ssh_cmd(Pkg::Config.distribution_server, cmd, true)
118
41
  return stdout.split
119
42
  rescue => e
120
- fail "Error: Could not retrieve directories that contain #{pkg_ext} packages in #{Pkg::Config.distribution_server}:#{artifact_directory}"
43
+ fail "Could not retrieve directories that contain #{pkg_ext} packages in #{Pkg::Config.distribution_server}:#{artifact_directory}"
121
44
  end
122
45
 
123
46
  def populate_repo_directory(artifact_parent_directory)
124
47
  cmd = "[ -d #{artifact_parent_directory}/artifacts ] || exit 1 ; "
125
48
  cmd << "pushd #{artifact_parent_directory} > /dev/null && "
126
49
  cmd << 'rsync --archive --verbose --one-file-system --ignore-existing artifacts/ repos/ '
127
- Pkg::Util::Net.remote_execute(Pkg::Config.distribution_server, cmd)
50
+ Pkg::Util::Net.remote_ssh_cmd(Pkg::Config.distribution_server, cmd)
128
51
  rescue => e
129
- fail "Error: Could not populate repos directory in #{Pkg::Config.distribution_server}:#{artifact_parent_directory}"
130
- end
131
-
132
- def argument_required?(argument_name, repo_command)
133
- repo_command.include?("__#{argument_name.upcase}__")
134
- end
135
-
136
- def update_repo(remote_host, command, options = {})
137
- fail_message = "Error: Missing required argument '%s', update your build_defaults?"
138
- [:repo_name, :repo_path, :repo_host, :repo_url].each do |option|
139
- fail fail_message % option.to_s if argument_required?(option.to_s, command) && !options[option]
140
- end
141
-
142
- whitelist = {
143
- __REPO_NAME__: options[:repo_name],
144
- __REPO_PATH__: options[:repo_path],
145
- __REPO_HOST__: options[:repo_host],
146
- __REPO_URL__: options[:repo_url],
147
- __APT_PLATFORMS__: Pkg::Config.apt_releases.join(' '),
148
- __GPG_KEY__: Pkg::Util::Gpg.key
149
- }
150
- Pkg::Util::Net.remote_execute(
151
- remote_host,
152
- Pkg::Util::Misc.search_and_replace(command, whitelist))
52
+ fail "Could not populate repos directory in #{Pkg::Config.distribution_server}:#{artifact_parent_directory}"
153
53
  end
154
54
  end
155
55
  end
@@ -8,37 +8,9 @@ module Pkg::Retrieve
8
8
  # --directory-prefix = where to save to disk (defaults to ./)
9
9
  # --reject = Reject all hits that match the supplied regex
10
10
 
11
- def default_wget_command(local_target, url, additional_options = {})
12
- default_options = {
13
- 'quiet' => true,
14
- 'recursive' => true,
15
- 'no-parent' => true,
16
- 'no-host-directories' => true,
17
- 'level' => 0,
18
- 'cut-dirs' => 3,
19
- 'directory-prefix' => local_target,
20
- 'reject' => "'index*'",
21
- }
22
- options = default_options.merge(additional_options)
11
+ def default_wget(local_target, url)
23
12
  wget = Pkg::Util::Tool.check_tool('wget')
24
- wget_command = wget
25
- options.each do |option, value|
26
- next unless value
27
- if value.is_a?(TrueClass)
28
- wget_command << " --#{option}"
29
- else
30
- wget_command << " --#{option}=#{value}"
31
- end
32
- end
33
- wget_command << " #{url}"
34
- return wget_command
35
- end
36
-
37
- # NOTE: When supplying additional options, if you want your value to be
38
- # quoted (e.g. --reject='index*'), you must include the quotes as part of
39
- # your string (e.g. {'reject' => "'index*'"}).
40
- def default_wget(local_target, url, additional_options = {})
41
- wget_command = default_wget_command(local_target, url, additional_options)
13
+ wget_command = "#{wget} --quiet --recursive --no-parent --no-host-directories --level=0 --cut-dirs 3 --directory-prefix=#{local_target} --reject 'index*' #{url}"
42
14
  puts "Executing #{wget_command} . . ."
43
15
  %x(#{wget_command})
44
16
  end
@@ -48,25 +20,24 @@ module Pkg::Retrieve
48
20
  unless Pkg::Config.foss_platforms
49
21
  fail "FOSS_ONLY specified, but I don't know anything about FOSS_PLATFORMS. Retrieve cancelled."
50
22
  end
51
- default_wget(local_target, "#{build_url}/", { 'level' => 1 })
23
+ default_wget(local_target, "#{build_url}/artifacts/#{Pkg::Config.ref}.yaml")
52
24
  yaml_path = File.join(local_target, "#{Pkg::Config.ref}.yaml")
53
25
  unless File.readable?(yaml_path)
54
26
  fail "Couldn't read #{Pkg::Config.ref}.yaml, which is necessary for FOSS_ONLY. Retrieve cancelled."
55
27
  end
56
28
  platform_data = Pkg::Util::Serialization.load_yaml(yaml_path)[:platform_data]
57
29
  platform_data.each do |platform, paths|
58
- path_to_retrieve = File.dirname(paths[:artifact])
59
- default_wget(local_target, "#{build_url}/#{path_to_retrieve}/") if Pkg::Config.foss_platforms.include?(platform)
30
+ default_wget(local_target, "#{build_url}/artifacts/#{paths[:artifact]}") if Pkg::Config.foss_platforms.include?(platform)
60
31
  end
61
32
  end
62
33
 
63
- def retrieve_all(build_url, rsync_path, local_target)
34
+ def retrieve_all(build_url, rsync_path, remote_target, local_target)
64
35
  if Pkg::Util::Tool.find_tool("wget")
65
- default_wget(local_target, "#{build_url}/")
36
+ default_wget(local_target, "#{build_url}/#{remote_target}/")
66
37
  else
67
38
  warn "Could not find `wget` tool. Falling back to rsyncing from #{Pkg::Config.distribution_server}."
68
39
  begin
69
- Pkg::Util::Net.rsync_from("#{rsync_path}/", Pkg::Config.distribution_server, "#{local_target}/")
40
+ Pkg::Util::Net.rsync_from("#{rsync_path}/#{remote_target}/", Pkg::Config.distribution_server, "#{local_target}/")
70
41
  rescue => e
71
42
  fail "Couldn't rsync packages from distribution server.\n#{e}"
72
43
  end
@@ -14,9 +14,9 @@ module Pkg::Rpm::Repo
14
14
  return
15
15
  end
16
16
 
17
- Pkg::Util::RakeUtils.invoke_task("pl:fetch")
17
+ invoke_task("pl:fetch")
18
18
  repo_dir = "#{Pkg::Config.jenkins_repo_path}/#{Pkg::Config.project}/#{Pkg::Config.ref}/#{target}/rpm"
19
- Pkg::Util::Net.remote_execute(Pkg::Config.distribution_server, "mkdir -p #{repo_dir}")
19
+ Pkg::Util::Net.remote_ssh_cmd(Pkg::Config.distribution_server, "mkdir -p #{repo_dir}")
20
20
  Pkg::Util::Execution.retry_on_fail(:times => 3) do
21
21
  Pkg::Util::Net.rsync_to("pkg/#{target}/rpm/", Pkg::Config.distribution_server, repo_dir)
22
22
  end
@@ -75,6 +75,9 @@ module Pkg::Rpm::Repo
75
75
  path = Pathname.new(origin_path)
76
76
  dest_path = Pathname.new(destination_path)
77
77
 
78
+ # You may think "rsync doesn't actually remove the sticky bit, let's
79
+ # remove the Dugo-s from the chmod". However, that will make your rsyncs
80
+ # fail due to permission errors.
78
81
  options = %w(
79
82
  rsync
80
83
  --recursive
@@ -215,7 +218,7 @@ module Pkg::Rpm::Repo
215
218
  command = Pkg::Rpm::Repo.repo_creation_command(File.join(artifact_directory, directory), artifact_paths)
216
219
 
217
220
  begin
218
- Pkg::Util::Net.remote_execute(Pkg::Config.distribution_server, command)
221
+ Pkg::Util::Net.remote_ssh_cmd(Pkg::Config.distribution_server, command)
219
222
  # Now that we've created our package repositories, we can generate repo
220
223
  # configurations for use with downstream jobs, acceptance clients, etc.
221
224
  Pkg::Rpm::Repo.generate_repo_configs
@@ -224,7 +227,7 @@ module Pkg::Rpm::Repo
224
227
  Pkg::Rpm::Repo.ship_repo_configs
225
228
  ensure
226
229
  # Always remove the lock file, even if we've failed
227
- Pkg::Util::Net.remote_execute(Pkg::Config.distribution_server, "rm -f #{artifact_directory}/repos/.lock")
230
+ Pkg::Util::Net.remote_ssh_cmd(Pkg::Config.distribution_server, "rm -f #{artifact_directory}/repos/.lock")
228
231
  end
229
232
  end
230
233
 
@@ -248,7 +251,7 @@ module Pkg::Rpm::Repo
248
251
  def deploy_repos(yum_path, origin_server, destination_server, dryrun = false)
249
252
  rsync_command = repo_deployment_command(yum_path, yum_path, destination_server, dryrun)
250
253
 
251
- Pkg::Util::Net.remote_execute(origin_server, rsync_command)
254
+ Pkg::Util::Net.remote_ssh_cmd(origin_server, rsync_command)
252
255
  end
253
256
  end
254
257
  end
data/lib/packaging/tar.rb CHANGED
@@ -14,10 +14,6 @@ module Pkg
14
14
  @files = Pkg::Config.files
15
15
  @target = File.join(Pkg::Config.project_root, "pkg", "#{@project}-#{@version}.tar.gz")
16
16
 
17
- # If the user did not specify any files, then archive the entire working directory
18
- # instead
19
- @files ||= Dir.glob('*')
20
-
21
17
  # We require that the excludes list be a string (which is space
22
18
  # separated, we hope)(deprecated) or an array.
23
19
  #
@@ -34,11 +30,6 @@ module Pkg
34
30
  @excludes = []
35
31
  end
36
32
 
37
- # If the user has specified things to exclude via config file, they will be
38
- # honored by the tar class, but we also always exclude the packaging repo
39
- # and 'pkg' directory.
40
- @excludes += ['pkg', 'ext/packaging']
41
-
42
33
  # On the other hand, support for explicit templates started with Arrays,
43
34
  # so that's all we support.
44
35
  #
@@ -11,10 +11,5 @@ module Pkg::Util::Date
11
11
  end
12
12
  Time.now.strftime(format)
13
13
  end
14
-
15
- def today
16
- format = "%m/%d/%Y"
17
- Time.now.strftime(format)
18
- end
19
14
  end
20
15
  end
@@ -58,7 +58,7 @@ module Pkg::Util::Execution
58
58
  # Loop a block up to the number of attempts given, exiting when we receive success
59
59
  # or max attempts is reached. Raise an exception unless we've succeeded.
60
60
  def retry_on_fail(args, &blk)
61
- success = false
61
+ success = FALSE
62
62
  exception = ''
63
63
 
64
64
  if args[:times].respond_to?(:times) and block_given?
@@ -69,7 +69,7 @@ module Pkg::Util::Execution
69
69
 
70
70
  begin
71
71
  blk.call
72
- success = true
72
+ success = TRUE
73
73
  break
74
74
  rescue => err
75
75
  puts "An error was encountered evaluating block. Retrying.."
@@ -6,7 +6,7 @@ module Pkg::Util::Git
6
6
  # Git utility to create a new git commit
7
7
  def commit_file(file, message = 'changes')
8
8
  fail_unless_repo
9
- puts 'Committing changes:'
9
+ puts 'Commiting changes:'
10
10
  puts
11
11
  diff, = Pkg::Util::Execution.capture3("#{Pkg::Util::Tool::GIT} diff HEAD #{file}")
12
12
  puts diff
@@ -25,7 +25,7 @@ module Pkg::Util::Gpg
25
25
  kill_keychain
26
26
  start_keychain
27
27
  end
28
- @keychain_loaded = true
28
+ @keychain_loaded = TRUE
29
29
  end
30
30
  end
31
31
 
@@ -51,10 +51,6 @@ module Pkg::Util::Gpg
51
51
  gpg ||= Pkg::Util::Tool.find_tool('gpg')
52
52
 
53
53
  if gpg
54
- if File.exist? "#{file}.asc"
55
- warn "Signature on #{file} exists, skipping..."
56
- return true
57
- end
58
54
  use_tty = "--no-tty --use-agent" if ENV['RPM_GPG_AGENT']
59
55
  stdout, _, _ = Pkg::Util::Execution.capture3("#{gpg} #{use_tty} --armor --detach-sign -u #{key} #{file}")
60
56
  stdout
@@ -20,11 +20,13 @@ module Pkg::Util::Net
20
20
  end
21
21
 
22
22
  # Check that the current host matches the one we think it should
23
- def check_host(host, options = { required: true })
24
- return true if hostname == host
25
-
26
- fail "Error: #{hostname} does not match #{host}" if options[:required]
27
- return nil
23
+ def check_host(host, args = { :required => true })
24
+ if hostname == host
25
+ return true
26
+ else
27
+ fail "#{hostname} does not match #{host}" if args[:required]
28
+ return nil
29
+ end
28
30
  end
29
31
 
30
32
  # @param hosts - An array of hosts to try ssh-ing into
@@ -36,7 +38,7 @@ module Pkg::Util::Net
36
38
  errs = []
37
39
  Array(hosts).flatten.each do |host|
38
40
  begin
39
- remote_execute(host, 'exit', { extra_options: '-oBatchMode=yes' })
41
+ remote_ssh_cmd(host, 'exit', false, '-oBatchMode=yes')
40
42
  rescue
41
43
  errs << host
42
44
  end
@@ -54,8 +56,7 @@ module Pkg::Util::Net
54
56
  errs = []
55
57
  Array(hosts).flatten.each do |host|
56
58
  begin
57
- remote_execute(host, "gpg --list-secret-keys #{gpg} > /dev/null 2&>1",
58
- { extra_options: '-oBatchMode=yes' })
59
+ remote_ssh_cmd(host, "gpg --list-secret-keys #{gpg} > /dev/null 2&>1", false, '-oBatchMode=yes')
59
60
  rescue
60
61
  errs << host
61
62
  end
@@ -63,62 +64,35 @@ module Pkg::Util::Net
63
64
  return errs
64
65
  end
65
66
 
66
- def remote_execute(target_host, command, user_options = {})
67
- option_defaults = {
68
- capture_output: false,
69
- extra_options: '',
70
- fail_fast: true,
71
- trace: false
72
- }
73
- options = option_defaults.merge(user_options)
74
-
67
+ def remote_ssh_cmd(target, command, capture_output = false, extra_options = '', fail_fast = true)
75
68
  ssh = Pkg::Util::Tool.check_tool('ssh')
76
69
 
77
70
  # we pass some pretty complicated commands in via ssh. We need this to fail
78
71
  # if any part of the remote ssh command fails.
79
- shell_flags = ''
80
- shell_flags += 'set -e;' if options[:fail_fast]
81
- shell_flags += 'set -x;' if options[:trace]
82
- shell_commands = "#{shell_flags}#{command}"
83
-
84
- remote_command = "#{ssh} #{options[:extra_options]} -t #{target_host} " +
85
- "'#{shell_commands.gsub("'", "'\\\\''")}'"
72
+ command = "set -e; #{command}" if fail_fast
73
+ cmd = "#{ssh} #{extra_options} -t #{target} '#{command.gsub("'", "'\\\\''")}'"
86
74
 
87
75
  # This is NOT a good way to support this functionality.
76
+ # It needs to be refactored into a set of methods that
77
+ # other methods can use to safely and deterministically
78
+ # support dry-run operations.
79
+ # But I need to ship packages RIGHT NOW.
80
+ # - Ryan McKern, 13/01/2016
88
81
  if ENV['DRYRUN']
89
82
  puts "[DRY-RUN] Executing '#{command}' on #{target}"
90
83
  puts "[DRY-RUN] #{cmd}"
91
- return ''
84
+ return
92
85
  end
93
86
 
94
- # We're forced to make different calls depending on the capture_output option
95
- # because something about our #capture3 method screws up gpg. This should
96
- # be untangled.
97
- if options[:capture_output]
98
- stdout, stderr, exitstatus = Pkg::Util::Execution.capture3(remote_command)
99
- Pkg::Util::Execution.success?(exitstatus) or
100
- raise "Remote ssh command (\"#{remote_command}\") failed."
87
+ puts "Executing '#{command}' on #{target}"
88
+ if capture_output
89
+ stdout, stderr, exitstatus = Pkg::Util::Execution.capture3(cmd)
90
+ Pkg::Util::Execution.success?(exitstatus) or raise "Remote ssh command failed."
101
91
  return stdout, stderr
92
+ else
93
+ Kernel.system(cmd)
94
+ Pkg::Util::Execution.success? or raise "Remote ssh command failed."
102
95
  end
103
-
104
- # Pkg::Util::Execution.capture3 reports its command but Kernel.system does not
105
- # Let's print it out for some amount of consistency.
106
- puts "Remote Execute: '#{remote_command}'"
107
- Kernel.system(remote_command)
108
- Pkg::Util::Execution.success? or
109
- raise "Remote ssh command (\"#{remote_command}\") failed."
110
- end
111
-
112
- ###
113
- ### Deprecated method implemented as a shim to the new `remote_execute` method
114
- ###
115
- def remote_ssh_cmd(target, command, capture_output = false, extra_options = '', fail_fast = true, trace = false) # rubocop:disable Style/ParameterLists
116
- puts "Warn: \"remote_ssh_cmd\" call in packaging is deprecated. Use \"remote_execute\" instead."
117
- remote_execute(target, command, {
118
- capture_output: capture_output,
119
- extra_options: extra_options,
120
- fail_fast: fail_fast,
121
- trace: trace })
122
96
  end
123
97
 
124
98
  # Construct a valid rsync command
@@ -156,7 +130,7 @@ module Pkg::Util::Net
156
130
  raise(ArgumentError, "Cannot sync between two remote hosts") if
157
131
  options[:origin_host] && options[:target_host]
158
132
 
159
- raise(ArgumentError, "Cannot sync path '#{origin}' because both origin_host and target_host are nil. Perhaps you need to set TEAM=release ?") unless
133
+ raise(ArgumentError, "Cannot sync path '#{origin}' to itself") unless
160
134
  options[:origin_host] || options[:target_host]
161
135
 
162
136
  cmd = %W(
@@ -293,17 +267,17 @@ module Pkg::Util::Net
293
267
 
294
268
  def remote_set_ownership(host, owner, group, files)
295
269
  remote_cmd = "for file in #{files.join(" ")}; do if [[ -d $file ]] || ! `lsattr $file | grep -q '\\-i\\-'`; then sudo chown #{owner}:#{group} $file; else echo \"$file is immutable\"; fi; done"
296
- Pkg::Util::Net.remote_execute(host, remote_cmd)
270
+ Pkg::Util::Net.remote_ssh_cmd(host, remote_cmd)
297
271
  end
298
272
 
299
273
  def remote_set_permissions(host, permissions, files)
300
274
  remote_cmd = "for file in #{files.join(" ")}; do if [[ -d $file ]] || ! `lsattr $file | grep -q '\\-i\\-'`; then sudo chmod #{permissions} $file; else echo \"$file is immutable\"; fi; done"
301
- Pkg::Util::Net.remote_execute(host, remote_cmd)
275
+ Pkg::Util::Net.remote_ssh_cmd(host, remote_cmd)
302
276
  end
303
277
 
304
278
  # Remotely set the immutable bit on a list of files
305
279
  def remote_set_immutable(host, files)
306
- Pkg::Util::Net.remote_execute(host, "sudo chattr +i #{files.join(" ")}")
280
+ Pkg::Util::Net.remote_ssh_cmd(host, "sudo chattr +i #{files.join(" ")}")
307
281
  end
308
282
 
309
283
  # Create a symlink indicating the latest version of a package
@@ -319,14 +293,10 @@ module Pkg::Util::Net
319
293
  # @option :excludes [Array] Strings you want to exclude from your search,
320
294
  # e.g. 'agent' if only searching for 'puppet'.
321
295
  def remote_create_latest_symlink(package_name, dir, platform_ext, options = {})
322
- ls_cmd = "ls -1 *.#{platform_ext} | grep -v latest | grep -v rc | grep -P '#{package_name}-\\d' "
323
-
324
- # store this in a separate var to avoid side affects
325
- full_package_name = String.new(package_name)
326
-
296
+ ls_cmd = "ls -1 *.#{platform_ext} | grep -v latest | grep -v rc | grep #{package_name} "
327
297
  if options[:arch]
328
298
  ls_cmd << "| grep #{options[:arch]}"
329
- full_package_name << "-#{options[:arch]}"
299
+ package_name << "-#{options[:arch]}"
330
300
  end
331
301
  if options[:excludes]
332
302
  options[:excludes].each do |excl|
@@ -342,15 +312,14 @@ module Pkg::Util::Net
342
312
  pushd '#{dir}'
343
313
  link_target=$(#{ls_cmd})
344
314
  if [ -z "$link_target" ] ; then
345
- echo "Unable to find a link target for '#{full_package_name}' in '#{dir}'; skipping link creation"
315
+ echo "Unable to find a link target for '#{package_name}' in '#{dir}'; skipping link creation"
346
316
  exit 0
347
317
  fi
348
318
  echo "creating link to '$link_target'"
349
- ln -sf "$link_target" #{full_package_name}-latest.#{platform_ext}
319
+ ln -sf "$link_target" #{package_name}-latest.#{platform_ext}
350
320
  CMD
351
321
 
352
- _, err = Pkg::Util::Net.remote_execute(
353
- Pkg::Config.staging_server, cmd, { capture_output: true })
322
+ _, err = Pkg::Util::Net.remote_ssh_cmd(Pkg::Config.staging_server, cmd, true)
354
323
  $stderr.puts err
355
324
  end
356
325
 
@@ -374,7 +343,7 @@ module Pkg::Util::Net
374
343
  # We take a tar argument for cases where `tar` isn't best, e.g. Solaris. We
375
344
  # also take an optional argument of the tarball containing the git bundle to
376
345
  # use.
377
- def remote_unpack_git_bundle(host, treeish, tar_cmd = nil, tarball = nil)
346
+ def remote_bootstrap(host, treeish, tar_cmd = nil, tarball = nil)
378
347
  unless tar = tar_cmd
379
348
  tar = 'tar'
380
349
  end
@@ -382,19 +351,8 @@ module Pkg::Util::Net
382
351
  tarball_name = File.basename(tarball).gsub('.tar.gz', '')
383
352
  Pkg::Util::Net.rsync_to(tarball, host, '/tmp')
384
353
  appendix = Pkg::Util.rand_string
385
- git_bundle_directory = File.join('/tmp', "#{Pkg::Config.project}-#{appendix}")
386
- command = <<-DOC
387
- #{tar} -zxvf /tmp/#{tarball_name}.tar.gz -C /tmp/ ;
388
- git clone --recursive /tmp/#{tarball_name} #{git_bundle_directory} ;
389
- DOC
390
- Pkg::Util::Net.remote_execute(host, command)
391
- return git_bundle_directory
392
- end
393
-
394
- def remote_bundle_install_command
395
- export_packaging_location = ''
396
- export_packaging_location = "export PACKAGING_LOCATION='#{ENV['PACKAGING_LOCATION']}';" if ENV['PACKAGING_LOCATION'] && !ENV['PACKAGING_LOCATION'].empty?
397
- command = "source /usr/local/rvm/scripts/rvm; rvm use ruby-2.5.1; #{export_packaging_location} bundle install --path .bundle/gems ;"
354
+ Pkg::Util::Net.remote_ssh_cmd(host, "#{tar} -zxvf /tmp/#{tarball_name}.tar.gz -C /tmp/ ; git clone --recursive /tmp/#{tarball_name} /tmp/#{Pkg::Config.project}-#{appendix} ; cd /tmp/#{Pkg::Config.project}-#{appendix} ; rake package:bootstrap")
355
+ "/tmp/#{Pkg::Config.project}-#{appendix}"
398
356
  end
399
357
 
400
358
  # Given a BuildInstance object and a host, send its params to the host. Return
@@ -67,7 +67,6 @@ module Pkg::Util::RakeUtils
67
67
  '00_utils.rake',
68
68
  '30_metrics.rake',
69
69
  'apple.rake',
70
- 'archive.rake',
71
70
  'build.rake',
72
71
  'clean.rake',
73
72
  'deb.rake',