Class: ChefRake::Task::Release
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- ChefRake::Task::Release
- Defined in:
- lib/chef/raketasks/release.rb
Instance Method Summary collapse
-
#initialize ⇒ Release
constructor
A new instance of Release.
Constructor Details
#initialize ⇒ Release
Returns a new instance of Release.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/chef/raketasks/release.rb', line 23 def initialize super namespace :release do desc 'Upload to Artifactory' task :artifactory, [:endpoint, :apikey, :repokey, :path] do |_t, args| Rake::Task['package:cookbook'].execute require 'berkshelf' current_dir = Rake.application.original_dir = Chef::Cookbook::Metadata.new .from_file File.join(current_dir, 'metadata.rb') file_name = format('cookbook-%<name>s-%<version>s.tar.gz', .to_hash.transform_keys(&:to_sym)) rel_path = File.join('pkg', file_name) abs_path = File.join(current_dir, rel_path) require 'artifactory' Artifactory.endpoint = args.endpoint # @TODO: Remove trailing slash, if exist Artifactory.api_key = args.apikey targetpath = File.join(args.path, file_name) artifact = Artifactory::Resource::Artifact.new(local_path: abs_path) upload = artifact.upload(args.repokey, targetpath) printf("Cookbook released to %s (size %d bytes)\n", upload.uri, upload.size) printf("SHA256 Checksum: %s\n", upload.checksums['sha256']) rescue StandardError => e puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI'] end desc 'Upload to Chef Server' task :chefserver do Rake::Task['clean:cookbook'].execute require 'berkshelf' current_dir = Rake.application.original_dir parent_dir = File.('..', current_dir) = Chef::Cookbook::Metadata.new .from_file File.join(current_dir, 'metadata.rb') cmd = "knife cookbook upload #{.name} --freeze" cmd << " --cookbook-path #{parent_dir}" sh cmd rescue StandardError => e puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI'] end desc 'Upload to Chef Supermarket' task :supermarket, [:siteurl, :user, :authkeyfile, :cookbookpath, :cookbookname, :configfile] do |_t, args| Rake::Task['clean:cookbook'].execute require 'berkshelf' current_dir = Rake.application.original_dir parent_dir = File.('..', current_dir) = Chef::Cookbook::Metadata.new .from_file File.join(current_dir, 'metadata.rb') args.with_defaults( cookbookpath: parent_dir ) cmd = "knife supermarket share #{.name}" if args.configfile.nil? cmd << " --cookbook-path #{parent_dir}" cmd << " --supermarket-site #{args.siteurl}" unless args.siteurl.nil? cmd << " --user #{args.user}" unless args.user.nil? cmd << " --key #{args.authkeyfile}" unless args.authkeyfile.nil? elsif args.configfile cmd << " --config #{args.configfile}" unless args.configfile.nil? end sh cmd # require 'chef/mixin/shell_out' # require 'chef/knife/supermarket_share' rescue StandardError => e puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI'] end end # namespace release end |