dpkg-tools 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/CHANGES +198 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +17 -0
  4. data/Rakefile +1 -0
  5. data/bin/dpkg-etc +6 -0
  6. data/bin/dpkg-gem +6 -0
  7. data/bin/dpkg-rails +6 -0
  8. data/lib/dpkg-tools.rb +6 -0
  9. data/lib/dpkg-tools/command_line.rb +142 -0
  10. data/lib/dpkg-tools/package.rb +30 -0
  11. data/lib/dpkg-tools/package/builder.rb +112 -0
  12. data/lib/dpkg-tools/package/config.rb +96 -0
  13. data/lib/dpkg-tools/package/control_files.rb +24 -0
  14. data/lib/dpkg-tools/package/control_files/base.rb +75 -0
  15. data/lib/dpkg-tools/package/control_files/changelog.rb +23 -0
  16. data/lib/dpkg-tools/package/control_files/control.rb +148 -0
  17. data/lib/dpkg-tools/package/control_files/copyright.rb +27 -0
  18. data/lib/dpkg-tools/package/control_files/rakefile.rb +28 -0
  19. data/lib/dpkg-tools/package/control_files/rules.rb +29 -0
  20. data/lib/dpkg-tools/package/data.rb +125 -0
  21. data/lib/dpkg-tools/package/etc.rb +26 -0
  22. data/lib/dpkg-tools/package/etc/builder.rb +19 -0
  23. data/lib/dpkg-tools/package/etc/control_files.rb +22 -0
  24. data/lib/dpkg-tools/package/etc/control_files/changelog.rb +30 -0
  25. data/lib/dpkg-tools/package/etc/control_files/rakefile.rb +18 -0
  26. data/lib/dpkg-tools/package/etc/data.rb +48 -0
  27. data/lib/dpkg-tools/package/etc/rake.rb +31 -0
  28. data/lib/dpkg-tools/package/etc/setup.rb +30 -0
  29. data/lib/dpkg-tools/package/fs_methods.rb +10 -0
  30. data/lib/dpkg-tools/package/gem.rb +43 -0
  31. data/lib/dpkg-tools/package/gem/builder.rb +77 -0
  32. data/lib/dpkg-tools/package/gem/control_files.rb +23 -0
  33. data/lib/dpkg-tools/package/gem/control_files/changelog.rb +19 -0
  34. data/lib/dpkg-tools/package/gem/control_files/copyright.rb +24 -0
  35. data/lib/dpkg-tools/package/gem/control_files/rakefile.rb +19 -0
  36. data/lib/dpkg-tools/package/gem/data.rb +115 -0
  37. data/lib/dpkg-tools/package/gem/gem_format.rb +10 -0
  38. data/lib/dpkg-tools/package/gem/rake.rb +37 -0
  39. data/lib/dpkg-tools/package/gem/setup.rb +159 -0
  40. data/lib/dpkg-tools/package/rails.rb +26 -0
  41. data/lib/dpkg-tools/package/rails/builder.rb +77 -0
  42. data/lib/dpkg-tools/package/rails/cap.rb +30 -0
  43. data/lib/dpkg-tools/package/rails/control_files.rb +22 -0
  44. data/lib/dpkg-tools/package/rails/control_files/changelog.rb +19 -0
  45. data/lib/dpkg-tools/package/rails/control_files/rakefile.rb +24 -0
  46. data/lib/dpkg-tools/package/rails/data.rb +160 -0
  47. data/lib/dpkg-tools/package/rails/rake.rb +40 -0
  48. data/lib/dpkg-tools/package/rails/setup.rb +84 -0
  49. data/lib/dpkg-tools/package/rake.rb +90 -0
  50. data/lib/dpkg-tools/package/setup.rb +145 -0
  51. data/lib/dpkg-tools/version.rb +23 -0
  52. data/spec/dpkg-tools/command_line_spec.rb +9 -0
  53. data/spec/dpkg-tools/package/builder_spec.rb +159 -0
  54. data/spec/dpkg-tools/package/config_spec.rb +150 -0
  55. data/spec/dpkg-tools/package/control_files/base_spec.rb +111 -0
  56. data/spec/dpkg-tools/package/control_files/changelog_spec.rb +22 -0
  57. data/spec/dpkg-tools/package/control_files/control_spec.rb +131 -0
  58. data/spec/dpkg-tools/package/control_files/copyright_spec.rb +29 -0
  59. data/spec/dpkg-tools/package/control_files/rakefile_spec.rb +37 -0
  60. data/spec/dpkg-tools/package/control_files/rules_spec.rb +16 -0
  61. data/spec/dpkg-tools/package/control_files_spec.rb +12 -0
  62. data/spec/dpkg-tools/package/data_spec.rb +115 -0
  63. data/spec/dpkg-tools/package/etc/builder_spec.rb +28 -0
  64. data/spec/dpkg-tools/package/etc/control_files/changelog_spec.rb +21 -0
  65. data/spec/dpkg-tools/package/etc/control_files/rakefile_spec.rb +16 -0
  66. data/spec/dpkg-tools/package/etc/control_files_spec.rb +12 -0
  67. data/spec/dpkg-tools/package/etc/data_spec.rb +74 -0
  68. data/spec/dpkg-tools/package/etc/rake_spec.rb +71 -0
  69. data/spec/dpkg-tools/package/etc/setup_spec.rb +62 -0
  70. data/spec/dpkg-tools/package/etc_spec.rb +39 -0
  71. data/spec/dpkg-tools/package/fs_methods_spec.rb +33 -0
  72. data/spec/dpkg-tools/package/gem/builder_spec.rb +84 -0
  73. data/spec/dpkg-tools/package/gem/control_files/changelog_spec.rb +25 -0
  74. data/spec/dpkg-tools/package/gem/control_files/copyright_spec.rb +28 -0
  75. data/spec/dpkg-tools/package/gem/control_files/rakefile_spec.rb +17 -0
  76. data/spec/dpkg-tools/package/gem/control_files_spec.rb +12 -0
  77. data/spec/dpkg-tools/package/gem/data_spec.rb +176 -0
  78. data/spec/dpkg-tools/package/gem/gem_format_spec.rb +26 -0
  79. data/spec/dpkg-tools/package/gem/rake_spec.rb +102 -0
  80. data/spec/dpkg-tools/package/gem/setup_spec.rb +274 -0
  81. data/spec/dpkg-tools/package/gem_spec.rb +68 -0
  82. data/spec/dpkg-tools/package/rails/builder_spec.rb +113 -0
  83. data/spec/dpkg-tools/package/rails/cap_spec.rb +37 -0
  84. data/spec/dpkg-tools/package/rails/control_files/changelog_spec.rb +25 -0
  85. data/spec/dpkg-tools/package/rails/control_files/rakefile_spec.rb +24 -0
  86. data/spec/dpkg-tools/package/rails/control_files_spec.rb +12 -0
  87. data/spec/dpkg-tools/package/rails/data_spec.rb +178 -0
  88. data/spec/dpkg-tools/package/rails/rake_spec.rb +78 -0
  89. data/spec/dpkg-tools/package/rails/setup_spec.rb +152 -0
  90. data/spec/dpkg-tools/package/rails_spec.rb +27 -0
  91. data/spec/dpkg-tools/package/rake_spec.rb +87 -0
  92. data/spec/dpkg-tools/package/setup_spec.rb +247 -0
  93. data/spec/dpkg-tools/package_spec.rb +34 -0
  94. data/spec/fixtures/BlueCloth-1.0.0.gem +1190 -0
  95. data/spec/fixtures/database.yml +33 -0
  96. data/spec/spec.opts +1 -0
  97. data/spec/spec_helper.rb +52 -0
  98. data/tasks/dist.rake +118 -0
  99. data/tasks/rspec.rake +21 -0
  100. metadata +165 -0
@@ -0,0 +1,26 @@
1
+ require 'dpkg-tools/package/rails/data'
2
+ require 'dpkg-tools/package/rails/setup'
3
+ require 'dpkg-tools/package/rails/builder'
4
+ require 'dpkg-tools/package/rails/control_files'
5
+ require 'dpkg-tools/package/rails/rake'
6
+ require 'dpkg-tools/package/rails/cap'
7
+
8
+ module DpkgTools
9
+ module Package
10
+ module Rails
11
+ class << self
12
+ def create_builder(path_to_app)
13
+ Builder.from_path(path_to_app)
14
+ end
15
+
16
+ def create_setup(path_to_app)
17
+ Setup.from_path(path_to_app)
18
+ end
19
+
20
+ def setup_from_path(path_to_app)
21
+ create_setup(path_to_app).create_structure
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,77 @@
1
+ require 'rake'
2
+ require 'rubygems'
3
+
4
+ require 'fileutils'
5
+
6
+ module DpkgTools
7
+ module Package
8
+ module Rails
9
+ class Builder < DpkgTools::Package::Builder
10
+ class << self
11
+ def from_path(path_to_app)
12
+ data = Data.new(path_to_app)
13
+ self.new(data)
14
+ end
15
+ end
16
+
17
+ def config_options
18
+ {:base_path => data.base_path}
19
+ end
20
+
21
+ def create_install_dirs
22
+ create_dir_if_needed(File.join(config.etc_install_path, 'apache2/sites-available'))
23
+ create_dir_if_needed(File.join(config.etc_install_path, 'logrotate.d'))
24
+ create_dir_if_needed(File.join(config.etc_install_path, 'init.d'))
25
+ create_dir_if_needed(File.join(config.buildroot, "var/lib/#{data.name}"))
26
+ create_dir_if_needed(File.join(config.buildroot, "var/log/#{data.name}/apache2"))
27
+ end
28
+
29
+ def generate_conf_file(template_path, target_path)
30
+ File.open(target_path, 'w') do |f|
31
+ f.write(render_template(File.read(template_path)))
32
+ end
33
+ end
34
+
35
+ def generate_conf_files
36
+ generate_conf_file(File.join(config.base_path, 'config/apache.conf.erb'),
37
+ File.join(config.etc_install_path, "apache2/sites-available/#{data.name}"))
38
+ generate_conf_file(File.join(config.base_path, 'config/logrotate.conf.erb'),
39
+ File.join(config.etc_install_path, "logrotate.d/#{data.name}"))
40
+ generate_conf_file(File.join(config.base_path, 'config/mongrel_cluster_init.erb'),
41
+ File.join(config.buildroot, data.init_script_path))
42
+ end
43
+
44
+ def read_deployers_ssh_keys
45
+ keys = []
46
+ Dir.entries(data.deployers_ssh_keys_dir).each do |name|
47
+ path = File.join(data.deployers_ssh_keys_dir, name)
48
+ keys << File.read(path) if File.file?(path)
49
+ end
50
+ keys
51
+ end
52
+
53
+ def write_authorized_keys(ssh_keys)
54
+ authorized_keys_path = File.join(config.buildroot, data.app_install_path, '.ssh/authorized_keys')
55
+ File.open(authorized_keys_path, 'w') { |f| f.write(ssh_keys.join("\n")) }
56
+ sh "chmod 600 \"#{File.join(config.buildroot, data.authorized_keys_path)}\""
57
+ end
58
+
59
+ def generate_authorized_keys
60
+ create_dir_if_needed(File.join(config.buildroot, data.dot_ssh_path))
61
+ sh "chmod 700 \"#{File.join(config.buildroot, data.dot_ssh_path)}\""
62
+
63
+ write_authorized_keys(read_deployers_ssh_keys)
64
+ end
65
+
66
+ def install_package_files
67
+ generate_conf_files
68
+
69
+ generate_authorized_keys
70
+
71
+ sh "chmod 755 \"#{File.join(config.buildroot, data.init_script_path)}\""
72
+ sh "chown -R root:root \"#{config.buildroot}\""
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,30 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Rails
4
+ class << self
5
+ def cap
6
+ DpkgTools::Package::Rails::Data.new(DpkgTools::Package::Rails::Cap.located_app_root)
7
+ end
8
+ end
9
+
10
+ module Cap
11
+ class << self
12
+ def dir_contains_config?(path)
13
+ Dir.entries(path).include?('config')
14
+ end
15
+
16
+ def located_app_root
17
+ path = Dir.pwd
18
+ while path != '/'
19
+ return path if dir_contains_config?(path)
20
+ path = File.dirname(path)
21
+ end
22
+ raise CannotLocateAppDir
23
+ end
24
+ end
25
+ end
26
+
27
+ class CannotLocateAppDir < StandardError; end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ require 'dpkg-tools/package/rails/control_files/changelog'
2
+ require 'dpkg-tools/package/rails/control_files/rakefile'
3
+
4
+ module DpkgTools
5
+ module Package
6
+ module Rails
7
+ module ControlFiles
8
+ class << self
9
+ def classes
10
+ [
11
+ DpkgTools::Package::Rails::ControlFiles::Changelog,
12
+ DpkgTools::Package::ControlFiles::Control,
13
+ DpkgTools::Package::ControlFiles::Copyright,
14
+ DpkgTools::Package::Rails::ControlFiles::Rakefile,
15
+ DpkgTools::Package::ControlFiles::Rules
16
+ ]
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Rails
4
+ module ControlFiles
5
+ class Changelog < DpkgTools::Package::ControlFiles::Changelog
6
+ def change_time
7
+ Time.now.rfc822
8
+ end
9
+
10
+ def changelog
11
+ "#{config.package_name} (#{config.deb_version(data.debian_revision)}) cp-gutsy; urgency=low\n"\
12
+ " * Packaged up #{data.full_name}\n"\
13
+ " -- Matt Patterson <matt@reprocessed.org> #{self.change_time}\n"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Rails
4
+ module ControlFiles
5
+ class Rakefile < DpkgTools::Package::ControlFiles::Rakefile
6
+ def rakefile
7
+ "require 'rubygems'\n" \
8
+ "begin\n" \
9
+ " require 'dpkg-tools'\n" \
10
+ "rescue LoadError\n" \
11
+ " # dpkg-tools not available (because we don't really need it on deployment targets)\n" \
12
+ "end\n" \
13
+ "\n" \
14
+ "if defined?(DpkgTools::Package::Rails)\n" \
15
+ " DpkgTools::Package::Rails::BuildTasks.new do |t|\n" \
16
+ " t.base_path = Rake.original_dir\n" \
17
+ " end\n" \
18
+ "end\n"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,160 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Rails
4
+ class DebYAMLParseError < StandardError; end
5
+
6
+ class Data < DpkgTools::Package::Data
7
+ class << self
8
+ include DpkgTools::Package::Data::YamlConfigHelpers
9
+
10
+ def load_package_data(base_path, filename)
11
+ YAML.load_file(File.join(base_path, 'config', filename)) if File.exist?(File.join(base_path, 'config', filename))
12
+ end
13
+
14
+ def base_deps
15
+ [{:name => 'mysql-client'}, {:name => 'mysql-server'}, {:name => 'apache2'},
16
+ {:name => 'ruby', :requirements => ['>= 1.8.2']}]
17
+ end
18
+
19
+ def base_gem_deps
20
+ [{:name => 'rails-rubygem', :requirements => ['>= 1.2.5-1']},
21
+ {:name => 'rake-rubygem', :requirements => ['>= 0.7.3-1']},
22
+ {:name => 'mysql-rubygem', :requirements => ['>= 2.7-1']},
23
+ {:name => 'mongrel-cluster-rubygem', :requirements => ['>= 1.0.1-1']}]
24
+ end
25
+
26
+ def resources_dirname
27
+ 'rails'
28
+ end
29
+ end
30
+
31
+ attr_reader :spec, :config, :base_path, :database_configurations
32
+
33
+ def initialize(base_path)
34
+ @data = self.class.load_package_data(base_path, 'deb.yml')
35
+ @mongrel_cluster_data = @data['mongrel_cluster']
36
+ @database_configurations = self.class.load_package_data(base_path, 'database.yml')
37
+
38
+ @dependencies = self.class.process_dependencies(@data)
39
+ @base_path = base_path
40
+ end
41
+
42
+ def name
43
+ @data['name']
44
+ end
45
+
46
+ def version
47
+ @data['version']
48
+ end
49
+
50
+ def license
51
+ @data['license']
52
+ end
53
+
54
+ def debian_revision
55
+ "1"
56
+ end
57
+
58
+ def debian_arch
59
+ "all"
60
+ end
61
+
62
+ def dependencies
63
+ @dependencies
64
+ end
65
+
66
+ def build_dependencies
67
+ @dependencies
68
+ end
69
+
70
+ def summary
71
+ @data['summary']
72
+ end
73
+
74
+ def full_name
75
+ "#{name}-#{version}"
76
+ end
77
+
78
+ def rakefile_location
79
+ [:base_path, 'lib/tasks/dpkg-tools.rake']
80
+ end
81
+
82
+ def mongrel_cluster_config_hash
83
+ @mongrel_cluster_data
84
+ end
85
+
86
+ def number_of_mongrels
87
+ @mongrel_cluster_data['servers']
88
+ end
89
+
90
+ def mongrel_cluster_start_port
91
+ @mongrel_cluster_data['port']
92
+ end
93
+
94
+ def mongrel_ports
95
+ Array.new(number_of_mongrels) {|i| (mongrel_cluster_start_port.to_i + i).to_s}
96
+ end
97
+
98
+ def init_name
99
+ @data['init_name']
100
+ end
101
+
102
+ def app_install_path
103
+ "/var/lib/#{name}"
104
+ end
105
+
106
+ def pidfile_dir_path
107
+ "/var/run/#{name}"
108
+ end
109
+
110
+ def logfile_path
111
+ "/var/log/#{name}"
112
+ end
113
+
114
+ def conf_dir_path
115
+ "#{app_install_path}/current/config"
116
+ end
117
+
118
+ def init_script_path
119
+ "/etc/init.d/#{name}"
120
+ end
121
+
122
+ def dot_ssh_path
123
+ "#{app_install_path}/.ssh"
124
+ end
125
+
126
+ def authorized_keys_path
127
+ "#{dot_ssh_path}/authorized_keys"
128
+ end
129
+
130
+ def username
131
+ name
132
+ end
133
+
134
+ def user
135
+ name
136
+ end
137
+
138
+ def server_name
139
+ @data['server_name']
140
+ end
141
+
142
+ def server_aliases
143
+ @data['server_aliases']
144
+ end
145
+
146
+ def application
147
+ name
148
+ end
149
+
150
+ def deploy_to
151
+ app_install_path
152
+ end
153
+
154
+ def deployers_ssh_keys_dir
155
+ File.join(base_path, 'config/deployers_ssh_keys')
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,40 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Rails
4
+ class BuildTasks < DpkgTools::Package::BuildTasks
5
+ attr_accessor :base_path
6
+
7
+ def check_setup
8
+ raise ArgumentError, "Needs to have base_path set" unless @base_path
9
+ end
10
+
11
+ def create_builder
12
+ DpkgTools::Package::Rails.create_builder(@base_path)
13
+ end
14
+
15
+ def create_setup
16
+ DpkgTools::Package::Rails.create_setup(@base_path)
17
+ end
18
+
19
+ def define_tasks
20
+ task "binary-arch" do
21
+ create_builder.binary_package
22
+ end
23
+
24
+ task "binary-indep" do
25
+ create_builder.binary_package
26
+ end
27
+
28
+ namespace :dpkg do
29
+ desc <<-EOD
30
+ Regenerate the config/mongre_cluster.yml file.
31
+ EOD
32
+ task :mongrel_cluster do
33
+ create_setup.generate_mongrel_cluster_config
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,84 @@
1
+ require 'erb'
2
+ require 'rake'
3
+
4
+ module DpkgTools
5
+ module Package
6
+ module Rails
7
+ class Setup < DpkgTools::Package::Setup
8
+ class << self
9
+ def bootstrap_file_path(base_path, filename)
10
+ File.join(base_path, 'config', filename)
11
+ end
12
+
13
+ def data_class
14
+ DpkgTools::Package::Rails::Data
15
+ end
16
+
17
+ def generate_mongrel_cluster_config_hash(data, config)
18
+ data.mongrel_cluster_config_hash.merge({'cwd' => "#{data.app_install_path}/current",
19
+ 'pid_file' => "#{data.pidfile_dir_path}/mongrel.pid",
20
+ 'log_file' => 'log/mongrel.log',
21
+ 'user' => data.name,
22
+ 'group' => data.name})
23
+ end
24
+
25
+ def generate_mongrel_cluster_config(data, config)
26
+ message = ["# Auto-generated by dpkg-tools, don't edit!",
27
+ "# You can edit config/deb.yml and then regenerate this file",
28
+ "# with rake dpkg:mongrel_cluster."]
29
+
30
+ yaml = generate_mongrel_cluster_config_hash(data, config).to_yaml.split("\n")
31
+ yaml.shift
32
+
33
+ File.open(config.base_path + '/config/mongrel_cluster.yml', 'w') do |f|
34
+ f.write((message + [""] + yaml).join("\n"))
35
+ end
36
+ end
37
+
38
+ def resource_file_names
39
+ ['apache.conf.erb', 'logrotate.conf.erb', 'mongrel_cluster_init.erb', 'deploy.rb']
40
+ end
41
+
42
+ def prepare_package(data, config)
43
+ resource_file_names.each do |filename|
44
+ bootstrap_file(config.base_path, filename)
45
+ end
46
+
47
+ create_dir_if_needed(data.deployers_ssh_keys_dir)
48
+
49
+ sh "capify \"#{config.base_path}\""
50
+ generate_mongrel_cluster_config(data, config)
51
+ end
52
+
53
+ def reset_package_resource_files(data, config)
54
+ resource_file_names.each do |filename|
55
+ bootstrap_file(config.base_path, filename, :backup => true)
56
+ end
57
+ end
58
+ end
59
+
60
+ attr_reader :data, :config
61
+
62
+ def control_file_classes
63
+ DpkgTools::Package::Rails::ControlFiles.classes
64
+ end
65
+
66
+ def config_options
67
+ {:base_path => @data.base_path}
68
+ end
69
+
70
+ def prepare_package
71
+ self.class.prepare_package(data, config)
72
+ end
73
+
74
+ def generate_mongrel_cluster_config
75
+ self.class.generate_mongrel_cluster_config(data, config)
76
+ end
77
+
78
+ def reset_package_resource_files
79
+ self.class.reset_package_resource_files(data, config)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end