knife-packager 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in knife-packager.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 John Dyer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Knife::Packager
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'knife-packager'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install knife-packager
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib/chef/knife', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "knife-packager"
7
+ gem.version = "0.1.2"
8
+ gem.authors = ["John Dyer"]
9
+ gem.email = ["johntdyer@gmail.com"]
10
+ gem.description = %q{Knife pluging to deploy cookbooks to S3}
11
+ gem.summary = %q{Knife pluging to deploy cookbooks to S3}
12
+ gem.homepage = ""
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency 'rake'
20
+ gem.add_dependency 'bundler'
21
+ gem.add_dependency 'chef'
22
+ gem.add_dependency 'berkshelf'
23
+ gem.add_dependency 's3'
24
+ gem.add_dependency 'fog'
25
+
26
+ end
@@ -0,0 +1,116 @@
1
+ $: << File.expand_path(File.dirname(__FILE__))
2
+
3
+ # workaround for https://github.com/RiotGames/berkshelf/issues/270
4
+ lang = ENV['LANG']
5
+ require 'berkshelf/cli'
6
+ ENV['LANG'] = lang unless lang.nil?
7
+
8
+ require 'chef/knife'
9
+ require 'digest/md5'
10
+ require 'fileutils'
11
+ require 'mime/types'
12
+ require 'pathname'
13
+ require 's3'
14
+ require 'tmpdir'
15
+ require 'voxconfig'
16
+ require 'yaml'
17
+
18
+ module Packager
19
+
20
+ class Packager < Chef::Knife
21
+
22
+ deps do
23
+ end
24
+
25
+ banner "knife packager"
26
+
27
+ def run
28
+ Berkshelf::Config.new
29
+ @config = VoxConfig.new(Dir.pwd)
30
+ @tmp = Dir.mktmpdir
31
+ get_dependencies
32
+ pkg = package_files
33
+ upload_cookbooks(pkg)
34
+ FileUtils.remove_entry_secure(@tmp)
35
+ end
36
+
37
+
38
+ def get_dependencies()
39
+ puts ui.highline.color "Gathering cookbook dependencies (this will take a minute)", :green
40
+ STDOUT.sync = true
41
+ berks = `berks install --path #{@tmp}/cookbooks`
42
+ unless $?.exitstatus == 0
43
+ puts ui.highline.color "Failed to gather dependencies", :red
44
+ exit 3
45
+ end
46
+ puts berks
47
+ end
48
+
49
+ def package_files
50
+ puts ui.highline.color "== Packaging cookbook", :green
51
+ `cd #{@tmp}; tar zcf #{get_cookbook_name}.#{get_cookbook_version}.tgz ./cookbooks`
52
+ unless $?.exitstatus == 0
53
+ puts ui.highline.color "Failed to archive cookbooks", :red
54
+ exit 3
55
+ end
56
+ return "#{@tmp}/#{get_cookbook_name}.#{get_cookbook_version}.tgz"
57
+ end
58
+
59
+ def get_cookbook_version
60
+ IO.read(Berkshelf.find_metadata).match(/^version.*/).to_s.split('"')[1]
61
+ end
62
+
63
+ def get_folder_name
64
+ if @config.project_name
65
+ return @config.project_name
66
+ else
67
+ get_cookbook_name
68
+ end
69
+ end
70
+
71
+ def get_cookbook_name
72
+ name = IO.read(Berkshelf.find_metadata).match(/^name.*/).to_s.split('"')[1]
73
+ if name.nil?
74
+ return Dir.pwd.split("/")[-1]
75
+ else
76
+ return name
77
+ end
78
+
79
+ end
80
+
81
+ def upload_cookbooks(file)
82
+ service = S3::Service.new({
83
+ :access_key_id => @config.aws_key,
84
+ :secret_access_key => @config.aws_secret
85
+ })
86
+ bucket = service.buckets.find(@config.bucket_name)
87
+ puts ui.highline.color "== Uploading cookbook [#{file}]", :green
88
+
89
+ ## Only upload files, we're not interested in directories
90
+ if File.file?(file)
91
+ remote_file = "#{get_folder_name}/#{file.split("/")[-1]}"
92
+
93
+ begin
94
+ obj = bucket.objects.find_first(remote_file)
95
+ if yes? "This cookbook version already exists, do you want to overwrite it ?", :red
96
+ puts ui.highline.color "== Ok, we'll overwrite it", :green
97
+ else
98
+ puts ui.highline.color "== Ok, exiting", :green
99
+ exit 0
100
+ end
101
+ rescue
102
+ obj = nil
103
+ end
104
+
105
+ puts ui.highline.color "== Uploading http://#{@config.bucket_name}/#{get_folder_name}/#{file.split("/")[-1]}", :blue
106
+ obj = bucket.objects.build(remote_file)
107
+ obj.content = open(file)
108
+ obj.content_type = MIME::Types.type_for(file).to_s
109
+ obj.save
110
+
111
+ end
112
+ puts ui.highline.color "== Done syncing #{file.split('/')[-1]}",:green
113
+ end
114
+
115
+ end
116
+ end
@@ -0,0 +1,39 @@
1
+ class VoxConfig
2
+
3
+ attr_reader :bucket_name, :aws_secret, :aws_key, :project_name
4
+
5
+ def initialize(path)
6
+ file_name=".deployer"
7
+
8
+ Pathname.new(path).ascend do |dir|
9
+ config_file = dir + file_name
10
+ if dir.children.include?(config_file)
11
+ merge_config(YAML::load_file(config_file))
12
+ end
13
+ end
14
+
15
+ end
16
+
17
+ private
18
+
19
+ def merge_config(config)
20
+
21
+ if config['bucket_name']
22
+ @bucket_name = config['bucket_name'] unless @bucket_name
23
+ end
24
+
25
+ if config['aws_secret']
26
+ @aws_secret = config['aws_secret'] unless @aws_secret
27
+ end
28
+
29
+ if config['aws_key']
30
+ @aws_key = config['aws_key'] unless @aws_key
31
+ end
32
+
33
+ if config['project_name']
34
+ @project_name = config['project_name'] unless @project_name
35
+ end
36
+
37
+ end
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-packager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Dyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: chef
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: berkshelf
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: s3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: fog
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Knife pluging to deploy cookbooks to S3
111
+ email:
112
+ - johntdyer@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - LICENSE.txt
120
+ - README.md
121
+ - Rakefile
122
+ - knife-packager.gemspec
123
+ - lib/chef/knife/packager.rb
124
+ - lib/chef/knife/voxconfig.rb
125
+ homepage: ''
126
+ licenses: []
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ segments:
138
+ - 0
139
+ hash: 1202753641670726567
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ segments:
147
+ - 0
148
+ hash: 1202753641670726567
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 1.8.23
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: Knife pluging to deploy cookbooks to S3
155
+ test_files: []