chef-dk 0.12.0 → 0.13.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ platforms = ARGV.shift
4
+ old_platforms = Gem.platforms
5
+ Gem.platforms = platforms.split(" ").map { |p| Gem::Platform.new(p) }
6
+ puts "bundle-platform set Gem.platforms to #{Gem.platforms.map { |p| p.to_s }} (was #{old_platforms.map { |p| p.to_s } })"
7
+
8
+ # The rest of this is a normal bundler binstub
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+
15
+ load Gem.bin_path("bundler", "bundle")
@@ -0,0 +1,2 @@
1
+ @ECHO OFF
2
+ ruby "%~dpn0" %*
@@ -0,0 +1,80 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2016 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require_relative "bundle_util"
19
+ require_relative "../version_policy"
20
+
21
+ desc "Tasks to work with the main Gemfile and Gemfile.<platform>"
22
+ namespace :bundle do
23
+ desc "Update Gemfile.lock and all Gemfile.<platform>.locks (or one or more gems via bundle:update gem1 gem2 ...). NOTE: use rake dependencies:update_current_chef to update the version of chef first, if you want it updated as well)."
24
+ task :update, [:args] do |t, rake_args|
25
+ extend BundleUtil
26
+ args = rake_args[:args] || ""
27
+ with_bundle_unfrozen do
28
+ puts ""
29
+ puts "-------------------------------------------------------------------"
30
+ puts "Updating Gemfile.lock ..."
31
+ puts "-------------------------------------------------------------------"
32
+ bundle "install #{args}", delete_gemfile_lock: true
33
+ platforms.each do |platform|
34
+ puts ""
35
+ puts "-------------------------------------------------------------------"
36
+ puts "Updating Gemfile.#{platform}.lock ..."
37
+ puts "-------------------------------------------------------------------"
38
+ bundle "lock", gemfile: "Gemfile.#{platform}", platform: platform, delete_gemfile_lock: true
39
+ end
40
+ end
41
+ end
42
+
43
+ desc "Conservatively update Gemfile.lock and all Gemfile.<platform>.locks"
44
+ task :install, [:args] do |t, rake_args|
45
+ extend BundleUtil
46
+ args = rake_args[:args] || ""
47
+ with_bundle_unfrozen do
48
+ puts ""
49
+ puts "-------------------------------------------------------------------"
50
+ puts "Updating Gemfile.lock ..."
51
+ puts "-------------------------------------------------------------------"
52
+ bundle "install #{args}"
53
+ platforms.each do |platform|
54
+ puts ""
55
+ puts "-------------------------------------------------------------------"
56
+ puts "Updating Gemfile.#{platform}.lock (conservatively) ..."
57
+ puts "-------------------------------------------------------------------"
58
+ bundle "lock", gemfile: "Gemfile.#{platform}", platform: platform
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ desc "Run bundle with arbitrary args against the given platform; e.g. rake bundle[show]. No platform to run against the main bundle; bundle[show,windows] to run the windows one; bundle[show,*] to run against all non-default platforms."
65
+ task :bundle, [:args,:platform] do |t, rake_args|
66
+ extend BundleUtil
67
+ args = rake_args[:args] || ""
68
+ platform = rake_args[:platform]
69
+ with_bundle_unfrozen do
70
+ if platform == "*"
71
+ platforms.each do |platform|
72
+ bundle args, platform: platform
73
+ end
74
+ elsif platform
75
+ bundle args, platform: platform
76
+ else
77
+ bundle args
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,93 @@
1
+ require 'shellwords'
2
+
3
+ module BundleUtil
4
+ PLATFORMS = { "windows" => %w{ruby x86-mingw32} }
5
+
6
+ def project_root
7
+ File.expand_path("../..", __FILE__)
8
+ end
9
+
10
+ def bundle_platform
11
+ File.join(project_root, "tasks", "bin", "bundle-platform")
12
+ end
13
+
14
+ # Parse the output of "bundle outdated" and get the list of gems that
15
+ # were outdated
16
+ def parse_bundle_outdated(bundle_outdated_output)
17
+ result = []
18
+ bundle_outdated_output.each_line do |line|
19
+ if line =~ /^\s*\* (.+) \(newest ([^,]+), installed ([^,)])*/
20
+ gem_name, newest_version, installed_version = $1, $2, $3
21
+ result << [ line, gem_name ]
22
+ end
23
+ end
24
+ result
25
+ end
26
+
27
+ def with_bundle_unfrozen
28
+ bundle "config --delete frozen"
29
+ begin
30
+ yield
31
+ ensure
32
+ bundle "config --local frozen 1"
33
+ end
34
+ end
35
+
36
+ # Run bundle-platform with the given ruby platform(s)
37
+ def bundle(args, gemfile: nil, platform: nil, cwd: nil, extract_output: false, delete_gemfile_lock: false)
38
+ args = args.split(/\s+/)
39
+ if cwd
40
+ prefix = "[#{cwd}] "
41
+ end
42
+ cwd = File.expand_path(cwd || ".", project_root)
43
+ Bundler.with_clean_env do
44
+ Dir.chdir(cwd) do
45
+ gemfile ||= "Gemfile"
46
+ gemfile = File.expand_path(gemfile, cwd)
47
+ raise "No platform #{platform} (supported: #{PLATFORMS.keys.join(", ")})" if platform && !PLATFORMS[platform]
48
+
49
+ # First delete the gemfile.lock
50
+ if delete_gemfile_lock
51
+ if File.exist?("#{gemfile}.lock")
52
+ puts "Deleting #{gemfile}.lock ..."
53
+ File.delete("#{gemfile}.lock")
54
+ end
55
+ end
56
+
57
+ # Run the bundle command
58
+ ruby_platforms = platform ? PLATFORMS[platform].join(" ") : "ruby"
59
+ cmd = Shellwords.join([bundle_platform, ruby_platforms, *args])
60
+ puts "#{prefix}#{Shellwords.join(["bundle", *args])}#{platform ? " for #{platform} platform" : ""}:"
61
+ with_gemfile(gemfile) do
62
+ puts "#{prefix}BUNDLE_GEMFILE=#{gemfile}"
63
+ puts "#{prefix}> #{cmd}"
64
+ if extract_output
65
+ `#{cmd}`
66
+ else
67
+ unless system(bundle_platform, ruby_platforms, *args)
68
+ raise "#{bundle_platform} failed: exit code #{$?}"
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ def with_gemfile(gemfile)
77
+ old_gemfile = ENV["BUNDLE_GEMFILE"]
78
+ ENV["BUNDLE_GEMFILE"] = gemfile
79
+ begin
80
+ yield
81
+ ensure
82
+ if old_gemfile
83
+ ENV["BUNDLE_GEMFILE"] = old_gemfile
84
+ else
85
+ ENV.delete("BUNDLE_GEMFILE")
86
+ end
87
+ end
88
+ end
89
+
90
+ def platforms
91
+ PLATFORMS.keys
92
+ end
93
+ end
@@ -0,0 +1,175 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2016 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require_relative "bundle_util"
19
+ require_relative "bundle"
20
+ require_relative "../version_policy"
21
+
22
+ desc "Tasks to update and check dependencies"
23
+ namespace :dependencies do
24
+ # Update all dependencies to the latest constraint-matching version
25
+ desc "Update all dependencies. dependencies:update[conservative] to update as little as possible."
26
+ task :update, [:conservative] => %w{
27
+ dependencies:update_current_chef
28
+ dependencies:update_gemfile_lock
29
+ dependencies:update_omnibus_overrides
30
+ dependencies:update_omnibus_gemfile_lock
31
+ dependencies:update_acceptance_gemfile_lock
32
+ }
33
+
34
+ desc "Update Gemfile.lock and all Gemfile.<platform>.locks. update_gemfile_lock[conservative] to update as little as possible."
35
+ task :update_gemfile_lock, [:conservative] do |t, rake_args|
36
+ conservative = rake_args[:conservative]
37
+ if conservative
38
+ Rake::Task["bundle:install"].invoke
39
+ else
40
+ Rake::Task["bundle:update"].invoke
41
+ end
42
+ end
43
+
44
+ desc "Update omnibus/Gemfile.lock. update_omnibus_gemfile_lock[conservative] to update as little as possible."
45
+ task :update_omnibus_gemfile_lock, [:conservative] do |t, rake_args|
46
+ extend BundleUtil
47
+ conservative = rake_args[:conservative]
48
+ puts ""
49
+ puts "-------------------------------------------------------------------"
50
+ puts "Updating omnibus/Gemfile.lock#{conservative ? " (conservatively)" : ""} ..."
51
+ puts "-------------------------------------------------------------------"
52
+ bundle "install", cwd: "omnibus", delete_gemfile_lock: !conservative
53
+ end
54
+
55
+ desc "Update acceptance/Gemfile.lock (or one or more gems via update[gem1,gem2,...]). update_acceptance_gemfile_lock[conservative] to update as little as possible."
56
+ task :update_acceptance_gemfile_lock, [:conservative] do |t, rake_args|
57
+ extend BundleUtil
58
+ conservative = rake_args[:conservative]
59
+ puts ""
60
+ puts "-------------------------------------------------------------------"
61
+ puts "Updating acceptance/Gemfile.lock#{conservative ? " (conservatively)" : ""} ..."
62
+ puts "-------------------------------------------------------------------"
63
+ bundle "install", cwd: "acceptance", delete_gemfile_lock: !conservative
64
+ end
65
+
66
+ desc "Update current chef release in Gemfile. update_current_chef[conservative] does nothing."
67
+ task :update_current_chef, [:conservative] do |t, rake_args|
68
+ extend BundleUtil
69
+ conservative = rake_args[:conservative]
70
+ unless conservative
71
+ puts ""
72
+ puts "-------------------------------------------------------------------"
73
+ puts "Updating Gemfile ..."
74
+ puts "-------------------------------------------------------------------"
75
+
76
+ require "mixlib/install"
77
+ # TODO in some edge cases, stable will actually be the latest chef because
78
+ # promotion *moves* the package out of current into stable rather than
79
+ # copying
80
+ puts "Getting latest chef 'current' version from omnitruck ..."
81
+ options = {
82
+ channel: :current,
83
+ product_name: 'chef',
84
+ product_version: :latest
85
+ }
86
+ version = Mixlib::Install.new(options).artifact_info.first.version
87
+
88
+ # Modify the gemfile to pin to current chef
89
+ gemfile_path = File.join(project_root, "Gemfile")
90
+ gemfile = IO.read(gemfile_path)
91
+ found = gemfile.sub!(/^(\s*gem "chef", github: "chef\/chef", branch: ")([^"]*)(")$/m) do
92
+ if $2 != "v#{version}"
93
+ puts "Setting chef version in Gemfile to v#{version} (was #{$2})"
94
+ else
95
+ puts "chef version in Gemfile already at latest current (#{$2})"
96
+ end
97
+ "#{$1}v#{version}#{$3}"
98
+ end
99
+ unless found
100
+ raise "Gemfile does not have a line of the form 'gem \"chef\", github: \"chef/chef\", branch: \"v<version>\"', so we didn't update it to latest current (v#{version}). Remove dependencies:update_current_chef from the `dependencies:update` rake task to prevent it from being run if this is intentional."
101
+ end
102
+
103
+ if gemfile != IO.read(gemfile_path)
104
+ puts "Writing modified #{gemfile_path} ..."
105
+ IO.write(gemfile_path, gemfile)
106
+ end
107
+ end
108
+ end
109
+
110
+ desc "Update omnibus overrides, including versions in version_policy.rb and latest version of gems: #{OMNIBUS_RUBYGEMS_AT_LATEST_VERSION.keys}. update_omnibus_overrides[conservative] does nothing."
111
+ task :update_omnibus_overrides, [:conservative] do |t, rake_args|
112
+ conservative = rake_args[:conservative]
113
+ unless conservative
114
+ puts ""
115
+ puts "-------------------------------------------------------------------"
116
+ puts "Updating omnibus_overrides.rb ..."
117
+ puts "-------------------------------------------------------------------"
118
+
119
+ # Generate the new overrides file
120
+ overrides = "# Generated by \"rake dependencies\". Do not edit.\n"
121
+
122
+ # Replace the bundler and rubygems versions
123
+ OMNIBUS_RUBYGEMS_AT_LATEST_VERSION.each do |override_name, gem_name|
124
+ # Get the latest bundler version
125
+ puts "Running gem list -re #{gem_name} ..."
126
+ gem_list = `gem list -re #{gem_name}`
127
+ unless gem_list =~ /^#{gem_name}\s*\(([^)]*)\)$/
128
+ raise "gem list -re #{gem_name} failed with output:\n#{gem_list}"
129
+ end
130
+
131
+ # Emit it
132
+ puts "Latest version of #{gem_name} is #{$1}"
133
+ overrides << "override #{override_name.inspect}, version: #{$1.inspect}\n"
134
+ end
135
+
136
+ # Add explicit overrides
137
+ OMNIBUS_OVERRIDES.each do |override_name, version|
138
+ overrides << "override #{override_name.inspect}, version: #{version.inspect}\n"
139
+ end
140
+
141
+ # Write the file out (if changed)
142
+ overrides_path = File.expand_path("../../omnibus_overrides.rb", __FILE__)
143
+ if overrides != IO.read(overrides_path)
144
+ puts "Overrides changed!"
145
+ puts `git diff #{overrides_path}`
146
+ puts "Writing modified #{overrides_path} ..."
147
+ IO.write(overrides_path, overrides)
148
+ end
149
+ end
150
+ end
151
+
152
+ # Find out if we're using the latest gems we can (so we don't regress versions)
153
+ desc "Check for gems that are not at the latest released version, and report if anything not in ACCEPTABLE_OUTDATED_GEMS (version_policy.rb) is out of date."
154
+ task :check_outdated do
155
+ puts ""
156
+ puts "-------------------------------------------------------------------"
157
+ puts "Checking for outdated gems ..."
158
+ puts "-------------------------------------------------------------------"
159
+ # TODO check for outdated windows gems too
160
+ bundle_outdated = bundle("outdated", extract_output: true)
161
+ puts bundle_outdated
162
+ outdated_gems = parse_bundle_outdated(bundle_outdated).map { |line, gem_name| gem_name }
163
+ # Weed out the acceptable ones
164
+ outdated_gems = outdated_gems.reject { |gem_name| ACCEPTABLE_OUTDATED_GEMS.include?(gem_name) }
165
+ if outdated_gems.empty?
166
+ puts ""
167
+ puts "SUCCESS!"
168
+ else
169
+ raise "ERROR: outdated gems: #{outdated_gems.join(", ")}. Either fix them or add them to ACCEPTABLE_OUTDATED_GEMS in #{__FILE__}."
170
+ end
171
+ end
172
+ end
173
+ desc "Update all dependencies and check for outdated gems. Call dependencies[conservative] to update as little as possible."
174
+ task :dependencies, [:conservative] => [ "dependencies:update", "dependencies:check_outdated" ]
175
+ task :update, [:conservative] => [ "dependencies:update", "dependencies:check_outdated"]
@@ -0,0 +1,99 @@
1
+ require "bundler"
2
+
3
+ module GemfileUtil
4
+ #
5
+ # Given a set of dependencies with groups in them, and a resolved set of
6
+ # gemspecs (with dependency info in them), creates a full set of specs
7
+ # with group information on it. If A is in groups x and y, and A depends on
8
+ # B and C, then B and C are also in groups x and y.
9
+ #
10
+ class GemGroups < Hash
11
+ def initialize(resolved)
12
+ @resolved = resolved
13
+ end
14
+ attr_reader :resolved
15
+
16
+ def add_dependency(dep)
17
+ add_gem_groups(dep.name, dep.groups)
18
+ end
19
+
20
+ private
21
+
22
+ def add_gem_groups(name, groups)
23
+ self[name] ||= []
24
+ difference = groups - self[name]
25
+ unless difference.empty?
26
+ self[name] += difference
27
+ spec = resolved.find { |spec| spec.name == name }
28
+ if spec
29
+ spec.dependencies.each do |spec|
30
+ add_gem_groups(spec.name, difference)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def calculate_dependents(spec_set)
38
+ dependents = {}
39
+ spec_set.each do |spec|
40
+ dependents[spec] ||= []
41
+ end
42
+ spec_set.each do |spec|
43
+ spec.dependencies.each do |dep|
44
+ puts "#{dep.class} -> #{spec.class}"
45
+ dependents[dep] << spec
46
+ end
47
+ end
48
+ dependents
49
+ end
50
+
51
+ def include_locked_gemfile(gemfile)
52
+ #
53
+ # Read the gemfile and inject its locks as first-class dependencies
54
+ #
55
+ current_source = nil
56
+ bundle = Bundler::Definition.build(gemfile, "#{gemfile}.lock", nil)
57
+
58
+ # Go through and create the actual gemfile from the given locks and
59
+ # groups.
60
+ bundle.resolve.sort_by { |spec| spec.name }.each do |spec|
61
+ # bundler can't be installed by bundler so don't pin it.
62
+ next if spec.name == "bundler"
63
+ dep = bundle.dependencies.find { |d| d.name == spec.name}
64
+ gem_metadata = ""
65
+ if dep
66
+ gem_metadata << ", groups: #{dep.groups.inspect}" if dep.groups != [:default]
67
+ gem_metadata << ", platforms: #{dep.platforms.inspect}" if dep.platforms && !dep.platforms.empty?
68
+ end
69
+ case spec.source
70
+ when Bundler::Source::Rubygems
71
+ if current_source
72
+ if current_source != spec.source
73
+ raise "Gem #{spec.name} has source #{spec.source}, but other gems have #{current_source}. Multiple rubygems sources are not supported."
74
+ end
75
+ else
76
+ current_source = spec.source
77
+ add_gemfile_line("source #{spec.source.remotes.first.to_s.inspect}", __LINE__)
78
+ end
79
+ add_gemfile_line("gem #{spec.name.inspect}, #{spec.version.to_s.inspect}#{gem_metadata}", __LINE__)
80
+ when Bundler::Source::Git
81
+ add_gemfile_line("gem #{spec.name.inspect}, git: #{spec.source.uri.to_s.inspect}, ref: #{spec.source.revision.inspect}#{gem_metadata}", __LINE__)
82
+ when Bundler::Source::Path
83
+ add_gemfile_line("gem #{spec.name.inspect}, path: #{spec.source.path.to_s.inspect}#{gem_metadata}", __LINE__)
84
+ else
85
+ raise "Unknown source #{spec.source} for gem #{spec.name}"
86
+ end
87
+ end
88
+ rescue
89
+ puts $!
90
+ puts $!.backtrace
91
+ raise
92
+ end
93
+
94
+ private
95
+
96
+ def add_gemfile_line(line, lineno)
97
+ instance_eval(line, __FILE__, lineno)
98
+ end
99
+ end