devinstall 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65c942b9af93dd07a39c2029c07bde331ac05ea5
4
+ data.tar.gz: 5225f01ff5e97008bb5ae05a45f44563d9541ba8
5
+ SHA512:
6
+ metadata.gz: b5f54243bf6f26420dae3a3f60c0266aaa9ceca9b551822fbbe1ecc4eb80203bcace3ba406efedc605889d48d84a3d440bc9ef6883a98215b0e5d7c5b59008d3
7
+ data.tar.gz: 561bb68c5072a1b11b110ed18632560c0f1dca94702f8e3697ae255f2c9bc8d6a75d08dc07ef8ccaf65b717db07c695ff6ef3594b2426f62fd275e3db6067f05
data/.idea/devinstall.iml CHANGED
@@ -15,9 +15,9 @@
15
15
  </content>
16
16
  <orderEntry type="inheritedJdk" />
17
17
  <orderEntry type="sourceFolder" forTests="false" />
18
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.0.pre.8, ruby-1.9.3-p392) [gem]" level="application" />
19
- <orderEntry type="library" scope="PROVIDED" name="getopt (v1.4.1, ruby-1.9.3-p392) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="rake (v10.0.3, ruby-1.9.3-p392) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.4, RVM: ruby-2.0.0-p0) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="getopt (v1.4.1, RVM: ruby-2.0.0-p0) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.0.3, RVM: ruby-2.0.0-p0) [gem]" level="application" />
21
21
  </component>
22
22
  </module>
23
23
 
data/.idea/misc.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
- <component name="ProjectRootManager" version="2" project-jdk-name="ruby-1.9.3-p392" project-jdk-type="RUBY_SDK" />
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.0.0-p0" project-jdk-type="RUBY_SDK" />
4
4
  </project>
5
5
 
data/bin/pkg-tool CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'getopt/long'
4
4
  require 'devinstall'
5
5
  require 'devinstall/settings'
6
+ require 'pp'
6
7
 
7
8
  begin
8
9
  opt =Getopt::Long.getopts(
@@ -36,20 +37,30 @@ if opt['help']
36
37
  help!
37
38
  exit!(0)
38
39
  end
39
-
40
+ unless opt['config']
41
+ puts 'You must specify a config file'
42
+ exit! 1
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]
48
+ end
49
+ end
50
+ puts "Working on #{opt['package']} for environment #{opt['env']}"
40
51
  unless opt['package'] && opt['config'] && opt['type'] && opt['env'] && (opt['build'] || opt['upload'] || opt['install'])
41
52
  puts 'You must speciffy --config file, --package, --type and --env and one of the actions (--build, --install, --upload)'
42
53
  exit!(0)
43
54
  end
44
- Settings.load!(opt['config'])
45
- package=Pkg.new(opt['package'])
55
+
56
+ package=Devinstall::Pkg.new(opt['package'])
46
57
 
47
58
  if opt['build']
48
- package.build!(opt['type'].to_sym)
59
+ package.build(opt['type'].to_sym)
49
60
  elsif opt['install']
50
- package.build!(opt['type'].to_sym)
51
- package.install!(opt['env'].to_sym)
61
+ package.build(opt['type'].to_sym)
62
+ package.install(opt['env'].to_sym)
52
63
  elsif opt['upload']
53
- package.build!(opt['type'].to_sym)
54
- package.upload!(opt['env'].to_sym)
64
+ package.build(opt['type'].to_sym)
65
+ package.upload(opt['env'].to_sym)
55
66
  end
@@ -11,11 +11,8 @@
11
11
  # 1) class Hash; include DeepSymbolizable; end
12
12
  # 2) myhash.extend DeepSymbolizable
13
13
 
14
- module DeepSymbolizable
15
14
 
16
- class Hash
17
- include DeepSymbolizable
18
- end
15
+ module DeepSymbolizable
19
16
 
20
17
  def deep_symbolize(&block)
21
18
  method = self.class.to_s.downcase.to_sym
@@ -1,7 +1,11 @@
1
1
  require 'yaml'
2
- require 'devinstall/deep_symbolize'
2
+
3
+ class Hash
4
+ include DeepSymbolizable
5
+ end
3
6
 
4
7
  module Settings
8
+
5
9
  extend self
6
10
 
7
11
  @_settings = {}
@@ -23,6 +27,10 @@ module Settings
23
27
  target.merge! data, &merger
24
28
  end
25
29
 
30
+ def defaults
31
+ @_settings[:defaults]
32
+ end
33
+
26
34
  def base
27
35
  @_settings[:base]
28
36
  end
@@ -1,3 +1,3 @@
1
1
  module Devinstall
2
- VERSION = "0.1.0" # first test
2
+ VERSION = "0.2.0" # first test
3
3
  end
data/lib/devinstall.rb CHANGED
@@ -1,22 +1,27 @@
1
1
  require 'devinstall/version'
2
+ require 'devinstall/deep_symbolize'
2
3
  require 'devinstall/settings' ## in near future we will have to abandon Settings
3
4
  # for something more complex because we will need to
4
5
  # define things (repos/install-hosts) for different
5
6
  # environments (dev/qa/prelive/live/prod/backup and so)
7
+ require 'pp'
6
8
 
7
9
  module Devinstall
10
+
11
+
8
12
  class Pkg
9
13
 
10
14
  # @param [Symbol] type
11
15
  def get_version(type)
12
16
  if type == :deb
13
- deb_changelog = "#{Settings.local[:folder]}/debian/changelog" # This is the folder that should be checked
14
- deb_package_version =File.open(deb_changelog, 'r').gets.chomp.sub(/^.*\((.*)\).*$/, "\1")
17
+ deb_changelog = File.expand_path "#{Settings.local[:folder]}/#{@package}/debian/changelog" # This is the folder that should be checked
18
+ deb_package_version =File.open(deb_changelog, 'r').gets.chomp.sub(/^.*\((.*)\).*$/, '\1')
15
19
  @_package_version[:deb]=deb_package_version
16
20
  end
17
21
  end
18
22
 
19
- def new (package)
23
+ # @param [String] package
24
+ def initialize (package)
20
25
  # curently implemented only for .deb packages (for .rpm later :D)
21
26
  @package =package.to_sym
22
27
  @_package_version =Hash.new # versions for types:
@@ -26,29 +31,34 @@ module Devinstall
26
31
  @package_files[:deb] ={deb: "#{pname}_#{arch}.deb",
27
32
  tgz: "#{pname}.tar.gz",
28
33
  dsc: "#{pname}.dsc",
29
- chg: "#{pname}_debian.changes"}
34
+ chg: "#{pname}_amd64.changes"}
30
35
  end
31
36
 
32
- def upload (environment)
37
+ def upload (env)
38
+ unless Settings.repos[:environments][env]
39
+ puts "Undefined environment '#{env}'"
40
+ exit! 1
41
+ end
33
42
  scp =Settings.base[:scp]
34
43
  repo =Hash.new
35
- type =Settings.repos[environment][:type]
44
+ type =Settings.repos[:environments][env][:type].to_sym
36
45
  [:user, :host, :folder].each do |k|
37
- fail("Unexistent key repos:#{environment}:#{k}") unless Settings.repos[environment].has_key?(k)
38
- repo[k]=Settings.repos[environment][k]
46
+ fail("Unexistent key repos:#{env}:#{k}") unless Settings.repos[:environments][env].has_key?(k)
47
+ repo[k]=Settings.repos[:environments][env][k]
39
48
  end
40
- build(type)
41
- @package_files[type].each do |p|
49
+ @package_files[type].each do |t,p|
50
+ puts "Uploading target #{t}(#{p}) to #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}"
42
51
  system("#{scp} #{Settings.local[:temp]}/#{p} #{repo[:user]}@#{repo[:host]}:#{repo[:folder]}")
43
52
  end
44
53
  end
45
54
 
46
55
  # @param [Symbol] type
47
56
  def build (type)
57
+ puts "Building package #{@package} type #{type.to_s}"
48
58
  unless Settings.packages[@package].has_key?(type)
49
- puts("Package '#{@package}' cannot be built for the required environment")
59
+ puts("Package '#{@package}' cannot be built for the required env")
50
60
  puts("undefined build configuration for '#{type.to_s}'")
51
- exit!(1)
61
+ exit! 1
52
62
  end
53
63
  build =Hash.new
54
64
  [:user, :host, :folder, :target].each do |k|
@@ -62,38 +72,44 @@ module Devinstall
62
72
  ssh =Settings.base[:ssh]
63
73
  build_command=Settings.packages[@package][type][:build_command]
64
74
  rsync =Settings.base[:rsync]
65
- local_folder =Settings.local[:folder]
66
- local_temp =Settings.local[:temp]
67
- build_command.sub('%f', Settings.build[:folder]).
68
- sub('%t', Settings.build[:target]).
69
- sub('%p', @package.to_s).
70
- sub('%T', type.to_s)
75
+ local_folder =File.expand_path Settings.local[:folder]
76
+ local_temp =File.expand_path Settings.local[:temp]
77
+
78
+ build_command = build_command.gsub('%f', build[:folder]).
79
+ gsub('%t', Settings.build[:target]).
80
+ gsub('%p', @package.to_s).
81
+ gsub('%T', type.to_s)
71
82
 
72
83
  system("#{rsync} -az #{local_folder}/ #{build[:user]}@#{build[:host]}:#{build[:folder]}")
73
- system("#{ssh} #{build[:user]}@#{build[:host]} -c \"#{build_command}\"")
74
- @package_files[type].each do |p|
75
- system("#{rsync} -az #{build[:user]}@#{build[:host]}/#{build[:target]}/#{p} #{local_temp}")
84
+ 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]}"
87
+ system("#{rsync} -az #{build[:user]}@#{build[:host]}:#{build[:target]}/#{t} #{local_temp}")
76
88
  end
77
89
  end
78
90
 
79
- def install (environment)
91
+ def install (env)
92
+ unless Settings.repos[:environments][env]
93
+ puts "Undefined environment '#{env}'"
94
+ exit! 1
95
+ end
96
+ puts "Installing #{@package} in #{env} environment."
80
97
  sudo =Settings.base[:sudo]
81
98
  scp =Settings.base[:scp]
82
- type =Settings.install[:environment][:type]
99
+ type=Settings.install[:environments][env][:type].to_sym
83
100
  local_temp =Settings.local[:temp]
84
- build(type)
85
101
  install=Hash.new
86
102
  [:user, :host, :folder].each do |k|
87
- unless Settings.install[:environment].has_key?(k)
88
- puts "Undefined key 'install:#{environment.to_s}:#{k.to_s}'"
103
+ unless Settings.install[:environments][env].has_key? k
104
+ puts "Undefined key 'install:environments:#{env.to_s}:#{k.to_s}'"
89
105
  exit!(1)
90
106
  end
91
- install[k]=Settings.install[environment][k]
107
+ install[k]=Settings.install[:environments][env][k]
92
108
  end
93
- case type.to_sym
109
+ case type
94
110
  when :deb
95
111
  system("#{scp} #{local_temp}/#{@package_files[type][:deb]} #{install[:user]}@#{install[:host]}/#{install[:folder]}")
96
- system("#{sudo} #{Settings.build[:user]}@#{Settings.build[:host]} \"dpkg -i #{install[:folder]}/#{@package_files[type][:deb]}")
112
+ system("#{sudo} #{Settings.build[:user]}@#{Settings.build[:host]} \"dpkg -i #{install[:folder]}/#{@package_files[type][:deb]}\"")
97
113
  else
98
114
  puts "unknown package type '#{type.to_s}'"
99
115
  exit!(1)
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devinstall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dragos Boca
@@ -14,49 +13,43 @@ dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: getopt
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: remote builder and installer
@@ -93,27 +86,26 @@ files:
93
86
  homepage: http://github.com/dboca/devinstall
94
87
  licenses:
95
88
  - MIT
89
+ metadata: {}
96
90
  post_install_message:
97
91
  rdoc_options: []
98
92
  require_paths:
99
93
  - lib
100
94
  required_ruby_version: !ruby/object:Gem::Requirement
101
- none: false
102
95
  requirements:
103
- - - ! '>='
96
+ - - '>='
104
97
  - !ruby/object:Gem::Version
105
98
  version: '0'
106
99
  required_rubygems_version: !ruby/object:Gem::Requirement
107
- none: false
108
100
  requirements:
109
- - - ! '>='
101
+ - - '>='
110
102
  - !ruby/object:Gem::Version
111
103
  version: '0'
112
104
  requirements: []
113
105
  rubyforge_project:
114
- rubygems_version: 1.8.25
106
+ rubygems_version: 2.0.3
115
107
  signing_key:
116
- specification_version: 3
108
+ specification_version: 4
117
109
  summary: Copy the source files to a build host, build the packages and install builded
118
110
  packages
119
111
  test_files: []