berkflow 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f6efb7683cb8b8251dfc35923a520ecabc68273
4
- data.tar.gz: 20ef5ac9d249a39a5bf1319d3eec4181fcbf72d5
3
+ metadata.gz: 3e954e4cef8846390031564211f9bba01b4e25ce
4
+ data.tar.gz: ea5d4db34fb05fb4a712c0cbc94b03b8fd218282
5
5
  SHA512:
6
- metadata.gz: f34faa9ed17ec3cef061cc435dffe70742e2b6ccb99fef0dd05d2513c62c62fb18d7e646d272c00a60f73c00ae9441f18090c7f02df5d43565680ab56c3945f8
7
- data.tar.gz: 6714994388de16ebafb05eda462b72541b40ae0709f0fc60c3854762bc463bec0f6878ca4a542cc27ee7c84dbc63e1584bd01e26178f85f2ac0c176326d00871
6
+ metadata.gz: a243d317a138e9444a104a68f8835f327a6a6dc3ec14834647d2699c1d0e5bbe58dd64d75fa8471097835090e031d05ff982c6a7a8388fe72d7a94541eac8333
7
+ data.tar.gz: 94ec93024b61cc6f9a14bba043fe2f7a989de28e0bf18b1e00fc6f0b6d7659b400539da04041eb44ccb4a4eae121d5f79afc4a55c5e78b6d8c0dcdea7e2015d6
@@ -0,0 +1,21 @@
1
+ # 0.2.0
2
+
3
+ * Features
4
+ * `blo install` command - installs a package generated by `berks package` into your configured Chef Server
5
+
6
+ * Enhancements
7
+ * Support `latest` as a version number in upgrade. This will upgrade the environment to the latest version of the given cookbook
8
+ * Leaving the version blank in upgrade will upgrade the environment to the latest version
9
+ * Upgrade won't occur if the environment is already at the given version. Override with the `--force` flag
10
+ * `blo install` aliased to `blo in`
11
+ * `blo upgrade` aliased to `blo up`
12
+
13
+ * Bug Fixes
14
+ * Now possible to install from the generated Gemfile. Previously was using many unreleased gems and dependencies.
15
+
16
+ # 0.1.0
17
+
18
+ Initial release
19
+
20
+ * Features
21
+ * `blo upgrade` command - upgrade an existing Chef Environment to the given cookbook version
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- gem "berkshelf", github: "berkshelf/berkshelf"
6
- gem "ridley", github: "RiotGames/ridley"
data/README.md CHANGED
@@ -14,7 +14,7 @@ A command line tool for managing Chef Environments using Berkshelf and the [Envi
14
14
 
15
15
  ### Upgrading a Chef Environment
16
16
 
17
- Berkflow exposes a command for configuring a Chef Environment and running Chef Client on all nodes in that environment.
17
+ Berkflow exposes a command for configuring a Chef Environment to a specific Environment Cookbook version and running Chef Client on all nodes in that environment.
18
18
 
19
19
  $ blo upgrade myface-dev myface 1.2.3
20
20
  Applying cookbook locks to myface-dev...
@@ -23,6 +23,14 @@ Berkflow exposes a command for configuring a Chef Environment and running Chef C
23
23
  Successfully ran Chef Client on 10 nodes
24
24
  Done. See berkflow_out/20140331172904 for logs.
25
25
 
26
+ You can also upgrade to the latest version of the cookbook found on the Chef Server by passing `latest`
27
+
28
+ $ blo upgrade myface-dev myface latest
29
+
30
+ or simply leaving the version blank
31
+
32
+ $ blo upgrade myface-dev myface
33
+
26
34
  Your Chef Server must meet the following requirements:
27
35
 
28
36
  * The `myface-dev` environment must exist
@@ -57,9 +65,24 @@ Shell commands executed with `blo exec` are by default not run with sudo. Use th
57
65
 
58
66
  $ blo exec myface-dev "ls -lah" --sudo
59
67
 
68
+ ### Installing Berkshelf packages into a Chef server
69
+
70
+ Packages generated by `berks package` can be easily installed into a Chef Server with Berkflow.
71
+
72
+ $ blo install https://github.com/berkshelf/berkshelf-cookbook/releases/download/v0.3.1/cookbooks.tar.gz
73
+
74
+ It works with filepaths, too
75
+
76
+ $ blo install cookbooks.tar.gz
77
+
78
+ Installing a package will upload and freeze each cookbook into your configured Chef Server. Already frozen cookbooks
79
+ will be skipped unless you specify the --force flag.
80
+
81
+ $ blo install cookbooks.tar.gz --force
82
+
60
83
  ## Contributing
61
84
 
62
- 1. Fork it ( https://github.com/[my-github-username]/berkflow/fork )
85
+ 1. Fork it ( https://github.com/reset/berkflow/fork )
63
86
  2. Create your feature branch (`git checkout -b my-new-feature`)
64
87
  3. Commit your changes (`git commit -am 'Add some feature'`)
65
88
  4. Push to the branch (`git push origin my-new-feature`)
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "solve"
22
- spec.add_dependency "berkshelf", "~> 3.0.0.beta7"
23
- spec.add_dependency "ridley", "~> 2.5"
24
- spec.add_dependency "ridley-connectors", "~> 1.7.0"
22
+ spec.add_dependency "berkshelf", "~> 3.0.0.beta8"
23
+ spec.add_dependency "ridley", "~> 3.0.0.rc1"
24
+ spec.add_dependency "ridley-connectors", "~> 2.0.0.rc1"
25
25
  spec.add_dependency "thor", "~> 0.18"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.6"
@@ -18,6 +18,13 @@ module Berkflow
18
18
  end
19
19
  end
20
20
 
21
+ LATEST = "latest".freeze
22
+
23
+ namespace "berkflow"
24
+
25
+ map "up" => :upgrade
26
+ map "in" => :install
27
+
21
28
  class_option :verbose,
22
29
  type: :boolean,
23
30
  desc: "Output verbose information",
@@ -44,6 +51,86 @@ module Berkflow
44
51
  aliases: "-P",
45
52
  default: nil
46
53
 
54
+ method_option :force,
55
+ type: :boolean,
56
+ aliases: "-f",
57
+ desc: "Upload cookbooks even if they are already present and frozen.",
58
+ default: false
59
+ desc "install URL", "install Berkshelf package into the Chef Server."
60
+ def install(url)
61
+ require 'uri'
62
+ require 'open-uri'
63
+ require 'zlib'
64
+ require 'rubygems/package'
65
+
66
+ if is_url?(url)
67
+ tempfile = Tempfile.new("berkflow")
68
+ begin
69
+ open(url) { |remote_file| tempfile.write(remote_file.read) }
70
+ rescue OpenURI::HTTPError => ex
71
+ error "Error retrieving remote package: #{ex.message}."
72
+ exit(1)
73
+ end
74
+ url = tempfile.path
75
+ end
76
+
77
+ unless File.exist?(url)
78
+ error "Package not found: #{url}."
79
+ exit(1)
80
+ end
81
+
82
+ tmpdir = Dir.mktmpdir("berkflow")
83
+
84
+ begin
85
+ zlib = Zlib::GzipReader.new(File.open(url, "rb"))
86
+ io = StringIO.new(zlib.read)
87
+ zlib.close
88
+
89
+ Gem::Package::TarReader.new io do |tar|
90
+ tar.each do |tarfile|
91
+ destination_file = File.join(tmpdir, tarfile.full_name)
92
+
93
+ if tarfile.directory?
94
+ FileUtils.mkdir_p(destination_file)
95
+ else
96
+ destination_directory = File.dirname(destination_file)
97
+ FileUtils.mkdir_p(destination_directory) unless File.directory?(destination_directory)
98
+ File.open(destination_file, "wb") { |f| f.print tarfile.read }
99
+ end
100
+ end
101
+ end
102
+ rescue Zlib::GzipFile::Error => ex
103
+ error "Error extracting package: #{ex.message}"
104
+ exit(1)
105
+ end
106
+
107
+ cookbooks_dir = File.join(tmpdir, "cookbooks")
108
+
109
+ unless File.exist?(cookbooks_dir)
110
+ error "Package did not contain a 'cookbooks' directory."
111
+ exit(1)
112
+ end
113
+
114
+ uploaded = Dir.entries(cookbooks_dir).collect do |path|
115
+ path = File.join(cookbooks_dir, path)
116
+ next unless File.cookbook?(path)
117
+ begin
118
+ cookbook = Ridley::Chef::Cookbook.from_path(path)
119
+ say "Uploading #{cookbook.cookbook_name} (#{cookbook.version})"
120
+ ridley.cookbook.upload(path, freeze: true, force: options[:force])
121
+ true
122
+ rescue Ridley::Errors::FrozenCookbook
123
+ true
124
+ end
125
+ end.compact
126
+
127
+ say "Uploaded #{uploaded.length} cookbooks."
128
+ say "Done."
129
+ ensure
130
+ tempfile.close(true) if tempfile
131
+ FileUtils.rm_rf(tmpdir) if tmpdir
132
+ end
133
+
47
134
  method_option :sudo,
48
135
  type: :boolean,
49
136
  desc: "Execute with sudo",
@@ -102,12 +189,31 @@ module Berkflow
102
189
  failures.empty? ? exit(0) : exit(1)
103
190
  end
104
191
 
105
- desc "upgrade ENV APP VERSION", "upgrade an environment to a specific application version."
106
- def upgrade(environment, application, version)
192
+ method_option :force,
193
+ type: :boolean,
194
+ aliases: "-f",
195
+ desc: "Upgrade an environment even if it's already at the given version.",
196
+ default: false
197
+ desc "upgrade ENV APP [VERSION]", "upgrade an environment to the specified cookbook version."
198
+ long_desc <<-EOH
199
+ Upgrades an environment to the specified cookbook version. If no version is given then the latest
200
+ version of the cookbook found on the Chef Server will be used.
201
+ EOH
202
+ def upgrade(environment, application, version = LATEST)
107
203
  version = sanitize_version(version)
108
204
  env = find_environment!(environment)
109
205
  cookbook = find_cookbook!(application, version)
110
206
 
207
+ unless options[:force]
208
+ if locked = env.cookbook_versions[application]
209
+ if Solve::Constraint.new(locked).version.to_s == cookbook.version
210
+ say "Environment already at #{cookbook.version}."
211
+ say "Done."
212
+ exit(0)
213
+ end
214
+ end
215
+ end
216
+
111
217
  file = Tempfile.new("berkflow")
112
218
  unless contents = cookbook.download_file(:root_file, Berkshelf::Lockfile::DEFAULT_FILENAME, file.path)
113
219
  error "#{application} (#{version}) did not contain a Berksfile.lock"
@@ -158,13 +264,26 @@ module Berkflow
158
264
  end
159
265
 
160
266
  def sanitize_version(version)
267
+ return version if version == LATEST
268
+
161
269
  Solve::Version.new(version).to_s
162
270
  rescue Solve::Errors::InvalidVersionFormat
163
271
  error "Invalid version: #{version}. Provide a valid SemVer version string. (i.e. 1.2.3)."
164
272
  exit(1)
165
273
  end
166
274
 
275
+ def is_url?(string)
276
+ string =~ /^#{URI::regexp}$/
277
+ end
278
+
167
279
  def find_cookbook!(application, version)
280
+ if version == LATEST
281
+ unless version = ridley.cookbook.latest_version(application)
282
+ error "No versions of Cookbook found: #{application}."
283
+ exit(1)
284
+ end
285
+ end
286
+
168
287
  unless cookbook = ridley.cookbook.find(application, version)
169
288
  error "Cookbook not found: #{application} (#{version})."
170
289
  exit(1)
@@ -1,3 +1,3 @@
1
1
  module Berkflow
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-01 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solve
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0.0.beta7
33
+ version: 3.0.0.beta8
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0.0.beta7
40
+ version: 3.0.0.beta8
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ridley
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '2.5'
47
+ version: 3.0.0.rc1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '2.5'
54
+ version: 3.0.0.rc1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ridley-connectors
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 1.7.0
61
+ version: 2.0.0.rc1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 1.7.0
68
+ version: 2.0.0.rc1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -118,8 +118,8 @@ extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
120
  - .gitignore
121
+ - CHANGELOG.md
121
122
  - Gemfile
122
- - Gemfile.lock
123
123
  - LICENSE
124
124
  - README.md
125
125
  - Rakefile
@@ -153,4 +153,3 @@ signing_key:
153
153
  specification_version: 4
154
154
  summary: A Cookbook-Centric Deployment workflow tool
155
155
  test_files: []
156
- has_rdoc: