devinstall 0.2.6 → 1.0.0

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: 814187f402502bc1f4530dbe4c2a8b9ec8c24190
4
- data.tar.gz: 9818041552ee6e73fbda4ed3e778e458472996e4
3
+ metadata.gz: a72a20aa430bcf037ca21512a32d6e143087f0f8
4
+ data.tar.gz: 5db3417f1ebd025f01da2c84dd9766050b29f9f2
5
5
  SHA512:
6
- metadata.gz: ad7dded5934b11adfb7715bb3c0cc0d97e4c758a509ff4f8b54d43b034641a356e796ea88219264882f3a8e59dd32ae9111234a7a6aa182e9aa29e81254399a3
7
- data.tar.gz: 3468b12ee4269d3dd87ac3de83123b0d20b0403376e4a59a96dccdb098261e65d090521605c7b2713d2b8242f2667ac4cb47fa97c58a37016bab750daf35bf05
6
+ metadata.gz: 705c0e2eac77b70d570246ea152a64be626a58a8f9762fb2367af6f49ca4bf55b9b23c6fb3c0f5837be82ddb1f8d26b2bc26bc2d7c9534a4427ea9d4dbdedf94
7
+ data.tar.gz: 7ff04e301b68ce8ca10615f98d647a150d8977bd95c61a15db0c28a9fa5bc2f3eed0b5ca2face0b84eaca1d090099887ebde781615d7dab25cb6fd7ae14b73fd
data/README.md CHANGED
@@ -24,29 +24,56 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- Example command:
27
+ When you install the gem, the installer automaticaly install a program named pkg-tool.
28
+ All the actions can be done via this tool.
28
29
 
29
- $ devinstall –config ./config.yml --environment dev --package ui-lbgenerate --action install
30
+ The general command line syntax is:
30
31
 
31
- This will build and install the package on dev environment
32
+ $ pkg_tool <action> [<package>] [--env <environment>] [--type <type>] [--config <config_file>]
32
33
 
33
- or
34
+ Where:
35
+
36
+ ### Action can be one of the:
37
+
38
+ build
39
+
40
+ Builds the package on the `build/env/host` and copy the package file(s) back in the `base/temp` folder
41
+
42
+ install
43
+
44
+ Build (using `build` command) and install the builded package on the `install/env/host`
45
+
46
+ tests
47
+
48
+ Run the tests described in `test` section of the configuration file
34
49
 
35
- $ devinstall --config ./config.yml --environment dev-rh --package ui-lbgenerate --action upload
50
+ upload
36
51
 
37
- This will build and upload package to repository for dev-rh environment as defined in config.yml
52
+ Build the package, run the tests and upload thr file to the repo
38
53
 
39
- The command line parameters are:
54
+ ### The switches
40
55
 
41
- --config: the config file (defaults to ./config.yml)
56
+ The command line switches are:
42
57
 
43
- --environment: the environment for the install or upload action
58
+ --config: the config file (defaults to ./devinstall.yml)
44
59
 
45
- -- package: the package to be built and installed/uploaded
60
+ --env: the environment for the install or upload action
61
+
62
+ --type: only for –action build and specifies the package type (deb, rpm, tar.gz, arc....)
63
+
64
+ The switches override the defaults in the config file
65
+
66
+ ## Example command:
67
+
68
+ $ pkg-tool install devinstall –config ./config.yml --env dev
69
+
70
+ This will build and install the package "devinstall" on dev environment
71
+
72
+ or
46
73
 
47
- --type: only for –action build and specifies the package type (deb, rpm, tar.gz, arc....)
74
+ $ pkg-tool upload devinstall --config ./config.yml --env dev-rh
48
75
 
49
- --action: can be build (require also --type), install (require --environment) or upload (also require --environment)
76
+ This will build and upload package "devinstall" to repository for dev-rh environment as defined in config.yml
50
77
 
51
78
  ## Contributing
52
79
 
data/bin/pkg-tool CHANGED
@@ -1,11 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
-
2
+ require 'rubygems'
3
+ require 'bundler/setup'
3
4
  require 'devinstall/cli'
4
5
 
6
+ unless ARGV[0]
7
+ puts "You must specify an action"
8
+ exit! ""
9
+ end
10
+
11
+ package = [] # creata a new Array
5
12
  command = ARGV.shift
6
- package = ''
7
13
 
8
- unless %w"build install upload help version test".include? command
14
+ while ARGV[0] and ARGV[0][0..1] != '--'
15
+ package << ARGV.shift
16
+ end
17
+
18
+ if %w"version --version -v".include? command
19
+ command = 'version'
20
+ end
21
+
22
+ if %w"help --help -h".include? command
23
+ command = 'help'
24
+ end
25
+
26
+ unless %w"build install upload test help version".include? command
9
27
  puts "Unknown command #{command}"
10
28
  exit! 1
11
29
  end
@@ -13,10 +31,6 @@ end
13
31
  ## the next should be the package
14
32
  # so if ARGV[0] don't start with --
15
33
  # we name it package
16
- if ARGV[0][0..1] != '--'
17
- package = ARGV.shift
18
- end
19
-
20
- cli=Devinstall::Cli.new(package)
34
+ cli=Devinstall::Cli.new(*package) ## Cli can be called for multiple packages
21
35
  cli.send(command.to_sym)
22
36
 
data/doc/example.yml CHANGED
@@ -2,12 +2,23 @@ base:
2
2
  rsync: /usr/bin/rsync
3
3
  ssh: /usr/bin/ssh
4
4
  scp: /usr/bin/scp
5
- sudo: /usr/bin/sshsudo
5
+ sudo: sshsudo
6
+ defaults:
7
+ package: devinstall
8
+ env: dev
9
+ type: deb
10
+ tests:
11
+ # dev is the environment
12
+ dev:
13
+ machine: dboca.dev.local
14
+ folder: rs
15
+ user: dboca
16
+ command: "cd %f && make devtest"
6
17
  local:
7
18
  # folder - source folder
8
19
  # temp - temporary folder
9
- folder: ~/work/project
10
- temp: ~/tmp
20
+ folder: ~/projects/devinstall
21
+ temp: ~/.tmp
11
22
  build:
12
23
  # host - build machine
13
24
  # folder - rsync to?
@@ -15,7 +26,7 @@ build:
15
26
  # user - for ssh / rsync
16
27
  # arch is the architecture for the generated package (like amd64 or i686)
17
28
  user: dboca
18
- host: vm.development.lan
29
+ host: vm-dboca.dev.local
19
30
  folder: rs
20
31
  target: rs
21
32
  arch: all
@@ -23,33 +34,25 @@ install:
23
34
  # host - dev/prod deploy and install host
24
35
  # user - for scp / ssh / rsync (defaults to base[user])
25
36
  # environment - live/qa/dev/...
26
- user: dboca
27
- environments:
28
- dev:
29
- host: dev01.server.lan
30
- type: deb
31
- folder: ~ ## folder for scp
32
- user: dboca1
33
- arch: all
34
- prod:
35
- host: prod01.server.lan
36
- type: rpm
37
- arch: all
38
- # user defaults to install[:user]
37
+ dev:
38
+ user: dboca
39
+ host:
40
+ - server1.lan
41
+ - server2.lan
42
+ folder: /home/dboca ## folder for scp/dpkg -i
43
+ type: deb
44
+ arch: all
39
45
  repos:
40
46
  # for repository deployment
41
47
  # in a repository should be all packages for all architectures so we don't have an 'arch:' field
42
- environments:
43
- dev:
44
- type: deb
45
- user: upload
46
- host: debian-repo01.server.lan
47
- folder: /srv/repo
48
- dev-rh:
49
- type: rpm
48
+ dev:
49
+ user: dboca
50
+ host: dboca.repo.lan
51
+ folder: /srv/repo/incoming
52
+ type: deb
50
53
  packages:
51
- ui-lbgenerate:
52
- # might contain all the sections above (local, build, install, repodeploy)
54
+ devinstall:
55
+ # might contain all the sections above (local, build, install, repos)
53
56
  # type and build_command are mandatory
54
57
  # in build_command the folowing expansions are made:
55
58
  # %f build[folder]
@@ -57,7 +60,6 @@ packages:
57
60
  # %p package (current package)
58
61
  # %T type (deb, rpm, tar.gz ,...)
59
62
  deb:
60
- build_command: "cd %f && dpkg-buildpackage"
61
- ui-lbcli:
62
- deb:
63
- build_command: "cd %f && dpkg-buildpackage"
63
+ build:
64
+ command: "cd %f/%p && dpkg-buildpackage"
65
+
@@ -3,9 +3,8 @@ require 'getopt/long'
3
3
  require 'devinstall/settings'
4
4
  module Devinstall
5
5
  class Cli
6
- # extend self
7
- # make this module a singleton also
8
- # See why
6
+
7
+ include Utils
9
8
 
10
9
  def get_config(fnames)
11
10
  fnames.each do |f|
@@ -14,78 +13,95 @@ module Devinstall
14
13
  @opt['config']
15
14
  end
16
15
 
17
- def initialize(package)
16
+ def initialize(*package)
18
17
  begin
19
18
  @opt = Getopt::Long.getopts(
20
- ['--package', '-p', Getopt::REQUIRED],
21
19
  ['--config', '-c', Getopt::REQUIRED],
22
20
  ['--type', '-t', Getopt::REQUIRED],
23
- ['--env','-e', Getopt::REQUIRED],
24
- ['--verbose', '-v'],
25
- ['--dry-run', '-d'],
21
+ ['--env', '-e', Getopt::REQUIRED],
22
+ ['--verbose', '-v'],
23
+ ['--dry-run', '-d'],
26
24
  )
27
25
  rescue
28
- puts 'Invalid option in command line'
26
+ puts 'Invalid option at command line'
29
27
  help
30
- exit! 1
31
28
  end
32
29
  #verbose and dry-run
33
30
  $verbose ||= @opt['verbose']
34
- $dry ||= @opt['dry-run']
31
+ $dry ||= @opt['dry-run']
35
32
  # get config file
36
- unless get_config(["./devinstall.yml"])
37
- puts 'You must specify the config file'
38
- exit! 1 # Exit
39
- end
40
- # parse config file
41
- Settings.load!(@opt['config'])
42
- # complete from default values
43
- %w"package env type".each { |o| @opt[o] ||= Settings.defaults[o.to_sym] if Settings.defaults[o.to_sym] }
44
- # verify all informations
45
- if package != '' # a packege was supplied on commandline
46
- @opt['package'] = package # this overrides all
33
+ get_config(["./devinstall.yml", "~/.devinstall.yml"])
34
+ # add packages
35
+ @opt['package']=[] # reset the package array because commandline have priority
36
+ if package # a package was supplied on command line
37
+ package.each { |p| @opt['package'] << p } # now this overrides everything
47
38
  end
48
- %w"package type env".each do |k|
49
- unless @opt[k]
50
- puts "You must specify option '#{k}' either as default or in command line"
51
- help
52
- end
39
+ #get default packages
40
+ if @opt['package'].empty?
41
+ config = Devinstall::Settings.new(@opt['config'], nil, @opt['env'], @opt['type']) # Just for pkg :D
42
+ @opt['package'] = config.pkg # we DO have accessor
53
43
  end
54
- # create package
55
- @package=Devinstall::Pkg.new(@opt['package'])
56
- end
57
-
58
- def version
59
- puts "devinstall version #{Devinstall::VERSION}"
60
- puts "pkg-tool version #{Devinstall::VERSION}"
61
- exit! 0
62
- end
63
-
64
- def help
65
- puts 'Usage:'
66
- puts 'pkg-install command --config|-c <file> --package|-p <package> --type|-t <package_type> --env|-e <environment>'
67
- puts 'where command is one of the: build, install, upload, help, version'
68
- exit! 0
69
44
  end
70
45
 
71
46
  def build
72
- @package.build(@opt['type'].to_sym)
47
+ if @opt['config'].empty?
48
+ exit! 'You must specify the config file'
49
+ end
50
+ # create package
51
+ @opt['package'].each do |package|
52
+ pk=Devinstall::Pkg.new(Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type']))
53
+ pk.build
54
+ end
73
55
  end
74
56
 
75
57
  def install
76
- @package.build(@opt['type'].to_sym)
77
- @package.install(@opt['env'].to_sym)
58
+ if @opt['config'].empty?
59
+ exit! 'You must specify the config file'
60
+ end
61
+ @opt['package'].each do |package|
62
+ pk=Devinstall::Pkg.new(Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type']))
63
+ pk.build
64
+ pk.install
65
+ end
78
66
  end
79
67
 
80
68
  def upload
81
- @package.build(@opt['type'].to_sym)
82
- @package.run_tests(@opt['env'].to_sym)
83
- @package.upload(@opt['env'].to_sym)
69
+ if @opt['config'].empty?
70
+ exit! 'You must specify the config file'
71
+ end
72
+ @opt['package'].each do |package|
73
+ config=Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type'])
74
+ pk=Devinstall::Pkg.new(config)
75
+ pk.build
76
+ pk.run_tests
77
+ pk.upload
78
+ end
84
79
  end
85
80
 
86
81
  def test
87
- @package.run_tests(@opt['env'].to_sym)
82
+ if @opt['config'].empty?
83
+ exit! 'You must specify the config file'
84
+ end
85
+ @opt['package'].each do |package|
86
+ config=Devinstall::Settings.new(@opt['config'], package, @opt['env'], @opt['type'])
87
+ pk=Devinstall::Pkg.new(config)
88
+ pk.run_tests
89
+ end
90
+ end
91
+
92
+ def help
93
+ puts 'Usage:'
94
+ puts 'pkg-tool command [package_name ... ] --config|-c <file> --type|-t <package_type> --env|-e <environment>'
95
+ puts 'where command is one of the: build, install, upload, help, version'
96
+ exit! ""
97
+ end
98
+
99
+ def version
100
+ puts "devinstall version #{Devinstall::VERSION}"
101
+ puts "pkg-tool version #{Devinstall::VERSION}"
102
+ exit! ""
88
103
  end
89
104
 
90
105
  end
91
106
  end
107
+
@@ -4,62 +4,127 @@ class Hash
4
4
  include DeepSymbolizable
5
5
  end
6
6
 
7
+ module Devinstall
8
+
9
+ class KeyNotDefinedError < RuntimeError; end
10
+
11
+ class UnknownKeyError < RuntimeError; end
12
+
13
+ class Settings
14
+ include Utils
15
+ attr_accessor :pkg, :env, :type
16
+
17
+ def initialize (filename, pkg = nil, env = nil, type = nil)
18
+ @@_files ||= []
19
+ @@_settings ||= {}
20
+ load! filename
21
+ self.pkg = pkg ? pkg : defaults(:package)
22
+ self.env = env ? env.to_sym : defaults(:env).to_sym
23
+ self.type = type ? type.to_sym : defaults(:type).to_sym
24
+ if Array === self.pkg
25
+ self.pkg.each do |p|
26
+ raise KeyNotDefinedError, "Package '#{p}' not defined" unless @@_settings[:packages].has_key? p.to_sym
27
+ raise KeyNotDefinedError, "Package #{p} type '#{type}' not defined " unless @@_settings[:packages][p.to_sym].has_key? self.type
28
+ end
29
+ else
30
+ raise KeyNotDefinedError, "Package '#{p}' not defined" unless @@_settings[:packages].has_key? self.pkg.to_sym
31
+ raise KeyNotDefinedError, "Package #{p} type '#{type}' not defined " unless @@_settings[:packages][self.pkg.to_sym].has_key? self.type
32
+ end
33
+ raise KeyNotDefinedError, "Missing package" unless self.pkg
34
+ raise KeyNotDefinedError, "Missing environment" unless self.env
35
+ raise KeyNotDefinedError, "Missing package type" unless self.type
36
+ rescue KeyNotDefinedError => e
37
+ puts "#{e.message}"
38
+ exit! "" #here should be raise
39
+ rescue UnknownKeyError => e
40
+ puts "Program error: #{e.message} at:"
41
+ puts e.backtrace
42
+ exit!
43
+ end
7
44
 
8
- module Settings
9
-
10
- extend self
11
-
12
- @_settings = {}
13
- attr_reader :_settings
45
+ def load!(filename) # Multiple load -> merge settings
46
+ unless File.exist?(filename)
47
+ puts "Unable to find config file \"#{filename}\""
48
+ exit!
49
+ end
50
+ unless @@_files.include? filename
51
+ @@_files << filename
52
+ newsets = YAML::load_file(filename).deep_symbolize
53
+ deep_merge!(@@_settings, newsets)
54
+ end
55
+ end
14
56
 
15
- def load!(filename, options = {})
16
- unless File.exist?(filename)
17
- puts "Unable to find config file \"#{filename}\""
18
- exit!(1)
57
+ def deep_merge!(target, data)
58
+ merger = proc do |_, v1, v2|
59
+ Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
60
+ end
61
+ target.merge! data, &merger
19
62
  end
20
- newsets = YAML::load_file(filename).deep_symbolize
21
- newsets = newsets[options[:env].to_sym] if options[:env] && newsets[options[:env].to_sym]
22
- deep_merge!(@_settings, newsets)
23
- end
24
63
 
25
- def deep_merge!(target, data)
26
- merger = proc do |_, v1, v2|
27
- Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
64
+ def defaults(key=nil)
65
+ return @@_settings.has_key? :defaults if key.nil?
66
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:package, :type, :env].include? key
67
+ @@_settings[:defaults][key] or raise KeyNotDefinedError, "Undefined key :default:#{key.to_s}"
28
68
  end
29
- target.merge! data, &merger
30
- end
31
69
 
32
- def defaults
33
- @_settings[:defaults]
34
- end
70
+ def base(key=nil)
71
+ return @@_settings.has_key? :base if key.nil?
72
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:rsync, :ssh, :sudo, :scp].include? key
73
+ @@_settings[:base][key] or raise KeyNotDefinedError, "Undefined key :base:#{key.to_s}"
74
+ end
35
75
 
36
- def tests
37
- @_settings[:tests]
38
- end
76
+ def local(key)
77
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:folder, :temp].include? key
78
+ ret=@@_settings[:local][key]
79
+ if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :local
80
+ ret = @@_settings[:packages][self.pgk.to_sym][self.type][:local][key] || ret
81
+ end
82
+ ret or raise KeyNotDefinedError, "Undefined key :local:#{key} or :#{self.pkg}:local:#{key}"
83
+ end
39
84
 
40
- def base
41
- @_settings[:base]
42
- end
85
+ def build(key)
86
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:user, :host, :folder, :target, :arch, :command].include? key
87
+ ret=@@_settings[:build][key]
88
+ if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :build
89
+ ret = @@_settings[:packages][self.pkg.to_sym][self.type][:build][key] || ret
90
+ end
91
+ ret or raise KeyNotDefinedError, "Undefined key :build:#{key} or :#{self.pkg}:#{self.type}:build:#{key}"
92
+ end
43
93
 
44
- def local
45
- @_settings[:local]
46
- end
94
+ def install(key)
95
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:user, :host, :folder, :type, :arch].include? key
96
+ ret=@@_settings[:install][self.env][key]
97
+ if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :install and @@_settings[:packages][:install].has_key? self.env
98
+ ret = @@_settings[:packages][self.pgk.to_sym][self.type][:install][self.env][key] || ret
99
+ end
100
+ ret or raise KeyNotDefinedError, "Undefined key :install:#{self.env.to_s}:#{key} or :#{self.pkg}:install:#{self.env.to_s}:#{key}"
101
+ end
47
102
 
48
- def build
49
- @_settings[:build]
50
- end
103
+ def tests(key=nil) # tests don't have 'env'
104
+ return @@_settings.has_key?(:tests) if key.nil?
105
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:machine, :folder, :user, :command].include? key
106
+ ret=@@_settings[:tests][key]
107
+ if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :tests
108
+ ret = @@_settings[:packages][self.pkg.to_sym][self.type][:tests][key] || ret
109
+ end
110
+ ret or raise KeyNotDefinedError, "Undefined key :tests:#{self.env.to_s}:#{key} or :#{self.pkg}:tests:#{self.env.to_s}:#{key}"
111
+ end
51
112
 
52
- def install
53
- @_settings[:install]
54
- end
113
+ def repos(key)
114
+ raise UnknownKeyError, "Don't know what are you asking about: '#{key}'" unless [:user, :host, :folder, :type, :arch].include? key
115
+ ret=@@_settings[:repos][self.env][key]
116
+ if @@_settings[:packages][self.pkg.to_sym][self.type].has_key? :repos and @@_settings[:packages][:repos].has_key? self.env
117
+ ret = @@_settings[:packages][self.pkg.to_sym][self.type][:repos][self.env][key] || ret
118
+ end
119
+ ret or raise KeyNotDefinedError, "Undefined key :repos:environments:#{self.env.to_s}:#{key} or :#{self.pkg}:repos:#{self.env.to_s}:#{key}"
120
+ end
55
121
 
56
- def repos
57
- @_settings[:repos]
58
- end
122
+ %w(repos packages).each do |m|
123
+ define_method(m) do
124
+ @@_settings[m.to_sym]
125
+ end
126
+ end
59
127
 
60
- def packages
61
- @_settings[:packages]
62
128
  end
63
-
64
129
  end
65
130
 
@@ -8,16 +8,22 @@ module Utils
8
8
  if $?.exitstatus != 0 ## return failure
9
9
  puts "While executing:"
10
10
  puts cmd
11
- puts "The command failed with exitstatus $?.exitstatus"
11
+ puts "The command failed with exitstatus #{$?.exitstatus}"
12
12
  puts "Full output of command follows"
13
13
  puts "="*40
14
14
  puts ret
15
+ puts "="*40
15
16
  puts "Nothing to do. Aborting!"
16
- exit! 1
17
+ exit! "Done"
17
18
  end
18
19
  end
19
20
  ret
20
21
  end
21
22
 
23
+ def exit! msg
24
+ puts msg || "Aborting!"
25
+ Kernel.exit 1
26
+ end
27
+
22
28
 
23
29
  end #module
@@ -1,3 +1,3 @@
1
1
  module Devinstall
2
- VERSION = '0.2.6' # Small bugfixes
2
+ VERSION = '1.0.0' # Working!
3
3
  end
data/lib/devinstall.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  require 'devinstall/version'
2
2
  require 'devinstall/deep_symbolize'
3
3
  require 'devinstall/utils'
4
- require 'devinstall/settings' ## in near future we will have to abandon Settings
5
- # for something more complex because we will need to
6
- # define things (repos/install-hosts) for different
7
- # environments (dev/qa/prelive/live/prod/backup and so)
4
+ require 'devinstall/settings'
8
5
  require 'pp'
9
6
 
10
7
  module Devinstall
@@ -13,85 +10,71 @@ module Devinstall
13
10
 
14
11
  include Utils
15
12
 
16
- # @param [Symbol] type
17
- def get_version(type)
18
- if type == :deb
19
- begin
20
- deb_changelog = File.expand_path "#{Settings.local[:folder]}/#{@package}/debian/changelog" # This is the folder that should be checked
21
- deb_package_version = File.open(deb_changelog, 'r') { |f| f.gets.chomp.sub(/^.*\((.*)\).*$/, '\1') }
22
- @_package_version[:deb] = deb_package_version
23
-
24
- rescue IOError => e
25
- puts "IO Error while opening #{deb_changelog}"
26
- puts "Aborting \n #{e}"
27
- exit! 1
28
- end
13
+ def get_version
14
+ case @config.type
15
+ when :deb
16
+ begin
17
+ deb_changelog = File.expand_path "#{@config.local(:folder)}/#{@package}/debian/changelog" # This is the folder that should be checked
18
+ unless File.exists? deb_changelog
19
+ exit! <<-eos
20
+ No 'debian/changelog' found in specified :local:folder (#{@config.local(:folder)})
21
+ Please check your config file
22
+ eos
23
+ end
24
+ @_package_version[:deb] = File.open(deb_changelog, 'r') { |f| f.gets.chomp.sub(/^.*\((.*)\).*$/, '\1') }
25
+ rescue IOError => e
26
+ exit! <<-eos
27
+ IO Error while opening #{deb_changelog}
28
+ Aborting \n #{e}
29
+ eos
30
+ end
29
31
  end
30
32
  end
31
33
 
32
34
  # @param [String] package
33
- def initialize (package)
34
- # curently implemented only for .deb packages (for .rpm later :D)
35
- unless Settings.packages.has_key? package.to_sym
36
- puts "You required an undefined package #{package}"
37
- puts "Aborting!"
38
- exit! 1
39
- end
40
- @package = package.to_sym
41
- @_package_version = Hash.new # versions for types:
42
- @package_files = Hash.new
43
- arch = Settings.build[:arch]
44
- pname = "#{package}_#{get_version :deb}"
45
- @package_files[:deb] = {deb: "#{pname}_#{arch}.deb",
46
- tgz: "#{pname}.tar.gz",
47
- dsc: "#{pname}.dsc",
48
- chg: "#{pname}_amd64.changes"}
35
+ # @param [String] config
36
+ def initialize (config)
37
+ @config=config #class variable,first thing!
38
+ # currently implemented only for .deb packages (for .rpm later :D)
39
+ @package = @config.pkg.to_sym
40
+ @_package_version = {} # versions for types:
41
+ @package_files = {}
42
+ arch = @config.build(:arch)
43
+ p_name = "#{@package}_#{get_version}"
44
+ @package_files[:deb] = {deb: "#{p_name}_#{arch}.deb",
45
+ tgz: "#{p_name}.tar.gz",
46
+ dsc: "#{p_name}.dsc",
47
+ chg: "#{p_name}_amd64.changes"}
49
48
  end
50
49
 
51
- def upload (env)
52
- scp = Settings.base[:scp]
50
+ def upload
51
+ scp = @config.base(:scp)
53
52
  repo = {}
54
- type = Settings.repos[:environments][env][:type].to_sym
55
- [:user, :host, :folder].each do |k|
56
- unless Settings.repos[:environments][env].has_key?(k)
57
- puts "Unexistent key #{k} in repos:environments:#{env}"
58
- puts "Aborting"
59
- exit! 1
60
- end
61
- repo[k] = Settings.repos[:environments][env][k]
53
+ [:user, :host, :folder, :type].each do |k|
54
+ repo[k] = @config.repos(k) # looks stupid
62
55
  end
63
- @package_files[type].each do |p,f|
56
+ @package_files[type].each do |p, f|
64
57
  puts "Uploading #{f}\t\t[#{p}] to $#{repo[:host]}"
65
- command("#{scp} #{Settings.local[:temp]}/#{f} #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}")
58
+ command("#{scp} #{@config.local(:temp)}/#{f} #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}")
66
59
  end
67
60
  end
68
61
 
69
- # @param [Symbol] type
70
- def build (type)
71
- puts "Building package #{@package} type #{type.to_s}"
72
- unless Settings.packages[@package].has_key? type
73
- puts "Package '#{@package}' cannot be built for the required environment"
74
- puts "undefined build configuration for '#{type.to_s}'"
75
- exit! 1
76
- end
62
+ def build
63
+ type = @config.type
64
+ puts "Building package #{@package} type #{type}"
77
65
  build = {}
78
66
  [:user, :host, :folder, :target].each do |k|
79
- unless Settings.build.has_key? k
80
- puts "Undefined key 'build:#{k.to_s}:'"
81
- puts "Aborting!"
82
- exit! 1
83
- end
84
- build[k] = Settings.build[k]
67
+ build[k] = @config.build(k)
85
68
  end
86
69
 
87
- ssh = Settings.base[:ssh]
88
- build_command = Settings.packages[@package][type][:build_command]
89
- rsync = Settings.base[:rsync]
90
- local_folder = File.expand_path Settings.local[:folder]
91
- local_temp = File.expand_path Settings.local[:temp]
70
+ ssh = @config.base(:ssh)
71
+ build_command = @config.build(:command)
72
+ rsync = @config.base(:rsync)
73
+ local_folder = File.expand_path @config.local(:folder)
74
+ local_temp = File.expand_path @config.local(:temp)
92
75
 
93
76
  build_command = build_command.gsub('%f', build[:folder]).
94
- gsub('%t', Settings.build[:target]).
77
+ gsub('%t', @config.build(:target)).
95
78
  gsub('%p', @package.to_s).
96
79
  gsub('%T', type.to_s)
97
80
 
@@ -103,69 +86,61 @@ module Devinstall
103
86
  end
104
87
  end
105
88
 
106
- def run_tests(env)
107
- # for tests we will use aprox the same setup as for build
108
- test = {}
109
- [:user, :machine, :command, :folder].each do |k|
110
- unless Settings.tests[env].has_key? k
111
- puts("Undefined key 'tests:#{env}:#{k.to_s}:'")
112
- exit! 1
113
- end
114
- test[k] = Settings.tests[env][k]
115
- end
116
- ssh = Settings.base[:ssh]
117
-
118
- test[:command] = test[:command].gsub('%f', test[:folder]).
119
- gsub('%t', Settings.build[:target]).
120
- gsub('%p', @package.to_s)
121
-
122
- local_folder = File.expand_path Settings.local[:folder] #take the sources from the local folder
123
-
124
- upload_sources("#{local_folder}/", "#{test[:user]}@#{test[:machine]}:#{test[:folder]}") # upload them to the test machine
125
-
126
- puts "Running all tests for the #{env} environment"
127
- puts "This will take some time and you have no output"
128
- command("#{ssh} #{test[:user]}@#{test[:machine]} \"#{test[:command]}\"")
129
- rescue => ee
130
- puts "Unknown exception during parsing config file"
131
- puts "Aborting (#{ee})"
132
- exit! 1
133
- end
134
-
135
- def install (environment)
136
- puts "Installing #{@package} in #{environment} environment."
137
- local_temp = Settings.local[:temp]
138
- sudo = Settings.base[:sudo]
139
- scp = Settings.base[:scp]
140
- type = Settings.install[:environments][environment][:type].to_sym
89
+ def install
90
+ env = @config.env
91
+ puts "Installing #{@package} in #{env} environment."
92
+ local_temp = @config.local(:temp)
93
+ sudo = @config.base(:sudo)
94
+ scp = @config.base(:scp)
95
+ type = @config.type
141
96
  install = {}
142
97
  [:user, :host, :folder].each do |k|
143
- unless Settings.install[:environments][environment].has_key? k
144
- puts "Undefined key 'install:#{environment.to_s}:#{k.to_s}'"
145
- exit! 1
146
- end
147
- install[k] = Settings.install[:environments][environment][k]
98
+ install[k] = @config.install(k)
148
99
  end
149
-
150
100
  install[:host] = [install[:host]] unless Array === install[:host]
151
-
152
101
  case type
153
- when :deb
154
- install[:host].each do |host|
155
- command("#{scp} #{local_temp}/#{@package_files[type][:deb]} #{install[:user]}@#{host}:#{install[:folder]}")
156
- command("#{sudo} #{install[:user]}@#{host} /usr/bin/dpkg -i #{install[:folder]}/#{@package_files[type][:deb]}")
157
- end
158
- else
159
- puts "unknown package type '#{type.to_s}'"
160
- exit! 1
102
+ when :deb
103
+ install[:host].each do |host|
104
+ command("#{scp} #{local_temp}/#{@package_files[type][:deb]} #{install[:user]}@#{host}:#{install[:folder]}")
105
+ command("#{sudo} #{install[:user]}@#{host} /usr/bin/dpkg -i #{install[:folder]}/#{@package_files[type][:deb]}")
106
+ end
107
+ else
108
+ exit! "unknown package type '#{type.to_s}'"
109
+ end
110
+ end
111
+
112
+ def run_tests
113
+ # check if we have the test section in the configuration file
114
+ unless @config.tests
115
+ puts "No test section in the config file."
116
+ puts "Skipping tests"
117
+ return;
161
118
  end
119
+ # for tests we will use almost the same setup as for build
120
+ test = {}
121
+ [:user, :machine, :command, :folder].each do |k|
122
+ test[k] = @config.(k)
123
+ end
124
+ ssh = @config.base(:ssh)
125
+ # replace "variables" in commands
126
+ test[:command] = test[:command].
127
+ gsub('%f', test[:folder]). # %f is the folder where the sources are rsync-ed
128
+ gsub('%t', @config.build(:target)). # %t is the folder where the build places the result
129
+ gsub('%p', @package.to_s) # %p is the package name
130
+ # take the sources from the local folder
131
+ local_folder = File.expand_path @config.local(:folder)
132
+ # upload them to the test machine
133
+ upload_sources("#{local_folder}/", "#{test[:user]}@#{test[:machine]}:#{test[:folder]}")
134
+ puts "Running all tests"
135
+ puts 'This will take some time and you have no output'
136
+ command("#{ssh} #{test[:user]}@#{test[:machine]} \"#{test[:command]}\"")
162
137
  end
163
138
 
164
139
  def upload_sources (source, dest)
165
- rsync = Settings.base[:rsync]
140
+ rsync = @config.base(:rsync)
166
141
  command("#{rsync} -az #{source} #{dest}")
167
142
  end
168
143
  end
169
- end
170
144
 
145
+ end
171
146
 
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.6
4
+ version: 1.0.0
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-18 00:00:00.000000000 Z
11
+ date: 2013-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler