rails-app-installer 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +8 -9
- data/bin/rails-app-installer-setup +71 -0
- data/bin/rails-backup +13 -0
- data/bin/rails-restore +24 -0
- data/{lib → examples}/apache13.conf.example.template +0 -0
- data/{lib → examples}/apache20.conf.example.template +0 -0
- data/examples/installer +2 -3
- data/{lib → examples}/lighttpd.conf.example.template +0 -0
- data/examples/release.rake +39 -0
- data/lib/rails-installer.rb +38 -5
- data/lib/rails-installer/databases.rb +3 -1
- metadata +68 -59
data/README
CHANGED
@@ -5,21 +5,20 @@ This installer was originally part of Typo (http://typosphere.org).
|
|
5
5
|
|
6
6
|
= Adding the installer to your Rails app
|
7
7
|
|
8
|
-
To add the installer to your application,
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
`installer` directory for your app and copy
|
14
|
-
`examples/rails_installer_defaults.yml` into it. You can probably use it
|
15
|
-
unchanged.
|
8
|
+
To add the installer to your application, cd to your application's directory
|
9
|
+
and run 'rails-app-installer-setup APPNAME'. This will create several files,
|
10
|
+
including 'bin/APPNAME' and 'lib/tasks/release.rake'. Edit these files to make
|
11
|
+
sure that they're appropriate for your application and then add them to your
|
12
|
+
revision control system.
|
16
13
|
|
17
14
|
You should now be able to test the installer like this:
|
18
15
|
|
19
16
|
$ ruby ./bin/my_installer install /tmp/foo cwd
|
20
17
|
|
21
18
|
This will try to install your app in `/tmp/foo` using the current directory as
|
22
|
-
a template.
|
19
|
+
a template. If you leave off the `cwd` option at the end, then the installer
|
20
|
+
will look for the most recent Ruby GEM for your app, using the
|
21
|
+
`application_name` line from the installer as the gem name.
|
23
22
|
|
24
23
|
= Creating a Gem
|
25
24
|
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rails-installer'
|
5
|
+
|
6
|
+
def usage
|
7
|
+
STDERR.puts "Usage:"
|
8
|
+
STDERR.puts " rails-app-installer-setup APPNAME"
|
9
|
+
STDERR.puts ""
|
10
|
+
STDERR.puts " APPNAME is the name of your application; it should be"
|
11
|
+
STDERR.puts " both the .gem name and the name of your installer."
|
12
|
+
STDERR.puts ""
|
13
|
+
STDERR.puts " Please run this command form the root of your Rails project."
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
# $ rails-app-installer-setup APPNAME
|
18
|
+
|
19
|
+
appname = ARGV[0]
|
20
|
+
|
21
|
+
unless appname and appname =~ /^[a-z][-_a-z0-9]+$/
|
22
|
+
usage
|
23
|
+
exit(1)
|
24
|
+
end
|
25
|
+
|
26
|
+
installer = RailsInstaller.new('.')
|
27
|
+
|
28
|
+
# Check for Rails in cwd
|
29
|
+
unless installer.is_valid_rails_directory?
|
30
|
+
STDERR.puts "Please run this command from the root of a valid Rails project"
|
31
|
+
exit(1)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Find GEM
|
35
|
+
|
36
|
+
gem_directory = installer.find_source_directory 'rails-app-installer'
|
37
|
+
|
38
|
+
# Copy files from GEM IFF they don't already exist.
|
39
|
+
|
40
|
+
files_to_copy = {
|
41
|
+
'examples/installer' => "bin/#{appname}",
|
42
|
+
'examples/rails_installer_defaults.yml' => 'installer/rails_installer_defaults.yml',
|
43
|
+
'examples/apache13.conf.example.template' => 'installer/apache13.conf.example.template',
|
44
|
+
'examples/apache20.conf.example.template' => 'installer/apache20.conf.example.template',
|
45
|
+
'examples/lighttpd.conf.example.template' => 'installer/lighttpd.conf.example.template',
|
46
|
+
'examples/release.rake' => 'lib/tasks/release.rake'
|
47
|
+
}
|
48
|
+
|
49
|
+
files_to_copy.each do |from, to|
|
50
|
+
next if File.exists? to
|
51
|
+
puts " creating #{to}"
|
52
|
+
FileUtils.mkdir_p File.dirname(to) rescue nil
|
53
|
+
contents = File.read File.join(gem_directory,from)
|
54
|
+
|
55
|
+
File.open(to,'w') do |out|
|
56
|
+
out.write contents.gsub(/\$APPNAME/,appname)
|
57
|
+
end
|
58
|
+
|
59
|
+
if to=~/^bin/
|
60
|
+
File.chmod(0755,to)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
puts "Successfully created an installer for your application."
|
65
|
+
puts
|
66
|
+
puts "Your next steps:"
|
67
|
+
puts " 1. Verify bin/#{appname} and lib/tasks/release.rake to make sure that they're"
|
68
|
+
puts " correct. Remove all 'FIXME's."
|
69
|
+
puts " 2. Create db/schema.*.sql files by installing the schema_generator gem and"
|
70
|
+
puts " running './script/generate schema'"
|
71
|
+
puts " 3. Run 'rake repackage' and verify that the generated .gem is correct."
|
data/bin/rails-backup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rails-installer'
|
5
|
+
|
6
|
+
installer = RailsInstaller.new('.')
|
7
|
+
|
8
|
+
unless installer.is_valid_rails_directory?
|
9
|
+
STDERR.puts "Please run this command from the root of a valid Rails project"
|
10
|
+
exit(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
installer.backup_database
|
data/bin/rails-restore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rails-installer'
|
5
|
+
|
6
|
+
installer = RailsInstaller.new('.')
|
7
|
+
|
8
|
+
unless installer.is_valid_rails_directory?
|
9
|
+
STDERR.puts "Please run this command from the root of a valid Rails project"
|
10
|
+
exit(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
restore_file = ARGV[0]
|
14
|
+
|
15
|
+
unless restore_file and File.exists?(restore_file) and restore_file =~ /\.yml$/
|
16
|
+
puts "Usage:"
|
17
|
+
puts " rails-restore FILENAME"
|
18
|
+
puts ""
|
19
|
+
puts " Restores the database contents from FILENAME into the database defined"
|
20
|
+
puts " in 'config/database.yml'. FILENAME should be generated by the "
|
21
|
+
puts " 'rails-backup' command."
|
22
|
+
end
|
23
|
+
|
24
|
+
installer.restore_database restore_file
|
File without changes
|
File without changes
|
data/examples/installer
CHANGED
@@ -4,9 +4,8 @@ require 'rubygems'
|
|
4
4
|
require 'rails-installer'
|
5
5
|
|
6
6
|
class AppInstaller < RailsInstaller
|
7
|
-
application_name '
|
8
|
-
support_location '
|
9
|
-
rails_version '1.1.6'
|
7
|
+
application_name '$APPNAME'
|
8
|
+
support_location 'the $APPNAME website'
|
10
9
|
end
|
11
10
|
|
12
11
|
directory = ARGV[1]
|
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
|
3
|
+
PKG_VERSION = "1.0.0"
|
4
|
+
PKG_NAME = "$APPNAME"
|
5
|
+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
6
|
+
|
7
|
+
spec = Gem::Specification.new do |s|
|
8
|
+
s.name = PKG_NAME
|
9
|
+
s.version = PKG_VERSION
|
10
|
+
s.summary = "FIXME"
|
11
|
+
s.description = "FIXME"
|
12
|
+
s.has_rdoc = false
|
13
|
+
|
14
|
+
s.files = Dir.glob('**/*', File::FNM_DOTMATCH).reject do |f|
|
15
|
+
[ /\.$/, /config\/database.yml$/, /config\/database.yml-/,
|
16
|
+
/database\.sqlite/,
|
17
|
+
/\.log$/, /^pkg/, /\.svn/, /^vendor\/rails/, /\~$/,
|
18
|
+
/\/\._/, /\/#/ ].any? {|regex| f =~ regex }
|
19
|
+
end
|
20
|
+
s.require_path = '.'
|
21
|
+
s.author = "FIXME"
|
22
|
+
s.email = "FIXME@example.com"
|
23
|
+
s.homepage = "http://www.FIXME.com"
|
24
|
+
s.rubyforge_project = "FIXME"
|
25
|
+
s.platform = Gem::Platform::RUBY
|
26
|
+
s.executables = ['$APPNAME']
|
27
|
+
|
28
|
+
s.add_dependency("rails", "= 1.1.6")
|
29
|
+
s.add_dependency("mongrel", ">= 0.3.13.3")
|
30
|
+
s.add_dependency("mongrel_cluster", ">= 0.2.0")
|
31
|
+
s.add_dependency("sqlite3-ruby", ">= 1.1.0")
|
32
|
+
s.add_dependency("rails-app-installer", ">= 0.1.0")
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::GemPackageTask.new(spec) do |p|
|
36
|
+
p.gem_spec = spec
|
37
|
+
p.need_tar = false
|
38
|
+
p.need_zip = false
|
39
|
+
end
|
data/lib/rails-installer.rb
CHANGED
@@ -367,15 +367,32 @@ class RailsInstaller
|
|
367
367
|
[added, changed, deleted, same]
|
368
368
|
end
|
369
369
|
|
370
|
+
# Decide which Rails version to freeze
|
371
|
+
def rails_version_to_freeze
|
372
|
+
if @@rails_version
|
373
|
+
return "= #{@@rails_version}"
|
374
|
+
else
|
375
|
+
specs = Gem.source_index.find_name(app_name,["= #{@install_version}"])
|
376
|
+
unless specs.to_a.size > 0
|
377
|
+
raise InstallFailed, "Can't locate version #{@install_version.first}!"
|
378
|
+
end
|
379
|
+
|
380
|
+
rails_dep = specs.first.dependencies.detect {|a| a.name=='rails'}
|
381
|
+
version = rails_dep.version_requirements.to_s
|
382
|
+
return version
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
370
386
|
# Freeze to a specific version of Rails gems.
|
371
387
|
def freeze_rails
|
372
|
-
|
388
|
+
new_version = rails_version_to_freeze
|
389
|
+
|
373
390
|
version_file = File.join(install_directory,'vendor','rails-version')
|
374
391
|
vendor_rails = File.join(install_directory,'vendor','rails')
|
375
392
|
|
376
393
|
old_version = File.read(version_file).chomp rescue nil
|
377
394
|
|
378
|
-
if
|
395
|
+
if new_version == old_version
|
379
396
|
return
|
380
397
|
elsif old_version != nil
|
381
398
|
rm_rf(vendor_rails)
|
@@ -392,10 +409,10 @@ class RailsInstaller
|
|
392
409
|
'activesupport' => File.join(vendor_rails,'activesupport'),
|
393
410
|
}
|
394
411
|
|
395
|
-
specs = Gem.source_index.find_name('rails',[
|
412
|
+
specs = Gem.source_index.find_name('rails',[new_version])
|
396
413
|
|
397
414
|
unless specs.to_a.size > 0
|
398
|
-
raise InstallFailed, "Can't locate Rails #{
|
415
|
+
raise InstallFailed, "Can't locate Rails #{new_version}!"
|
399
416
|
end
|
400
417
|
|
401
418
|
copy_gem(specs.first, package_map[specs.first.name])
|
@@ -566,7 +583,7 @@ class RailsInstaller
|
|
566
583
|
end
|
567
584
|
|
568
585
|
# Locate the source directory for a specific Version
|
569
|
-
def find_source_directory(gem_name, version)
|
586
|
+
def find_source_directory(gem_name, version=nil)
|
570
587
|
if version == 'cwd'
|
571
588
|
return Dir.pwd
|
572
589
|
elsif version
|
@@ -580,6 +597,9 @@ class RailsInstaller
|
|
580
597
|
raise InstallFailed, "Can't locate version #{version}!"
|
581
598
|
end
|
582
599
|
|
600
|
+
@install_version = specs.last.version
|
601
|
+
message "Installing #{app_name} #{@install_version}"
|
602
|
+
|
583
603
|
specs.last.full_gem_path
|
584
604
|
end
|
585
605
|
|
@@ -644,6 +664,19 @@ class RailsInstaller
|
|
644
664
|
STDERR.puts " #{help}"
|
645
665
|
end
|
646
666
|
end
|
667
|
+
|
668
|
+
def is_valid_rails_directory?
|
669
|
+
valid = false
|
670
|
+
in_directory install_directory do
|
671
|
+
valid = File.exists?('config/database.yml') and
|
672
|
+
File.directory?('app') and
|
673
|
+
File.directory?('app/models') and
|
674
|
+
File.directory?('vendor')
|
675
|
+
end
|
676
|
+
|
677
|
+
valid
|
678
|
+
end
|
679
|
+
|
647
680
|
end
|
648
681
|
|
649
682
|
# Run a block inside of a specific directory. Chdir into the directory
|
@@ -15,8 +15,10 @@ class RailsInstaller
|
|
15
15
|
database_yml = File.read File.join(installer.install_directory, 'config', 'database.yml') rescue nil
|
16
16
|
database_yml ||= yml(installer)
|
17
17
|
|
18
|
+
environment = ENV['RAILS_ENV'] || 'development' # Mirror Rails' default.
|
19
|
+
|
18
20
|
ActiveRecord::Base.establish_connection(
|
19
|
-
YAML.load(database_yml)[
|
21
|
+
YAML.load(database_yml)[environment])
|
20
22
|
begin
|
21
23
|
tables = ActiveRecord::Base.connection.tables
|
22
24
|
if tables.size > 0
|
metadata
CHANGED
@@ -1,84 +1,93 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: rails-app-installer
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-08-
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2006-08-15 00:00:00 -07:00
|
8
8
|
summary: An installer for Rails apps
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: scott@sigkill.org
|
12
12
|
homepage: http://scottstuff.net
|
13
13
|
rubyforge_project:
|
14
|
-
description:
|
14
|
+
description: ""
|
15
15
|
autorequire: rails-installer
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
18
18
|
has_rdoc: true
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
25
24
|
version:
|
26
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
27
29
|
authors:
|
28
|
-
|
30
|
+
- Scott Laird
|
29
31
|
files:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
- bin/rails-app-installer-setup
|
33
|
+
- bin/rails-backup
|
34
|
+
- bin/rails-restore
|
35
|
+
- lib/rails-installer
|
36
|
+
- lib/rails-installer.rb
|
37
|
+
- examples/apache13.conf.example.template
|
38
|
+
- examples/apache20.conf.example.template
|
39
|
+
- examples/installer
|
40
|
+
- examples/lighttpd.conf.example.template
|
41
|
+
- examples/rails_installer_defaults.yml
|
42
|
+
- examples/release.rake
|
43
|
+
- examples/typo
|
44
|
+
- README
|
45
|
+
- lib/rails-installer/commands.rb
|
46
|
+
- lib/rails-installer/databases.rb
|
47
|
+
- lib/rails-installer/web-servers.rb
|
42
48
|
test_files: []
|
49
|
+
|
43
50
|
rdoc_options:
|
44
|
-
|
45
|
-
|
51
|
+
- --main
|
52
|
+
- RailsInstaller
|
46
53
|
extra_rdoc_files:
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
executables:
|
54
|
+
- README
|
55
|
+
- lib/rails-installer/commands.rb
|
56
|
+
- lib/rails-installer/databases.rb
|
57
|
+
- lib/rails-installer/web-servers.rb
|
58
|
+
executables:
|
59
|
+
- rails-app-installer-setup
|
60
|
+
- rails-backup
|
61
|
+
- rails-restore
|
52
62
|
extensions: []
|
63
|
+
|
53
64
|
requirements: []
|
65
|
+
|
54
66
|
dependencies:
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: 1.1.0
|
84
|
-
version:
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: mongrel
|
69
|
+
version_requirement:
|
70
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.3.13.3
|
75
|
+
version:
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: mongrel_cluster
|
78
|
+
version_requirement:
|
79
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.2.0
|
84
|
+
version:
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: sqlite3-ruby
|
87
|
+
version_requirement:
|
88
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.1.0
|
93
|
+
version:
|