vanagon 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb77baf3c8dca42c4cec74d3a31c74af63ee37df
4
- data.tar.gz: 32949fe6e83be1972bc91057b5a522b116de0bc2
3
+ metadata.gz: 931b3b9e351487626cfc70250f5515612364a25d
4
+ data.tar.gz: 41efa48f0508c3c030650b13991b7049153f1e56
5
5
  SHA512:
6
- metadata.gz: e2a8b0411fc595f95b40c8f63229f73ed4324f9712c9c04dab01340a95fa27246e305cc0d44b7a7c7b7b2a5725ac6991971607d31eb7313a4953baf60fe7bb98
7
- data.tar.gz: 5b6ee385067ff48a3befb3f2d5abc796a3b7589ef389534c2ab3d2a0840a85982f1eca22a3365c2a4f875a1619cc722fc1f7655118c273e47793d63f596d9c28
6
+ metadata.gz: 3b15f73c6cee6de81dd0b4e0b53d7d72bd1dc02dd4d9eb1e11f5b114dba410828089552fb68db206907514d853d0c5a88d8f43718d3c2ccd7f16e5dabaa9bee2
7
+ data.tar.gz: 2bb2d911f8046369d1807937e017a56aaff4c0f8ee82ae6a13cfda544765a487158be6e4d9e1be2dad9b4ac762fb7d42f988c575ad01c90f58d9d796f6f5e3f0
@@ -214,7 +214,7 @@ class Vanagon
214
214
  end
215
215
 
216
216
  # Register the service for use in packaging
217
- @component.service = OpenStruct.new(:name => service_name, :service_file => target_service_file)
217
+ @component.service = OpenStruct.new(:name => service_name, :service_file => target_service_file, :type => service_type)
218
218
  end
219
219
 
220
220
  # Copies a file from source to target during the install phase of the component
@@ -1,5 +1,6 @@
1
1
  require 'vanagon/component/source/http'
2
2
  require 'vanagon/component/source/git'
3
+ require 'vanagon/component/source/localsource'
3
4
 
4
5
  class Vanagon
5
6
  class Component
@@ -64,7 +65,7 @@ class Vanagon
64
65
  when /^http/
65
66
  Vanagon::Component::Source::Http.new(self.rewrite(url, 'http'), options[:sum], workdir)
66
67
  when /^file/
67
- Vanagon::Component::Source::Http.new(self.rewrite(url, 'file'), options[:sum], workdir)
68
+ Vanagon::Component::Source::LocalSource.new(self.rewrite(url, 'file'), workdir)
68
69
  when /^git/
69
70
  Vanagon::Component::Source::Git.new(self.rewrite(url, 'git'), options[:ref], workdir)
70
71
  else
@@ -52,7 +52,6 @@ class Vanagon
52
52
  uri = URI.parse(@url)
53
53
  target_file = File.basename(uri.path)
54
54
  puts "Downloading file '#{target_file}' from url '#{@url}'"
55
-
56
55
  case uri.scheme
57
56
  when 'http', 'https'
58
57
  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
@@ -69,17 +68,6 @@ class Vanagon
69
68
  end
70
69
  end
71
70
  end
72
- when 'file'
73
- uri = @url.match(/^file:\/\/(.*)$/)
74
- if uri
75
- source_file = uri[1]
76
- target_file = File.basename(source_file)
77
- FileUtils.cp(source_file, File.join(@workdir, target_file))
78
- else
79
- raise Vanagon::Error, "Unable to parse '#{@url}' for local file path."
80
- end
81
- else
82
- fail "Unable to download files using the uri scheme '#{uri.scheme}'. Maybe you have a typo or need to teach me a new trick?"
83
71
  end
84
72
 
85
73
  target_file
@@ -0,0 +1,119 @@
1
+ require 'vanagon/utilities'
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ class Vanagon
6
+ class Component
7
+ class Source
8
+ class LocalSource
9
+ include Vanagon::Utilities
10
+ attr_accessor :url, :file, :extension, :workdir, :cleanup
11
+
12
+ # Extensions for files we intend to unpack during the build
13
+ ARCHIVE_EXTENSIONS = '.tar.gz', '.tgz', '.zip'
14
+
15
+ # Constructor for the File source type
16
+ #
17
+ # @param url [String] url of the http source to fetch
18
+ # @param workdir [String] working directory to download into
19
+ def initialize(url, workdir)
20
+ @url = url
21
+ @workdir = workdir
22
+ end
23
+
24
+ # Download the source from the url specified. Sets the full path to the
25
+ # file as @file and the @extension for the file as a side effect.
26
+ def fetch
27
+ @file = download
28
+ @extension = get_extension
29
+ end
30
+
31
+ # Local files need no checksum so this is a noop
32
+ def verify
33
+ # nothing to do here, so just return
34
+ end
35
+
36
+ # Moves file from source to workdir
37
+ #
38
+ # @raise [RuntimeError, Vanagon::Error] an exception is raised if the URI scheme cannot be handled
39
+ def download
40
+ uri = URI.parse(@url)
41
+ target_file = File.basename(uri.path)
42
+ puts "Moving file '#{target_file}' to workdir"
43
+
44
+ uri = @url.match(/^file:\/\/(.*)$/)
45
+ if uri
46
+ source_file = uri[1]
47
+ target_file = File.basename(source_file)
48
+ FileUtils.cp(source_file, File.join(@workdir, target_file))
49
+ else
50
+ raise Vanagon::Error, "Unable to parse '#{@url}' for local file path."
51
+ end
52
+
53
+ target_file
54
+
55
+ end
56
+
57
+ # Gets the command to extract the archive given if needed (uses @extension)
58
+ #
59
+ # @param tar [String] the tar command to use
60
+ # @return [String, nil] command to extract the source
61
+ # @raise [RuntimeError] an exception is raised if there is no known extraction method for @extension
62
+ def extract(tar)
63
+ if ARCHIVE_EXTENSIONS.include?(@extension)
64
+ case @extension
65
+ when ".tar.gz", ".tgz"
66
+ return "gunzip -c '#{@file}' | '#{tar}' xf -"
67
+ when ".zip"
68
+ return "unzip '#{@file}' || 7za x -r -tzip -o'#{File.basename(@file, ".zip")}' '#{@file}'"
69
+ end
70
+ else
71
+ # Extension does not appear to be an archive
72
+ return ':'
73
+ end
74
+ end
75
+
76
+ # Return the correct incantation to cleanup the source archive and source directory for a given source
77
+ #
78
+ # @return [String] command to cleanup the source
79
+ # @raise [RuntimeError] an exception is raised if there is no known extraction method for @extension
80
+ def cleanup
81
+ if ARCHIVE_EXTENSIONS.include?(@extension)
82
+ return "rm #{@file}; rm -r #{dirname}"
83
+ else
84
+ # Because dirname will be ./ here, we don't want to try to nuke it
85
+ return "rm #{@file}"
86
+ end
87
+ end
88
+
89
+ # Returns the extension for @file
90
+ #
91
+ # @return [String] the extension of @file
92
+ def get_extension
93
+ extension_match = @file.match(/.*(#{Regexp.union(ARCHIVE_EXTENSIONS)})/)
94
+ unless extension_match
95
+ if @file.split('.').last.include?('.')
96
+ return '.' + @file.split('.').last
97
+ else
98
+ # This is the case where the file has no extension
99
+ return @file
100
+ end
101
+ end
102
+ extension_match[1]
103
+ end
104
+
105
+ # The dirname to reference when building from the source
106
+ #
107
+ # @return [String] the directory that should be traversed into to build this source
108
+ # @raise [RuntimeError] if the @extension for the @file isn't currently handled by the method
109
+ def dirname
110
+ if ARCHIVE_EXTENSIONS.include?(@extension)
111
+ return @file.chomp(@extension)
112
+ else
113
+ return './'
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -137,7 +137,8 @@ class Vanagon
137
137
  # and reachable from the current commit in that repository.
138
138
  #
139
139
  def version_from_git
140
- @project.version = Vanagon::Utilities.git_version(File.expand_path("..", Vanagon::Driver.configdir)).gsub('-', '.')
140
+ version = Vanagon::Utilities.git_version(File.expand_path("..", Vanagon::Driver.configdir))
141
+ @project.version = version.split('-').reject(&:empty?).join('.')
141
142
  end
142
143
 
143
144
  # Sets the vendor for the project. Used in packaging artifacts.
@@ -44,7 +44,7 @@ depend fmri=pkg:/<%= requirement %> type=require
44
44
  <transform dir path=<%= strip_and_escape(File.dirname(service.service_file)) -%>$ -> drop>
45
45
  <%- end -%>
46
46
  <transform dir path=(var|lib)/svc/manifest$ -> drop>
47
- set name=org.opensolaris.smf.fmri <%= get_services.map {|service| "value=svc:/#{service.name}"}.join(" ") %>
47
+ set name=org.opensolaris.smf.fmri <%= get_services.map {|service| "value=svc:/#{service.type}/#{service.name}"}.join(" ") %>
48
48
  <%- end -%>
49
49
 
50
50
  <%- unless @bill_of_materials -%>
@@ -56,7 +56,7 @@ set name=org.opensolaris.smf.fmri <%= get_services.map {|service| "value=svc:/#{
56
56
  # Preserve the old conf file on upgrade, restart services on config file change
57
57
  <transform file path=<%= strip_and_escape(config.path) %>$ -> add preserve renamenew>
58
58
  <%- get_services.each do |service| -%>
59
- <transform file path=<%= strip_and_escape(config.path) %>$ -> add restart_fmri <%= "svc:/#{service.name}:*" %> >
59
+ <transform file path=<%= strip_and_escape(config.path) %>$ -> add restart_fmri <%= "svc:/#{service.type}/#{service.name}:*" %> >
60
60
  <%- end -%>
61
61
  <%- end -%>
62
62
 
File without changes
File without changes
File without changes
@@ -0,0 +1,41 @@
1
+ require 'vanagon/component/source/git'
2
+
3
+ describe "Vanagon::Component::Source::File" do
4
+ let (:file_base) { 'file://spec/fixtures/files/fake_file_ext' }
5
+ let (:tar_filename) { 'file://spec/fixtures/files/fake_dir.tar.gz' }
6
+ let (:plaintext_filename) { 'file://spec/fixtures/files/fake_file.txt' }
7
+ let (:workdir) { "/tmp" }
8
+
9
+ describe "#fetch" do
10
+ it "puts the source file in to the workdir" do
11
+ file = Vanagon::Component::Source::LocalSource.new(plaintext_filename, workdir)
12
+ file.fetch
13
+ expect(File).to exist("#{workdir}/fake_file.txt")
14
+ end
15
+ end
16
+
17
+ describe "#dirname" do
18
+ it "returns the name of the tarball, minus extension for archives" do
19
+ file = Vanagon::Component::Source::LocalSource.new(tar_filename, workdir)
20
+ file.fetch
21
+ expect(file.dirname).to eq("fake_dir")
22
+ end
23
+
24
+ it "returns the current directory for non-archive files" do
25
+ file = Vanagon::Component::Source::LocalSource.new(plaintext_filename, workdir)
26
+ file.fetch
27
+ expect(file.dirname).to eq("./")
28
+ end
29
+ end
30
+
31
+ describe "#get_extension" do
32
+ it "returns the extension for valid extensions" do
33
+ Vanagon::Component::Source::LocalSource::ARCHIVE_EXTENSIONS.each do |ext|
34
+ filename = "#{file_base}#{ext}"
35
+ file = Vanagon::Component::Source::LocalSource.new(filename, workdir)
36
+ file.fetch
37
+ expect(file.get_extension).to eq(ext)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -43,7 +43,7 @@ describe "Vanagon::Component::Source" do
43
43
  end
44
44
 
45
45
  it "returns an object of the correct type for file:// urls" do
46
- expect(Vanagon::Component::Source.source(file_url, {:sum => sum }, workdir).class).to equal(Vanagon::Component::Source::Http)
46
+ expect(Vanagon::Component::Source.source(file_url, {:sum => sum }, workdir).class).to equal(Vanagon::Component::Source::LocalSource)
47
47
  end
48
48
 
49
49
  it "applies any rewrite rules before defining an http Source" do
@@ -17,6 +17,14 @@ end" }
17
17
  proj.version_from_git
18
18
  expect(proj._project.version).to eq('1.2.3.1234')
19
19
  end
20
+ it 'sets the version based on the git describe with multiple dashes' do
21
+ expect(Vanagon::Driver).to receive(:configdir).and_return(configdir)
22
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
23
+ proj.instance_eval(project_block)
24
+ expect(Vanagon::Utilities).to receive(:git_version).with(File.expand_path('..', configdir)).and_return('1.2.3---1234')
25
+ proj.version_from_git
26
+ expect(proj._project.version).to eq('1.2.3.1234')
27
+ end
20
28
  end
21
29
 
22
30
  describe '#directory' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-31 00:00:00.000000000 Z
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -80,6 +80,7 @@ files:
80
80
  - lib/vanagon/component/source.rb
81
81
  - lib/vanagon/component/source/git.rb
82
82
  - lib/vanagon/component/source/http.rb
83
+ - lib/vanagon/component/source/localsource.rb
83
84
  - lib/vanagon/driver.rb
84
85
  - lib/vanagon/engine/base.rb
85
86
  - lib/vanagon/engine/docker.rb
@@ -140,6 +141,11 @@ files:
140
141
  - spec/fixtures/component/invalid-test-fixture.json
141
142
  - spec/fixtures/component/mcollective.service
142
143
  - spec/fixtures/component/test-fixture.json
144
+ - spec/fixtures/files/fake_dir.tar.gz
145
+ - spec/fixtures/files/fake_file.txt
146
+ - spec/fixtures/files/fake_file_ext.tar.gz
147
+ - spec/fixtures/files/fake_file_ext.tgz
148
+ - spec/fixtures/files/fake_file_ext.zip
143
149
  - spec/fixtures/wix/resources/windows/wix/file-1.wxs
144
150
  - spec/fixtures/wix/resources/windows/wix/file-2.wxs
145
151
  - spec/fixtures/wix/resources/windows/wix/file-3.wxs.erb
@@ -156,6 +162,7 @@ files:
156
162
  - spec/lib/vanagon/component/rules_spec.rb
157
163
  - spec/lib/vanagon/component/source/git_spec.rb
158
164
  - spec/lib/vanagon/component/source/http_spec.rb
165
+ - spec/lib/vanagon/component/source/localsource_spec.rb
159
166
  - spec/lib/vanagon/component/source_spec.rb
160
167
  - spec/lib/vanagon/component_spec.rb
161
168
  - spec/lib/vanagon/engine/base_spec.rb
@@ -196,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
203
  version: '0'
197
204
  requirements: []
198
205
  rubyforge_project:
199
- rubygems_version: 2.4.6
206
+ rubygems_version: 2.5.1
200
207
  signing_key:
201
208
  specification_version: 3
202
209
  summary: All of your packages will fit into this van with this one simple trick.
@@ -208,6 +215,7 @@ test_files:
208
215
  - spec/lib/vanagon/component/rules_spec.rb
209
216
  - spec/lib/vanagon/component/source/git_spec.rb
210
217
  - spec/lib/vanagon/component/source/http_spec.rb
218
+ - spec/lib/vanagon/component/source/localsource_spec.rb
211
219
  - spec/lib/vanagon/component/source_spec.rb
212
220
  - spec/lib/vanagon/component_spec.rb
213
221
  - spec/lib/vanagon/engine/base_spec.rb