product_metadata_tasks 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f65924237573761f1db6c2c4c8f9477f2deb035
4
+ data.tar.gz: b59ca37523e8e1de37e4a5064f8184ab0496a496
5
+ SHA512:
6
+ metadata.gz: 4bcd34fcdbde5ede0b78d987254ae984e34f3f02f2d0685abbd8344f95b39acd2609863c00273a81866017f48137da757298db1cd3e0504d0bfa197641fc2437
7
+ data.tar.gz: 8781c3f3c237d42a636bac5b44c6e83d1d2e45a555f723314c7bb9f2c955e53776f63f784b373716f61754501b363ce27b02ea0208d6bde62fd19a32cc16ebe3
@@ -0,0 +1,15 @@
1
+ require 'product_metadata_tasks/tasks'
2
+
3
+ # Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
4
+ #
5
+ # Unauthorized use, copying or distribution of this source code via any
6
+ # medium is strictly prohibited without the express written consent of
7
+ # Pivotal Software, Inc.
8
+ #
9
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
12
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
13
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
14
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
15
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ require 'uri'
2
+ require 'httparty'
3
+ require 'pathname'
4
+
5
+ module ProductMetadataTasks
6
+ class Stemcell
7
+ def initialize(url_string)
8
+ @url = url_string
9
+
10
+ raise "Not a URL: #{url_string}" unless url.is_a?(URI::HTTP)
11
+ end
12
+
13
+ def version
14
+ /bosh\-stemcell\-([^-]+)/.match(file).captures.first
15
+ end
16
+
17
+ def file
18
+ url.path.split('/').last
19
+ end
20
+
21
+ def md5
22
+ response = HTTParty.head(url.to_s)
23
+ response.headers['etag'].gsub('"','')
24
+ end
25
+
26
+ def url
27
+ URI.parse(@url)
28
+ end
29
+ end
30
+ end
31
+
32
+ # Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
33
+ #
34
+ # Unauthorized use, copying or distribution of this source code via any
35
+ # medium is strictly prohibited without the express written consent of
36
+ # Pivotal Software, Inc.
37
+ #
38
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
39
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
42
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
43
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
44
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ require 'yaml'
2
+
3
+ require 'product_metadata_tasks/stemcell'
4
+
5
+ module ProductMetadataTasks
6
+ class StemcellUpdateTask
7
+ def initialize(stemcell_url, binaries_path)
8
+ @binaries_path = binaries_path
9
+ @stemcell = Stemcell.new(stemcell_url)
10
+
11
+ check_binaries_path!
12
+ end
13
+
14
+ def run(verbose=false)
15
+ binaries_config = load_binaries_config
16
+
17
+ binaries_config['stemcell']['version'] = stemcell.version
18
+ binaries_config['stemcell']['file'] = stemcell.file
19
+ binaries_config['stemcell']['md5'] = stemcell.md5
20
+
21
+ persist_binaries_config(binaries_config)
22
+
23
+ if verbose
24
+ puts "Updated stemcell to #{stemcell.file}"
25
+ puts ''
26
+ puts `git diff #{binaries_path}`
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :binaries_path, :stemcell
33
+
34
+ def load_binaries_config
35
+ YAML.load_file(binaries_path)
36
+ end
37
+
38
+ def persist_binaries_config(config)
39
+ yaml = config.to_yaml
40
+ File.open(binaries_path,'w'){ |f| f.write(yaml) }
41
+ end
42
+
43
+ def check_binaries_path!
44
+ raise "#{binaries_path} not found, are you sure this is an ops manager product directory?" unless File.exist?(binaries_path)
45
+ end
46
+ end
47
+ end
48
+
49
+ # Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
50
+ #
51
+ # Unauthorized use, copying or distribution of this source code via any
52
+ # medium is strictly prohibited without the express written consent of
53
+ # Pivotal Software, Inc.
54
+ #
55
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
59
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
60
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
61
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ require 'rake'
2
+
3
+ require 'product_metadata_tasks/stemcell_update_task'
4
+ require 'product_metadata_tasks/version_number_update_task'
5
+
6
+ namespace :metadata do
7
+ desc 'Available stemcells'
8
+ task :available_stemcells do
9
+ output = `bosh public stemcells --full --all`
10
+
11
+ puts output.split("\n").select{|l| l =~ /bosh-stemcell/ }.map{|l| l.split("|")[2].strip }
12
+ end
13
+
14
+ desc 'Update to a specific stemcell'
15
+ task :update_stemcell, [:url] do |t, args|
16
+ ProductMetadataTasks::StemcellUpdateTask.new(args[:url], File.expand_path('metadata_parts/binaries.yml')).run(true)
17
+ end
18
+
19
+ desc 'Update the version number in the metadata and migrations'
20
+ task :update_product_version, [:version_number,:minimum_supported_opsman_version] do |t, args|
21
+ args.with_defaults(minimum_supported_opsman_version: "1.6")
22
+ ProductMetadataTasks::VersionNumberUpdateTask.new(Dir.pwd).update_version(
23
+ args[:version_number],
24
+ args[:minimum_supported_opsman_version]
25
+ )
26
+ end
27
+
28
+ desc 'Create a migration'
29
+ task :create_migration, [:from_version, :to_version] do |t, args|
30
+ ProductMetadataTasks::VersionNumberUpdateTask.new(Dir.pwd).create_new_migration(args[:from_version], args[:to_version])
31
+ end
32
+ end
33
+
34
+ # Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
35
+ #
36
+ # Unauthorized use, copying or distribution of this source code via any
37
+ # medium is strictly prohibited without the express written consent of
38
+ # Pivotal Software, Inc.
39
+ #
40
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
41
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
44
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
45
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
46
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ module ProductMetadataTasks
2
+ VERSION = '1.0.0'
3
+ end
4
+
5
+ # Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
6
+ #
7
+ # Unauthorized use, copying or distribution of this source code via any
8
+ # medium is strictly prohibited without the express written consent of
9
+ # Pivotal Software, Inc.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
15
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
16
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
17
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,100 @@
1
+ module ProductMetadataTasks
2
+ class VersionNumberUpdateTask
3
+ def initialize(root_directory)
4
+ raise "root_directory not found" unless File.directory?(root_directory)
5
+ @root_directory = Pathname.new(root_directory)
6
+ end
7
+
8
+ def update_version(version_number, supported_opsman_version = "1.6")
9
+ update_binaries_yml(version_number)
10
+ if Gem::Version.new(supported_opsman_version) < Gem::Version.new("1.7")
11
+ update_content_migrations(version_number)
12
+ end
13
+ end
14
+
15
+ def create_new_migration(version_from, version_to)
16
+ migration = {
17
+ "from_version" => version_from,
18
+ "rules" => [{
19
+ "type" => "update",
20
+ "selector" => "product_version",
21
+ "to" => "#{version_to}$PRERELEASE_VERSION$"
22
+ }]
23
+ }
24
+ write_yaml(migration, File.join(migrations_directory_path, "from_#{version_from}.yml"))
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :root_directory
30
+
31
+ def update_binaries_yml(version_number)
32
+ binaries_yml = get_yaml(binaries_file_path)
33
+ binaries_yml["product_version"] = version_number + "$PRERELEASE_VERSION$"
34
+ binaries_yml["provides_product_versions"].each do |element|
35
+ element["version"] = version_number
36
+ end
37
+ write_yaml(binaries_yml, binaries_file_path)
38
+ end
39
+
40
+ def update_content_migrations(version_number)
41
+ base_yml = get_yaml(base_file_path)
42
+ old_version = base_yml["to_version"].split("$").first
43
+ base_yml["to_version"] = version_number + "$PRERELEASE_VERSION$"
44
+ write_yaml(base_yml, base_file_path)
45
+
46
+ migration_file_paths.each do |migration_file|
47
+ migration_path = migrations_directory_path.join(migration_file)
48
+ migration_yml = get_yaml(migration_path)
49
+ migration_yml["rules"].each do |element|
50
+ element["to"] = version_number + "$PRERELEASE_VERSION$" if element["selector"] == "product_version"
51
+ end
52
+ write_yaml(migration_yml, migration_path)
53
+ end
54
+
55
+ create_new_migration(old_version, version_number)
56
+ end
57
+
58
+ def binaries_file_path
59
+ root_directory.join('metadata_parts/binaries.yml')
60
+ end
61
+
62
+ def base_file_path
63
+ root_directory.join('content_migrations_parts/base.yml')
64
+ end
65
+
66
+ def migrations_directory_path
67
+ root_directory.join('content_migrations_parts/migrations')
68
+ end
69
+
70
+ def migration_file_paths
71
+ Dir.entries(migrations_directory_path).select do |entry|
72
+ entry.end_with?('.yml')
73
+ end
74
+ end
75
+
76
+ def write_yaml(yaml, path)
77
+ File.open(path, 'w') do |f|
78
+ f.write yaml.to_yaml
79
+ end
80
+ end
81
+
82
+ def get_yaml(path)
83
+ YAML.load(File.read(path))
84
+ end
85
+ end
86
+ end
87
+
88
+ # Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
89
+ #
90
+ # Unauthorized use, copying or distribution of this source code via any
91
+ # medium is strictly prohibited without the express written consent of
92
+ # Pivotal Software, Inc.
93
+ #
94
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
95
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
96
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
97
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
98
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
99
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
100
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: product_metadata_tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - CF London
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gemfury
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-mocks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.1.0
83
+ description: A library of rake tasks for repetitive updates to product metadata.
84
+ email:
85
+ - cf-london-eng@pivotal.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/product_metadata_tasks.rb
91
+ - lib/product_metadata_tasks/stemcell.rb
92
+ - lib/product_metadata_tasks/stemcell_update_task.rb
93
+ - lib/product_metadata_tasks/tasks.rb
94
+ - lib/product_metadata_tasks/version.rb
95
+ - lib/product_metadata_tasks/version_number_update_task.rb
96
+ homepage:
97
+ licenses: []
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.6.4
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: A library of rake tasks for repetitive updates to product metadata.
119
+ test_files: []