clc-promote 0.3.4 → 0.3.5

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: 6bb2e8ce77e8107d62b221d47dcd485a1b8cfd78
4
- data.tar.gz: 484229a859e81b88a960bafc7c5ef690a75c7faf
3
+ metadata.gz: d1648dc80e86e5091475fbfd5a3f37af2d205650
4
+ data.tar.gz: 517af2fb1dfc639eb0c7ee913b06203b8e54f10d
5
5
  SHA512:
6
- metadata.gz: 6efb5d1e4c07b4bf5279729caf7415fa1007809f66a683632658d79127785e9f25b5442f2e3d6bedefbe4dadbfa6980798c83453848ae2a170885b88a2f56e4f
7
- data.tar.gz: 14fc885442580739a00e46ab152d27baf4ef7adfa33d5d7d6451c3036f504dab57d2039fbdfe524673a246bf85fadb57b303e364fe0481df3751c6e537673efc
6
+ metadata.gz: f3707c1103ab6bab1a1e1e5279af57858274073a16b4240212b9ebc2ba611369505785fd2b3d547afa683d5091888dd811b8d6fbba4088946ef2353f8291436b
7
+ data.tar.gz: 044f7283e1ba7275c6f29ee1a0d5a77897741d0b9fff09486398af22e33ca35484b65d6afd8d2200c29c6886abaf7e84e18a9cc116a746030e6fb7fdd73e4c10
data/README.md CHANGED
@@ -72,7 +72,7 @@ Bumps the versions of all databag entries.
72
72
  Performs a berks install on all cookbooks in the chef repo.
73
73
 
74
74
  ### Promote:upload_cookbooks
75
- Uploads all cookbooks to the chef server. **Note**: only cookbooks that have been bumped will be uploaded. Uploaded cookbooks are frozen.
75
+ Uploads all cookbook versions of an environment to the chef server. **Note**: only cookbooks that have been bumped will be uploaded. Uploaded cookbooks are frozen.
76
76
 
77
77
  ### Promote:upload_environment
78
78
  Uploads an environment file to the chef server
data/lib/promote.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'promote/config'
2
+ require 'promote/environment_file'
2
3
  require 'promote/git_helper'
3
4
  require 'promote/uploader'
4
5
  require 'promote/versioner'
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+
3
+ module Promote
4
+ class EnvironmentFile
5
+ attr_accessor :name
6
+
7
+ def initialize(environment_name, config)
8
+ @name = environment_name
9
+ @config = config
10
+ end
11
+
12
+ def file_path
13
+ File.join(@config.environment_directory, "#{name}.json")
14
+ end
15
+
16
+ def cookbook_versions
17
+ content.has_key?('cookbook_versions') ? content['cookbook_versions'] : {}
18
+ end
19
+
20
+ def write_cookbook_versions(versions)
21
+ content['cookbook_versions'] = versions
22
+
23
+ File.open(file_path, 'w') do |out|
24
+ out << JSON.pretty_generate(content)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def content
31
+ @content ||= get_environment_content
32
+ end
33
+
34
+ def get_environment_content
35
+ JSON.parse(File.read(file_path))
36
+ end
37
+ end
38
+ end
@@ -9,17 +9,10 @@ module Promote
9
9
  end
10
10
 
11
11
  def promote_to(source_environment, destination_environment)
12
- source_file = File.join(config.environment_directory, "#{source_environment}.json")
13
- dest_file = File.join(config.environment_directory, "#{destination_environment}.json")
12
+ source = EnvironmentFile.new(source_environment, config)
13
+ dest = EnvironmentFile.new(destination_environment, config)
14
14
 
15
- source_content = JSON.parse(File.read(source_file))
16
- dest_content = JSON.parse(File.read(dest_file))
17
-
18
- dest_content['cookbook_versions'] = source_content['cookbook_versions']
19
-
20
- File.open(dest_file, 'w') do |out|
21
- out << JSON.pretty_generate(dest_content)
22
- end
15
+ dest.write_cookbook_versions(source.cookbook_versions)
23
16
  end
24
17
 
25
18
  def stage_promotion(promote_environment, destination_config, ui)
@@ -35,8 +28,8 @@ module Promote
35
28
 
36
29
  ui.info "Downloading cookbooks..."
37
30
  server_versions = Promote::Utils.chef_server_cookbooks(destination_config)
38
- env_content = JSON.parse(File.read(File.join(config.temp_directory, deploy_file)))
39
- env_content['cookbook_versions'].each do |k,v|
31
+ env_content = EnvironmentFile.new(promote_environment, Config.new({:repo_root => config.temp_directory}))
32
+ env_content.cookbook_versions.each do |k,v|
40
33
  if !server_versions.has_key?(k) || (server_versions[k]["versions"].select {|version| version['version'] == v}).empty?
41
34
  ui.info "#{k}-#{v}"
42
35
  download_files(config.temp_directory, "/cookbooks/#{k}", v)
@@ -126,10 +126,10 @@ module Promote
126
126
 
127
127
  def define_upload_cookbooks
128
128
  namespace "Promote" do
129
- desc "Upload all cookbooks to chef server"
130
- task "upload_cookbooks" do
129
+ desc "Upload all cookbooks in an environment to the chef server"
130
+ task "upload_cookbooks", :environment do |task, args|
131
131
  puts "Uploading cookbooks not already on server..."
132
- @uploader.upload_cookbooks
132
+ @uploader.upload_cookbooks(args.environment)
133
133
  end
134
134
  end
135
135
  end
@@ -22,30 +22,28 @@ module Promote
22
22
  Chef::Config[:chef_repo_path] = config.repo_root
23
23
  end
24
24
 
25
- def upload_cookbooks
26
- nothing_to_upload = true
25
+ def upload_cookbooks(environment)
26
+ anything_to_upload = false
27
27
  server_cookbooks = Utils.chef_server_cookbooks(config)
28
28
  FileUtils.rm_rf(config.temp_directory) if Dir.exist?(config.temp_directory)
29
29
  Dir.mkdir(config.temp_directory)
30
+
31
+ env_versions = EnvironmentFile.new(environment, config).cookbook_versions
30
32
  Dir.glob(File.expand_path("~/.berkshelf/cookbooks/*")).each do | dir |
31
33
  cp_name = File.basename(dir)
32
34
  idx = cp_name.rindex('-')
33
- if !server_cookbooks.has_key?(cp_name[0,idx]) || (server_cookbooks[cp_name[0,idx]]["versions"].select {|v| v['version'] == cp_name[idx+1,cp_name.length-idx]}).empty?
34
- FileUtils.copy_entry(dir, File.join(config.temp_directory, cp_name[0,idx]))
35
- nothing_to_upload = false
36
- end
35
+ cb_name = cp_name[0,idx]
36
+ cb_version = cp_name[idx+1,cp_name.length-idx]
37
+ anything_to_upload = cookbooks_copied?(cb_name, cb_version, dir, server_cookbooks, env_versions)
37
38
  end
38
39
 
39
40
  Dir.glob(File.join(config.cookbook_directory, "*")).each do | dir |
40
41
  metadata = Chef::Cookbook::Metadata.new
41
42
  metadata.from_file(File.join(dir, "metadata.rb"))
42
- if !server_cookbooks.has_key?(metadata.name) || (server_cookbooks[metadata.name]["versions"].select {|v| v['version'] == metadata.version}).empty?
43
- FileUtils.copy_entry(dir, File.join(config.temp_directory, metadata.name))
44
- nothing_to_upload = false
45
- end
43
+ anything_to_upload = cookbooks_copied?(metadata.name, metadata.version, dir, server_cookbooks, env_versions) || anything_to_upload
46
44
  end
47
45
 
48
- if !nothing_to_upload
46
+ if anything_to_upload
49
47
  upload_cookbook_directory(config.temp_directory)
50
48
  end
51
49
  end
@@ -72,6 +70,16 @@ module Promote
72
70
 
73
71
  private
74
72
 
73
+ #only include versions in environment but exclude whats on the server
74
+ def cookbooks_copied?(name, version, dir, server_cookbooks, environment_cookbooks)
75
+ if !server_cookbooks.has_key?(name) || (server_cookbooks[name]["versions"].select {|v| v['version'] == version}).empty?
76
+ if environment_cookbooks.has_key?(name) && environment_cookbooks[name] == version
77
+ FileUtils.copy_entry(dir, File.join(config.temp_directory, name))
78
+ true
79
+ end
80
+ end
81
+ end
82
+
75
83
  def upload_file(file_path)
76
84
  fs_config = Chef::ChefFS::Config.new
77
85
  pattern = Chef::ChefFS::FilePattern.new(file_path)
@@ -92,16 +92,13 @@ module Promote
92
92
 
93
93
  def constrain_environment(environment_name, cookbook_name)
94
94
  dependencies = environment_dependencies(cookbook_name)
95
- env_file = File.join(config.environment_directory, "#{environment_name}.json")
96
- content = JSON.parse(File.read(env_file))
97
- content['cookbook_versions'] = {}
95
+ env_file = EnvironmentFile.new(environment_name, config)
96
+ versions = {}
98
97
  dependencies.each do | dep |
99
- content['cookbook_versions'][dep.name] = dep.locked_version.to_s
98
+ versions[dep.name] = dep.locked_version.to_s
100
99
  end
101
100
 
102
- File.open(env_file, 'w') do |out|
103
- out << JSON.pretty_generate(content)
104
- end
101
+ env_file.write_cookbook_versions(versions)
105
102
  dependencies
106
103
  end
107
104
 
@@ -109,10 +106,9 @@ module Promote
109
106
  dependencies = environment_dependencies(environment_cookbook)
110
107
  cb_dependency = (dependencies.select { |dep| dep.name == cookbook_name })[0]
111
108
 
112
- env_file = File.join(config.environment_directory, "#{environment_name}.json")
113
- content = JSON.parse(File.read(env_file))
114
- if content.has_key?('cookbook_versions') && content['cookbook_versions'].has_key?(cookbook_name)
115
- return cb_dependency.locked_version.to_s != content['cookbook_versions'][cookbook_name]
109
+ env_file = EnvironmentFile.new(environment_name, config)
110
+ if env_file.cookbook_versions.has_key?(cookbook_name)
111
+ return cb_dependency.locked_version.to_s != env_file.cookbook_versions[cookbook_name]
116
112
  else
117
113
  return true
118
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clc-promote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -115,6 +115,7 @@ files:
115
115
  - lib/chef/knife/promote.rb
116
116
  - lib/promote.rb
117
117
  - lib/promote/config.rb
118
+ - lib/promote/environment_file.rb
118
119
  - lib/promote/git_helper.rb
119
120
  - lib/promote/promoter.rb
120
121
  - lib/promote/rake_tasks.rb