labs-deployer 0.0.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 labs-deployer.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,36 @@
1
+ # Labs::Deployer
2
+
3
+ Thor task to help w/ deployment of cookbooks to S3 for use by Chef-Solo
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'labs-deployer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install labs-deployer
18
+
19
+ ## Usage
20
+
21
+ Thos task that helps bundle and deploy cookbooks to S3. Expects the following in your knife.rb
22
+
23
+ ```ruby
24
+
25
+ knife[:aws_access_key_id] = "abc123"
26
+ knife[:aws_secret_access_key] = "abc123"
27
+ knife[:bucket] = 'cookbooks.myserver.com'
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'labs-deployer/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "labs-deployer"
8
+ gem.version = Labs::Deployer::VERSION
9
+ gem.authors = ["John Dyer"]
10
+ gem.email = ["johntdyer@gmail.com"]
11
+ gem.description = %q{Thor tasks to package chef solo cookbooks}
12
+ gem.summary = %q{Deployed cookbooks to s3}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,5 @@
1
+ module Labs
2
+ module Deployer
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+
3
+ require "labs-deployer/version"
4
+ require 'thor'
5
+ require 'bundler'
6
+ require 'bundler/setup'
7
+ require 'berkshelf/thor'
8
+ require 'fileutils'
9
+ require 'digest/md5'
10
+ require 'mime/types'
11
+ require 'berkshelf/cli'
12
+ require 's3'
13
+
14
+ class Solo < Thor
15
+
16
+ Berkshelf.load_config
17
+
18
+ AWS_ACCESS_KEY_ID = Chef::Config[:knife][:aws_access_key_id]
19
+ AWS_SECRET_ACCESS_KEY = Chef::Config[:knife][:aws_secret_access_key]
20
+ AWS_BUCKET = Chef::Config[:knife][:bucket]
21
+
22
+ desc "package", "package and deploy a cookbook"
23
+
24
+ def package
25
+
26
+ get_dependencies
27
+ pkg = package_files
28
+ upload_cookbooks(pkg)
29
+ end
30
+
31
+ private
32
+
33
+ def get_dependencies()
34
+ say "Gathering cookbook dependencies", :green
35
+ `mkdir -p /tmp/berkshelf-tmp`
36
+ invoke("berkshelf:install", [], path: "/tmp/berkshelf-tmp", berksfile: "./Berksfile")
37
+ end
38
+
39
+ def package_files
40
+ say "Packaging cookbook", :green
41
+ `tar zcf #{get_cookbook_name}.#{get_cookbook_version}.tgz -C /tmp/berkshelf-tmp .`
42
+ FileUtils.mv "#{get_cookbook_name}.#{get_cookbook_version}.tgz", '/tmp'
43
+ return "/tmp/#{get_cookbook_name}.#{get_cookbook_version}.tgz"
44
+ end
45
+
46
+ def upload_cookbooks(file)
47
+ service = S3::Service.new({
48
+ :access_key_id => AWS_ACCESS_KEY_ID,
49
+ :secret_access_key => AWS_SECRET_ACCESS_KEY
50
+ })
51
+
52
+ bucket = service.buckets.find(AWS_BUCKET)
53
+
54
+ say "Uploading cookbook [#{file}]", :green
55
+
56
+ ## Only upload files, we're not interested in directories
57
+ if File.file?(file)
58
+ remote_file = "#{get_cookbook_name}/#{file.split("/")[-1]}"
59
+
60
+ begin
61
+ obj = bucket.objects.find_first(remote_file)
62
+ if yes? "This cookbook version already exists, do you want to overwrite it ?", :red
63
+ say "Ok, we'll overwrite it", :green
64
+ else
65
+ say "Ok, exiting", :green
66
+ exit 0
67
+ end
68
+ rescue
69
+ obj = nil
70
+ end
71
+
72
+ ## If the object does not exist, or if the MD5 Hash / etag of the file has changed, upload it.
73
+ if !obj || (obj.etag != Digest::MD5.hexdigest(File.read(file)))
74
+ say "Uploading #{file}", :green
75
+ obj = bucket.objects.build(remote_file)
76
+ obj.content = open(file)
77
+ obj.content_type = MIME::Types.type_for(file).to_s
78
+ obj.save
79
+ else
80
+ say "Skipping duplicate file [ #{file} ]", :yellow
81
+ end
82
+ end
83
+ say "== Done syncing #{file.split('/')[-1]}",:green
84
+ end
85
+
86
+ def get_cookbook_version
87
+ IO.read(Berkshelf.find_metadata).match(/^version.*/).to_s.split('"')[1]
88
+ end
89
+
90
+ def get_cookbook_name
91
+ Dir.pwd.split("/")[-1]
92
+ end
93
+
94
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: labs-deployer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Dyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Thor tasks to package chef solo cookbooks
15
+ email:
16
+ - johntdyer@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - labs-deployer.gemspec
27
+ - lib/labs-deployer.rb
28
+ - lib/labs-deployer/version.rb
29
+ homepage: ''
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ segments:
42
+ - 0
43
+ hash: 1372670327228798834
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ segments:
51
+ - 0
52
+ hash: 1372670327228798834
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.24
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Deployed cookbooks to s3
59
+ test_files: []