devinstall 0.2.0 → 0.2.1

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: 65c942b9af93dd07a39c2029c07bde331ac05ea5
4
- data.tar.gz: 5225f01ff5e97008bb5ae05a45f44563d9541ba8
3
+ metadata.gz: c2f2c6937b701ffa7244cbbcad05ec74cf378383
4
+ data.tar.gz: febe47467ab63606b4bf1c9d43fe1b0fb331da3b
5
5
  SHA512:
6
- metadata.gz: b5f54243bf6f26420dae3a3f60c0266aaa9ceca9b551822fbbe1ecc4eb80203bcace3ba406efedc605889d48d84a3d440bc9ef6883a98215b0e5d7c5b59008d3
7
- data.tar.gz: 561bb68c5072a1b11b110ed18632560c0f1dca94702f8e3697ae255f2c9bc8d6a75d08dc07ef8ccaf65b717db07c695ff6ef3594b2426f62fd275e3db6067f05
6
+ metadata.gz: 24d0732f67276785ae6785c9df8ac46f275b711932ad355b59c5064e108d13dcc244ae0cf08a6935349d8250f2e0eaebe78f4e6afe953b2ba69dd03899315f5a
7
+ data.tar.gz: 9a0cbe36d5203618ce5046a207db353e5bb2e5b5b0575d2e2766da629ac32a02b84a89af1ae8982ebb8b9911c3423a27130e81a0f0cb27bff78fe673c3bde539
data/bin/pkg-tool CHANGED
@@ -3,7 +3,6 @@
3
3
  require 'getopt/long'
4
4
  require 'devinstall'
5
5
  require 'devinstall/settings'
6
- require 'pp'
7
6
 
8
7
  begin
9
8
  opt =Getopt::Long.getopts(
@@ -15,12 +14,13 @@ begin
15
14
  ['--build', '-b',],
16
15
  ['--upload', '-u',],
17
16
  ['--install', '-i',],
17
+ ['--test', '-t,'],
18
18
  ['--help', '-h',],
19
19
  )
20
20
  rescue
21
21
  puts 'Invalid option in command line'
22
22
  help!
23
- exit!(1)
23
+ exit! 1
24
24
  end
25
25
 
26
26
  def help!
@@ -38,21 +38,21 @@ if opt['help']
38
38
  exit!(0)
39
39
  end
40
40
  unless opt['config']
41
- puts 'You must specify a config file'
42
- exit! 1
41
+ puts 'You must specify the config file'
42
+ exit! 1 # Exit
43
43
  end
44
- Settings.load!(opt['config'])
45
- [:package, :type, :env].each do |a|
46
- if Settings.defaults[a] and not opt[a.to_s]
47
- opt[a.to_s]=Settings.defaults[a]
44
+ Settings.load! opt['config']
45
+
46
+ ['package', 'env', 'type'].each do |o|
47
+ if Settings.defaults[o.to_sym]
48
+ opt[o]=Settings.defaults[o.to_sym]
48
49
  end
49
50
  end
50
- puts "Working on #{opt['package']} for environment #{opt['env']}"
51
- unless opt['package'] && opt['config'] && opt['type'] && opt['env'] && (opt['build'] || opt['upload'] || opt['install'])
52
- puts 'You must speciffy --config file, --package, --type and --env and one of the actions (--build, --install, --upload)'
53
- exit!(0)
54
- end
55
51
 
52
+ unless opt['package'] && opt['config'] && opt['type'] && opt['env'] && (opt['build'] || opt['upload'] || opt['install'] || opt['test'])
53
+ puts 'You must speciffy --config file, --package, --type and --env and one of the actions (--build, --install, --upload or --test)'
54
+ exit! 1
55
+ end
56
56
  package=Devinstall::Pkg.new(opt['package'])
57
57
 
58
58
  if opt['build']
@@ -62,5 +62,8 @@ elsif opt['install']
62
62
  package.install(opt['env'].to_sym)
63
63
  elsif opt['upload']
64
64
  package.build(opt['type'].to_sym)
65
+ package.run_tests(opt['env'].to_sym)
65
66
  package.upload(opt['env'].to_sym)
67
+ elsif opt['test']
68
+ package.run_tests(opt['env'].to_sym)
66
69
  end
@@ -4,6 +4,7 @@ class Hash
4
4
  include DeepSymbolizable
5
5
  end
6
6
 
7
+
7
8
  module Settings
8
9
 
9
10
  extend self
@@ -31,6 +32,10 @@ module Settings
31
32
  @_settings[:defaults]
32
33
  end
33
34
 
35
+ def tests
36
+ @_settings[:tests]
37
+ end
38
+
34
39
  def base
35
40
  @_settings[:base]
36
41
  end
@@ -1,3 +1,3 @@
1
1
  module Devinstall
2
- VERSION = "0.2.0" # first test
2
+ VERSION = "0.2.1" # first test
3
3
  end
data/lib/devinstall.rb CHANGED
@@ -8,7 +8,6 @@ require 'pp'
8
8
 
9
9
  module Devinstall
10
10
 
11
-
12
11
  class Pkg
13
12
 
14
13
  # @param [Symbol] type
@@ -34,20 +33,16 @@ module Devinstall
34
33
  chg: "#{pname}_amd64.changes"}
35
34
  end
36
35
 
37
- def upload (env)
38
- unless Settings.repos[:environments][env]
39
- puts "Undefined environment '#{env}'"
40
- exit! 1
41
- end
36
+ def upload (environment)
42
37
  scp =Settings.base[:scp]
43
38
  repo =Hash.new
44
- type =Settings.repos[:environments][env][:type].to_sym
39
+ type =Settings.repos[:environments][environment][:type]
45
40
  [:user, :host, :folder].each do |k|
46
- fail("Unexistent key repos:#{env}:#{k}") unless Settings.repos[:environments][env].has_key?(k)
47
- repo[k]=Settings.repos[:environments][env][k]
41
+ fail("Unexistent key repos:#{environment}:#{k}") unless Settings.repos[:environments][environment].has_key?(k)
42
+ repo[k]=Settings.repos[:environments][environment][k]
48
43
  end
49
- @package_files[type].each do |t,p|
50
- puts "Uploading target #{t}(#{p}) to #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}"
44
+ build(type)
45
+ @package_files[type].each do |p|
51
46
  system("#{scp} #{Settings.local[:temp]}/#{p} #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}")
52
47
  end
53
48
  end
@@ -56,9 +51,9 @@ module Devinstall
56
51
  def build (type)
57
52
  puts "Building package #{@package} type #{type.to_s}"
58
53
  unless Settings.packages[@package].has_key?(type)
59
- puts("Package '#{@package}' cannot be built for the required env")
54
+ puts("Package '#{@package}' cannot be built for the required environment")
60
55
  puts("undefined build configuration for '#{type.to_s}'")
61
- exit! 1
56
+ exit!(1)
62
57
  end
63
58
  build =Hash.new
64
59
  [:user, :host, :folder, :target].each do |k|
@@ -80,41 +75,75 @@ module Devinstall
80
75
  gsub('%p', @package.to_s).
81
76
  gsub('%T', type.to_s)
82
77
 
83
- system("#{rsync} -az #{local_folder}/ #{build[:user]}@#{build[:host]}:#{build[:folder]}")
78
+ upload_sources("#{local_folder}/", "#{build[:user]}@#{build[:host]}:#{build[:folder]}")
84
79
  system("#{ssh} #{build[:user]}@#{build[:host]} \"#{build_command}\"")
85
- @package_files[type].each do |p,t|
86
- puts "Receiving target #{p.to_s}(#{t.to_s}) from #{build[:user]}@#{build[:host]}:#{build[:target]}"
80
+ @package_files[type].each do |p, t|
81
+ puts "Receiving target #{p.to_s} for #{t.to_s}"
87
82
  system("#{rsync} -az #{build[:user]}@#{build[:host]}:#{build[:target]}/#{t} #{local_temp}")
88
83
  end
89
84
  end
90
85
 
91
- def install (env)
92
- unless Settings.repos[:environments][env]
93
- puts "Undefined environment '#{env}'"
86
+ def run_tests(environment)
87
+ # for tests we will use aprox the same setup as for build
88
+ test =Hash.new
89
+ [:user, :machine, :command, :folder].each do |k|
90
+ unless Settings.tests[environment].has_key?(k)
91
+ puts("Undefined key 'tests:#{environment}:#{k.to_s}:'")
92
+ exit!(1)
93
+ end
94
+ test[k]=Settings.tests[environment][k]
95
+ end
96
+ ssh =Settings.base[:ssh]
97
+
98
+ test[:command] = test[:command].gsub('%f', test[:folder]).
99
+ gsub('%t', Settings.build[:target]).
100
+ gsub('%p', @package.to_s)
101
+
102
+ local_folder =File.expand_path Settings.local[:folder] #take the sources from the local folder
103
+
104
+ upload_sources("#{local_folder}/", "#{test[:user]}@#{test[:machine]}:#{test[:folder]}") # upload them to the test machine
105
+
106
+ puts "Running all tests for the #{environment} environment"
107
+ puts "This will take some time"
108
+ ret=system("#{ssh} #{test[:user]}@#{test[:machine]} \"#{test[:command]}\"")
109
+ if ret
110
+ puts "Errors during test. Aborting current procedure"
94
111
  exit! 1
95
112
  end
96
- puts "Installing #{@package} in #{env} environment."
113
+ rescue Exception => ee
114
+ puts "Unknown exception during parsing config file"
115
+ puts "Aborting (#{ee})"
116
+ exit! 1
117
+ end
118
+
119
+ def install (environment)
120
+ puts "Installing #{@package} in #{environment} environment."
97
121
  sudo =Settings.base[:sudo]
98
122
  scp =Settings.base[:scp]
99
- type=Settings.install[:environments][env][:type].to_sym
123
+ type=Settings.install[:environments][environment][:type].to_sym
100
124
  local_temp =Settings.local[:temp]
101
125
  install=Hash.new
102
126
  [:user, :host, :folder].each do |k|
103
- unless Settings.install[:environments][env].has_key? k
104
- puts "Undefined key 'install:environments:#{env.to_s}:#{k.to_s}'"
105
- exit!(1)
127
+ unless Settings.install[:environments][environment].has_key?(k)
128
+ puts "Undefined key 'install:#{environment.to_s}:#{k.to_s}'"
129
+ exit! 1
106
130
  end
107
- install[k]=Settings.install[:environments][env][k]
131
+ install[k]=Settings.install[:environments][environment][k]
108
132
  end
109
133
  case type
110
134
  when :deb
111
- system("#{scp} #{local_temp}/#{@package_files[type][:deb]} #{install[:user]}@#{install[:host]}/#{install[:folder]}")
135
+ system("#{scp} #{local_temp}/#{@package_files[type][:deb]} #{install[:user]}@#{install[:host]}:#{install[:folder]}")
112
136
  system("#{sudo} #{Settings.build[:user]}@#{Settings.build[:host]} \"dpkg -i #{install[:folder]}/#{@package_files[type][:deb]}\"")
113
137
  else
114
138
  puts "unknown package type '#{type.to_s}'"
115
- exit!(1)
139
+ exit! 1
116
140
  end
117
141
  end
142
+
143
+ def upload_sources (source, dest)
144
+ rsync =Settings.base[:rsync]
145
+ system("#{rsync} -az #{source} #{dest}")
146
+ end
118
147
  end
119
148
  end
120
149
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devinstall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dragos Boca
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-16 00:00:00.000000000 Z
11
+ date: 2013-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler