gigpark-ec2onrails 0.9.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +190 -0
- data/COPYING +339 -0
- data/Manifest +160 -0
- data/README.textile +233 -0
- data/Rakefile +31 -0
- data/TODO +104 -0
- data/ec2onrails.gemspec +46 -0
- data/echoe_config.rb +27 -0
- data/examples/Capfile +3 -0
- data/examples/deploy.rb +103 -0
- data/examples/s3.yml +9 -0
- data/lib/ec2onrails.rb +20 -0
- data/lib/ec2onrails/capistrano_utils.rb +47 -0
- data/lib/ec2onrails/recipes.rb +146 -0
- data/lib/ec2onrails/recipes/db.rb +366 -0
- data/lib/ec2onrails/recipes/deploy.rb +26 -0
- data/lib/ec2onrails/recipes/server.rb +517 -0
- data/lib/ec2onrails/version.rb +29 -0
- data/server/build +74 -0
- data/server/files/etc/README +7 -0
- data/server/files/etc/aliases +5 -0
- data/server/files/etc/cron.d/ec2onrails +16 -0
- data/server/files/etc/cron.daily/app +31 -0
- data/server/files/etc/cron.daily/logrotate_post +25 -0
- data/server/files/etc/cron.hourly/app +31 -0
- data/server/files/etc/cron.monthly/app +31 -0
- data/server/files/etc/cron.weekly/app +31 -0
- data/server/files/etc/default/varnish +33 -0
- data/server/files/etc/default/varnishncsa +11 -0
- data/server/files/etc/denyhosts.conf +628 -0
- data/server/files/etc/dpkg/dpkg.cfg +13 -0
- data/server/files/etc/ec2onrails/rails_env +1 -0
- data/server/files/etc/ec2onrails/roles.yml +5 -0
- data/server/files/etc/environment +2 -0
- data/server/files/etc/event.d/god +8 -0
- data/server/files/etc/god/db_primary.god +16 -0
- data/server/files/etc/god/dkim_filter.god +17 -0
- data/server/files/etc/god/master.conf +40 -0
- data/server/files/etc/god/memcache.god +15 -0
- data/server/files/etc/god/notifications.god +11 -0
- data/server/files/etc/god/proxy.god +40 -0
- data/server/files/etc/god/system.god +37 -0
- data/server/files/etc/god/web.god +23 -0
- data/server/files/etc/init.d/ec2-every-startup +29 -0
- data/server/files/etc/init.d/ec2-first-startup +37 -0
- data/server/files/etc/init.d/nginx +78 -0
- data/server/files/etc/logrotate.d/nginx +10 -0
- data/server/files/etc/logrotate.d/rails +8 -0
- data/server/files/etc/logrotate.d/varnish +14 -0
- data/server/files/etc/memcached.conf +47 -0
- data/server/files/etc/motd.tail +13 -0
- data/server/files/etc/mysql/my.cnf +152 -0
- data/server/files/etc/nginx/conf.d/custom.conf +1 -0
- data/server/files/etc/nginx/nginx.conf.erb +152 -0
- data/server/files/etc/postfix/main.cf +4 -0
- data/server/files/etc/ssh/sshd_config +96 -0
- data/server/files/etc/sudoers +31 -0
- data/server/files/etc/syslog.conf +63 -0
- data/server/files/etc/varnish/default.vcl.erb +140 -0
- data/server/files/usr/local/ec2onrails/COPYING +339 -0
- data/server/files/usr/local/ec2onrails/bin/archive_file +44 -0
- data/server/files/usr/local/ec2onrails/bin/backup_app_db +160 -0
- data/server/files/usr/local/ec2onrails/bin/backup_dir +89 -0
- data/server/files/usr/local/ec2onrails/bin/ec2_meta_data +80 -0
- data/server/files/usr/local/ec2onrails/bin/exec_runner +76 -0
- data/server/files/usr/local/ec2onrails/bin/in_role +33 -0
- data/server/files/usr/local/ec2onrails/bin/init_services +43 -0
- data/server/files/usr/local/ec2onrails/bin/install_system_files +56 -0
- data/server/files/usr/local/ec2onrails/bin/optimize_mysql +346 -0
- data/server/files/usr/local/ec2onrails/bin/public-hostname +24 -0
- data/server/files/usr/local/ec2onrails/bin/rails_env +33 -0
- data/server/files/usr/local/ec2onrails/bin/rebundle +62 -0
- data/server/files/usr/local/ec2onrails/bin/restore_app_db +58 -0
- data/server/files/usr/local/ec2onrails/bin/set_rails_env +36 -0
- data/server/files/usr/local/ec2onrails/bin/set_roles +36 -0
- data/server/files/usr/local/ec2onrails/bin/uninstall_system_files +34 -0
- data/server/files/usr/local/ec2onrails/config +30 -0
- data/server/files/usr/local/ec2onrails/lib/aws_helper.rb +75 -0
- data/server/files/usr/local/ec2onrails/lib/god_helper.rb +84 -0
- data/server/files/usr/local/ec2onrails/lib/mysql_helper.rb +100 -0
- data/server/files/usr/local/ec2onrails/lib/roles_helper.rb +156 -0
- data/server/files/usr/local/ec2onrails/lib/s3_helper.rb +116 -0
- data/server/files/usr/local/ec2onrails/lib/system_files_helper.rb +110 -0
- data/server/files/usr/local/ec2onrails/lib/system_files_manifest.rb +107 -0
- data/server/files/usr/local/ec2onrails/lib/utils.rb +26 -0
- data/server/files/usr/local/ec2onrails/lib/vendor/ini.rb +268 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/README +5 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/create-mysqld-pid-dir +26 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/README +5 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/create-dirs +45 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/generate-default-web-cert-and-key +49 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/get-hostname +27 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/misc +27 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/prepare-mysql-data-dir +24 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-credentials +32 -0
- data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-file-permissions +30 -0
- data/server/rakefile-wrapper +26 -0
- data/server/rakefile.rb +267 -0
- data/test/autobench.conf +60 -0
- data/test/spec/lib/s3_helper_spec.rb +154 -0
- data/test/spec/lib/s3_old.yml +3 -0
- data/test/spec/lib/system_files_manifest_spec.rb +122 -0
- data/test/spec/test_files/system_files1/_manifest +13 -0
- data/test/spec/test_files/system_files1/test1 +0 -0
- data/test/spec/test_files/system_files1/test2 +0 -0
- data/test/spec/test_files/system_files1/testfolder/test3 +0 -0
- data/test/spec/test_files/system_files2/_manifest +2 -0
- data/test/spec/test_files/system_files2/test1 +0 -0
- data/test/spec/test_files/system_files2/test2 +0 -0
- data/test/spec/test_files/system_files2/testfolder/test3 +0 -0
- data/test/spec/test_files/test2 +0 -0
- data/test/test_app/Capfile +3 -0
- data/test/test_app/README +243 -0
- data/test/test_app/Rakefile +10 -0
- data/test/test_app/app/controllers/application_controller.rb +10 -0
- data/test/test_app/app/controllers/db_fast_controller.rb +6 -0
- data/test/test_app/app/controllers/fast_controller.rb +5 -0
- data/test/test_app/app/controllers/slow_controller.rb +6 -0
- data/test/test_app/app/controllers/very_slow_controller.rb +6 -0
- data/test/test_app/app/helpers/application_helper.rb +3 -0
- data/test/test_app/config/boot.rb +110 -0
- data/test/test_app/config/database.yml +24 -0
- data/test/test_app/config/deploy.rb +22 -0
- data/test/test_app/config/ec2onrails/config.rb +5 -0
- data/test/test_app/config/environment.rb +41 -0
- data/test/test_app/config/environments/development.rb +17 -0
- data/test/test_app/config/environments/production.rb +28 -0
- data/test/test_app/config/environments/test.rb +28 -0
- data/test/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/test_app/config/initializers/inflections.rb +10 -0
- data/test/test_app/config/initializers/mime_types.rb +5 -0
- data/test/test_app/config/initializers/new_rails_defaults.rb +19 -0
- data/test/test_app/config/initializers/session_store.rb +15 -0
- data/test/test_app/config/locales/en.yml +5 -0
- data/test/test_app/config/routes.rb +43 -0
- data/test/test_app/doc/README_FOR_APP +2 -0
- data/test/test_app/public/404.html +30 -0
- data/test/test_app/public/422.html +30 -0
- data/test/test_app/public/500.html +30 -0
- data/test/test_app/public/favicon.ico +0 -0
- data/test/test_app/public/images/rails.png +0 -0
- data/test/test_app/public/index.html +275 -0
- data/test/test_app/public/javascripts/application.js +2 -0
- data/test/test_app/public/javascripts/controls.js +963 -0
- data/test/test_app/public/javascripts/dragdrop.js +973 -0
- data/test/test_app/public/javascripts/effects.js +1128 -0
- data/test/test_app/public/javascripts/prototype.js +4320 -0
- data/test/test_app/public/robots.txt +5 -0
- data/test/test_app/script/about +4 -0
- data/test/test_app/script/console +3 -0
- data/test/test_app/script/dbconsole +3 -0
- data/test/test_app/script/destroy +3 -0
- data/test/test_app/script/generate +3 -0
- data/test/test_app/script/performance/benchmarker +3 -0
- data/test/test_app/script/performance/profiler +3 -0
- data/test/test_app/script/plugin +3 -0
- data/test/test_app/script/runner +3 -0
- data/test/test_app/script/server +3 -0
- data/test/test_app/test/performance/browsing_test.rb +9 -0
- data/test/test_app/test/test_helper.rb +38 -0
- metadata +266 -0
data/test/autobench.conf
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Autobench Configuration File
|
2
|
+
|
3
|
+
# host1, host2
|
4
|
+
# The hostnames of the servers under test
|
5
|
+
# Eg. host1 = iis.test.com
|
6
|
+
# host2 = apache.test.com
|
7
|
+
|
8
|
+
file = out.tsv
|
9
|
+
|
10
|
+
host1 = ec2-67-202-61-243.compute-1.amazonaws.com
|
11
|
+
|
12
|
+
# uri1, uri2
|
13
|
+
# The URI to test (relative to the document root). For a fair comparison
|
14
|
+
# the files should be identical (although the paths to them may differ on the
|
15
|
+
# different hosts)
|
16
|
+
|
17
|
+
uri1 = /
|
18
|
+
|
19
|
+
# port1, port2
|
20
|
+
# The port number on which the servers are listening
|
21
|
+
|
22
|
+
port1 = 80
|
23
|
+
|
24
|
+
# low_rate, high_rate, rate_step
|
25
|
+
# The 'rate' is the number of number of connections to open per second.
|
26
|
+
# A series of tests will be conducted, starting at low rate,
|
27
|
+
# increasing by rate step, and finishing at high_rate.
|
28
|
+
# The default settings test at rates of 20,30,40,50...180,190,200
|
29
|
+
|
30
|
+
low_rate = 1
|
31
|
+
high_rate = 5
|
32
|
+
rate_step = 1
|
33
|
+
|
34
|
+
# num_conn, num_call
|
35
|
+
# num_conn is the total number of connections to make during a test
|
36
|
+
# num_call is the number of requests per connection
|
37
|
+
# The product of num_call and rate is the the approximate number of
|
38
|
+
# requests per second that will be attempted.
|
39
|
+
|
40
|
+
num_conn = 1000
|
41
|
+
num_call = 5
|
42
|
+
|
43
|
+
# timeout sets the maximimum time (in seconds) that httperf will wait
|
44
|
+
# for replies from the web server. If the timeout is exceeded, the
|
45
|
+
# reply concerned is counted as an error.
|
46
|
+
|
47
|
+
timeout = 10
|
48
|
+
|
49
|
+
# output_fmt
|
50
|
+
# sets the output type - may be either "csv", or "tsv";
|
51
|
+
|
52
|
+
output_fmt = tsv
|
53
|
+
|
54
|
+
## Config for distributed autobench (autobench_admin)
|
55
|
+
# clients
|
56
|
+
# comma separated list of the hostnames and portnumbers for the
|
57
|
+
# autobench clients. No whitespace can appear before or after the commas.
|
58
|
+
# clients = bench1.foo.com:4600,bench2.foo.com:4600,bench3.foo.com:4600
|
59
|
+
|
60
|
+
#clients = localhost:4600
|
@@ -0,0 +1,154 @@
|
|
1
|
+
# This file is part of EC2 on Rails.
|
2
|
+
# http://rubyforge.org/projects/ec2onrails/
|
3
|
+
#
|
4
|
+
# Copyright 2007 Paul Dowman, http://pauldowman.com/
|
5
|
+
#
|
6
|
+
# EC2 on Rails is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# EC2 on Rails is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'spec'
|
20
|
+
require "#{File.dirname(__FILE__)}/../../../server/files/usr/local/ec2onrails/lib/s3_helper"
|
21
|
+
|
22
|
+
REAL_S3_CONFIG = "#{File.dirname(__FILE__)}/../../../../local/s3.yml"
|
23
|
+
MOCK_S3_CONFIG = "#{File.dirname(__FILE__)}/../../../examples/s3.yml"
|
24
|
+
|
25
|
+
TEST_FILE_1 = "#{File.dirname(__FILE__)}/../test_files/test1"
|
26
|
+
TEST_FILE_2 = "#{File.dirname(__FILE__)}/../test_files/test2"
|
27
|
+
|
28
|
+
describe Ec2onrails::S3Helper do
|
29
|
+
before(:each) do
|
30
|
+
FileUtils.rm_f("/tmp/test*")
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "with a mock connection" do
|
34
|
+
before(:each) do
|
35
|
+
bucket = mock("bucket")
|
36
|
+
s3 = mock("s3")
|
37
|
+
s3.stub!(:bucket).and_return bucket
|
38
|
+
RightAws::S3.stub!(:new).and_return(s3)
|
39
|
+
@s3_helper = Ec2onrails::S3Helper.new("bucket", nil, MOCK_S3_CONFIG, "production")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can load S3 config details from a config file with multiple environment sections" do
|
43
|
+
@s3_helper.aws_access_key.should == "DEF456"
|
44
|
+
@s3_helper.aws_secret_access_key.should == "def456def456def456def456"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "can load S3 config details from a config file with no environment sections" do
|
48
|
+
s3 = Ec2onrails::S3Helper.new("bucket", nil, "#{File.dirname(__FILE__)}/s3_old.yml", "production")
|
49
|
+
s3.aws_access_key.should == "ABC123"
|
50
|
+
s3.aws_secret_access_key.should == "abc123abc123abc123abc123"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can create an s3 key using a given filename" do
|
54
|
+
@s3_helper.s3_key(TEST_FILE_1).should == "test1"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "can create an s3 key using a given filename and a subdir name" do
|
58
|
+
@s3_helper = Ec2onrails::S3Helper.new("bucket", "subdir", MOCK_S3_CONFIG, "production")
|
59
|
+
@s3_helper.s3_key(TEST_FILE_1).should == "subdir/test1"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "with a real connection" do
|
64
|
+
# Integration tests to make sure we can use the real API
|
65
|
+
# TODO these are currently broken, fix them and come up with a better way of specifying the real S3 credentials, maybe specify in ENV?
|
66
|
+
before(:each) do
|
67
|
+
@s3_helper = Ec2onrails::S3Helper.new("ec2onrails-test", nil, REAL_S3_CONFIG, "production")
|
68
|
+
begin
|
69
|
+
bucket = AWS::S3::Bucket.find(@s3_helper.bucket)
|
70
|
+
bucket.delete_all
|
71
|
+
# bucket.delete
|
72
|
+
rescue AWS::S3::NoSuchBucket
|
73
|
+
# no problem
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "can create a bucket" do
|
78
|
+
@s3_helper.create_bucket
|
79
|
+
AWS::S3::Bucket.find(@s3_helper.bucket)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "can upload a file to S3" do
|
83
|
+
@s3_helper.store_file(TEST_FILE_1)
|
84
|
+
AWS::S3::S3Object.find("test1", "ec2onrails-test")
|
85
|
+
end
|
86
|
+
|
87
|
+
it "can upload a file to S3 into a subdir" do
|
88
|
+
@s3_helper = Ec2onrails::S3Helper.new("test", "subdir", REAL_S3_CONFIG, "production")
|
89
|
+
@s3_helper.store_file(TEST_FILE_1)
|
90
|
+
AWS::S3::S3Object.find("subdir/test1", "ec2onrails-test")
|
91
|
+
end
|
92
|
+
|
93
|
+
it "can retrieve a file from S3" do
|
94
|
+
@s3_helper.store_file(TEST_FILE_1)
|
95
|
+
AWS::S3::S3Object.find("test1", "ec2onrails-test")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "can retrieve a file from S3 into a subdir" do
|
99
|
+
@s3_helper = Ec2onrails::S3Helper.new("test", "subdir", REAL_S3_CONFIG, "production")
|
100
|
+
@s3_helper.store_file(TEST_FILE_1)
|
101
|
+
@s3_helper.retrieve_file("/tmp/test1")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "can delete files with a given prefix" do
|
105
|
+
@s3_helper.store_file(TEST_FILE_1)
|
106
|
+
@s3_helper.store_file(TEST_FILE_2)
|
107
|
+
AWS::S3::S3Object.find("test1", "ec2onrails-test")
|
108
|
+
AWS::S3::S3Object.find("test2", "ec2onrails-test")
|
109
|
+
@s3_helper.delete_files("test")
|
110
|
+
lambda {
|
111
|
+
AWS::S3::S3Object.find("test1", "ec2onrails-test")
|
112
|
+
}.should raise_error
|
113
|
+
lambda {
|
114
|
+
AWS::S3::S3Object.find("test2", "ec2onrails-test")
|
115
|
+
}.should raise_error
|
116
|
+
end
|
117
|
+
|
118
|
+
it "can delete files with a given prefix in a subdir" do
|
119
|
+
@s3_helper = Ec2onrails::S3Helper.new("test", "subdir", REAL_S3_CONFIG, "production")
|
120
|
+
@s3_helper.store_file(TEST_FILE_1)
|
121
|
+
@s3_helper.store_file(TEST_FILE_2)
|
122
|
+
AWS::S3::S3Object.find("subdir/test1", "ec2onrails-test")
|
123
|
+
AWS::S3::S3Object.find("subdir/test2", "ec2onrails-test")
|
124
|
+
@s3_helper.delete_files("test")
|
125
|
+
lambda {
|
126
|
+
AWS::S3::S3Object.find("subdir/test1", "ec2onrails-test")
|
127
|
+
}.should raise_error
|
128
|
+
lambda {
|
129
|
+
AWS::S3::S3Object.find("subdir/test2", "ec2onrails-test")
|
130
|
+
}.should raise_error
|
131
|
+
end
|
132
|
+
|
133
|
+
it "can retrieve files with a given prefix into a local dir" do
|
134
|
+
@s3_helper.store_file(TEST_FILE_1)
|
135
|
+
@s3_helper.store_file(TEST_FILE_2)
|
136
|
+
AWS::S3::S3Object.find("test1", "ec2onrails-test")
|
137
|
+
AWS::S3::S3Object.find("test2", "ec2onrails-test")
|
138
|
+
@s3_helper.retrieve_files("test", "/tmp")
|
139
|
+
File.exists?("/tmp/test1").should be_true
|
140
|
+
File.exists?("/tmp/test2").should be_true
|
141
|
+
end
|
142
|
+
|
143
|
+
it "can retrieve files with a given prefix in a subdir into a local dir" do
|
144
|
+
@s3_helper = Ec2onrails::S3Helper.new("test", "subdir", REAL_S3_CONFIG, "production")
|
145
|
+
@s3_helper.store_file(TEST_FILE_1)
|
146
|
+
@s3_helper.store_file(TEST_FILE_2)
|
147
|
+
AWS::S3::S3Object.find("subdir/test1", "ec2onrails-test")
|
148
|
+
AWS::S3::S3Object.find("subdir/test2", "ec2onrails-test")
|
149
|
+
@s3_helper.retrieve_files("test", "/tmp")
|
150
|
+
File.exists?("/tmp/test1").should be_true
|
151
|
+
File.exists?("/tmp/test2").should be_true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# This file is part of EC2 on Rails.
|
2
|
+
# http://rubyforge.org/projects/ec2onrails/
|
3
|
+
#
|
4
|
+
# Copyright 2007 Paul Dowman, http://pauldowman.com/
|
5
|
+
#
|
6
|
+
# EC2 on Rails is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# EC2 on Rails is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
require 'spec'
|
20
|
+
require "#{File.dirname(__FILE__)}/../../../server/files/usr/local/ec2onrails/lib/system_files_manifest"
|
21
|
+
|
22
|
+
TEST_FILES_ROOT = "#{File.dirname(__FILE__)}/../test_files"
|
23
|
+
|
24
|
+
describe Ec2onrails::SystemFilesManifest do
|
25
|
+
before(:each) do
|
26
|
+
Ec2onrails::SystemFilesManifest.stub!(:log_error)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "with a valid directory that matches the manifest" do
|
30
|
+
before(:each) do
|
31
|
+
@dir = File.join TEST_FILES_ROOT, "system_files1"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can construct a new object from the directory" do
|
35
|
+
Ec2onrails::SystemFilesManifest.new @dir
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can construct a new object given the manifest file name" do
|
39
|
+
Ec2onrails::SystemFilesManifest.new "#{@dir}/#{Ec2onrails::SystemFilesManifest::MANIFEST_FILE_NAME}"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "recognizes the format of comment and empty lines" do
|
43
|
+
m = Ec2onrails::SystemFilesManifest.new(@dir)
|
44
|
+
m.comment_or_empty_line?("").should be_true
|
45
|
+
m.comment_or_empty_line?(" ").should be_true
|
46
|
+
m.comment_or_empty_line?(" ").should be_true
|
47
|
+
m.comment_or_empty_line?("\t ").should be_true
|
48
|
+
m.comment_or_empty_line?("#").should be_true
|
49
|
+
m.comment_or_empty_line?(" #").should be_true
|
50
|
+
m.comment_or_empty_line?("\t#").should be_true
|
51
|
+
m.comment_or_empty_line?(" #xx ").should be_true
|
52
|
+
m.comment_or_empty_line?(" #xx # ").should be_true
|
53
|
+
|
54
|
+
m.comment_or_empty_line?(" x# ").should be_false
|
55
|
+
m.comment_or_empty_line?(" x#xx ").should be_false
|
56
|
+
m.comment_or_empty_line?("x#").should be_false
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can provide metadata about the mode and owner of the file" do
|
60
|
+
m = Ec2onrails::SystemFilesManifest.new @dir
|
61
|
+
m["test1"].should == {:mode => nil, :owner => nil}
|
62
|
+
m["test2"].should == {:mode => "777", :owner => "user1:user1"}
|
63
|
+
m["testfolder"].should == {:mode => nil, :owner => nil}
|
64
|
+
m["testfolder/test3"].should == {:mode => "700", :owner => "user2"}
|
65
|
+
end
|
66
|
+
|
67
|
+
it "can provide metadata about the file even if the filename has a leading slash appended" do
|
68
|
+
m = Ec2onrails::SystemFilesManifest.new @dir
|
69
|
+
m["/test1"].should == {:mode => nil, :owner => nil}
|
70
|
+
end
|
71
|
+
|
72
|
+
it "can provide metadata about the file even if the filename has the full server_files dir path appended" do
|
73
|
+
m = Ec2onrails::SystemFilesManifest.new @dir
|
74
|
+
m["#{@dir}/test1"].should == {:mode => nil, :owner => nil}
|
75
|
+
end
|
76
|
+
|
77
|
+
it "can normalize a given filename by removing the directories up to and including the server_files dir, and removing the leading slash" do
|
78
|
+
m = Ec2onrails::SystemFilesManifest.new @dir
|
79
|
+
m.normalize("test").should == "test"
|
80
|
+
m.normalize("/test").should == "test"
|
81
|
+
m.normalize("#{@dir}/test").should == "test"
|
82
|
+
m.normalize("#{@dir}/x/test").should == "x/test"
|
83
|
+
end
|
84
|
+
|
85
|
+
it "can return all filenames as an array" do
|
86
|
+
m = Ec2onrails::SystemFilesManifest.new @dir
|
87
|
+
m.filenames.should == %w(test1 test2 testfolder testfolder/test3)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "with a valid directory that doesn't match the manifest" do
|
92
|
+
before(:each) do
|
93
|
+
@dir = File.join TEST_FILES_ROOT, "system_files2"
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should raise an error on new" do
|
98
|
+
lambda {Ec2onrails::SystemFilesManifest.new @dir}.should raise_error
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "with a valid directory that contains no manifest" do
|
103
|
+
before(:each) do
|
104
|
+
@dir = File.join TEST_FILES_ROOT
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should raise an error on new" do
|
108
|
+
lambda {Ec2onrails::SystemFilesManifest.new @dir}.should raise_error
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "with an invalid directory" do
|
113
|
+
before(:each) do
|
114
|
+
@dir = "does_not_exist"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should raise an error on new" do
|
118
|
+
lambda {Ec2onrails::SystemFilesManifest.new @dir}.should raise_error
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This is a manifest file with comments
|
2
|
+
|
3
|
+
# test1 has no metadata
|
4
|
+
test1
|
5
|
+
|
6
|
+
# test2 should have mode 777 and be owned by user1
|
7
|
+
test2 mode=777 owner=user1:user1
|
8
|
+
|
9
|
+
# testfolder has no metadata
|
10
|
+
testfolder
|
11
|
+
|
12
|
+
# test3 should be mode 700 and owned by user2
|
13
|
+
testfolder/test3 mode=700 owner=user2
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,243 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application framework that includes everything needed to create
|
4
|
+
database-backed web applications according to the Model-View-Control pattern.
|
5
|
+
|
6
|
+
This pattern splits the view (also called the presentation) into "dumb" templates
|
7
|
+
that are primarily responsible for inserting pre-built data in between HTML tags.
|
8
|
+
The model contains the "smart" domain objects (such as Account, Product, Person,
|
9
|
+
Post) that holds all the business logic and knows how to persist themselves to
|
10
|
+
a database. The controller handles the incoming requests (such as Save New Account,
|
11
|
+
Update Product, Show Post) by manipulating the model and directing data to the view.
|
12
|
+
|
13
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
14
|
+
layer entitled Active Record. This layer allows you to present the data from
|
15
|
+
database rows as objects and embellish these data objects with business logic
|
16
|
+
methods. You can read more about Active Record in
|
17
|
+
link:files/vendor/rails/activerecord/README.html.
|
18
|
+
|
19
|
+
The controller and view are handled by the Action Pack, which handles both
|
20
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
21
|
+
are bundled in a single package due to their heavy interdependence. This is
|
22
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
23
|
+
more separate. Each of these packages can be used independently outside of
|
24
|
+
Rails. You can read more about Action Pack in
|
25
|
+
link:files/vendor/rails/actionpack/README.html.
|
26
|
+
|
27
|
+
|
28
|
+
== Getting Started
|
29
|
+
|
30
|
+
1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
|
31
|
+
and your application name. Ex: rails myapp
|
32
|
+
2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
|
33
|
+
3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
|
34
|
+
4. Follow the guidelines to start developing your application
|
35
|
+
|
36
|
+
|
37
|
+
== Web Servers
|
38
|
+
|
39
|
+
By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
|
40
|
+
with a variety of other web servers.
|
41
|
+
|
42
|
+
Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
|
43
|
+
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
|
44
|
+
getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
|
45
|
+
More info at: http://mongrel.rubyforge.org
|
46
|
+
|
47
|
+
Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
|
48
|
+
Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
|
49
|
+
FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
|
50
|
+
|
51
|
+
== Apache .htaccess example for FCGI/CGI
|
52
|
+
|
53
|
+
# General Apache options
|
54
|
+
AddHandler fastcgi-script .fcgi
|
55
|
+
AddHandler cgi-script .cgi
|
56
|
+
Options +FollowSymLinks +ExecCGI
|
57
|
+
|
58
|
+
# If you don't want Rails to look in certain directories,
|
59
|
+
# use the following rewrite rules so that Apache won't rewrite certain requests
|
60
|
+
#
|
61
|
+
# Example:
|
62
|
+
# RewriteCond %{REQUEST_URI} ^/notrails.*
|
63
|
+
# RewriteRule .* - [L]
|
64
|
+
|
65
|
+
# Redirect all requests not available on the filesystem to Rails
|
66
|
+
# By default the cgi dispatcher is used which is very slow
|
67
|
+
#
|
68
|
+
# For better performance replace the dispatcher with the fastcgi one
|
69
|
+
#
|
70
|
+
# Example:
|
71
|
+
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
|
72
|
+
RewriteEngine On
|
73
|
+
|
74
|
+
# If your Rails application is accessed via an Alias directive,
|
75
|
+
# then you MUST also set the RewriteBase in this htaccess file.
|
76
|
+
#
|
77
|
+
# Example:
|
78
|
+
# Alias /myrailsapp /path/to/myrailsapp/public
|
79
|
+
# RewriteBase /myrailsapp
|
80
|
+
|
81
|
+
RewriteRule ^$ index.html [QSA]
|
82
|
+
RewriteRule ^([^.]+)$ $1.html [QSA]
|
83
|
+
RewriteCond %{REQUEST_FILENAME} !-f
|
84
|
+
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
|
85
|
+
|
86
|
+
# In case Rails experiences terminal errors
|
87
|
+
# Instead of displaying this message you can supply a file here which will be rendered instead
|
88
|
+
#
|
89
|
+
# Example:
|
90
|
+
# ErrorDocument 500 /500.html
|
91
|
+
|
92
|
+
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
|
93
|
+
|
94
|
+
|
95
|
+
== Debugging Rails
|
96
|
+
|
97
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
98
|
+
will help you debug it and get it back on the rails.
|
99
|
+
|
100
|
+
First area to check is the application log files. Have "tail -f" commands running
|
101
|
+
on the server.log and development.log. Rails will automatically display debugging
|
102
|
+
and runtime information to these files. Debugging info will also be shown in the
|
103
|
+
browser on requests from 127.0.0.1.
|
104
|
+
|
105
|
+
You can also log your own messages directly into the log file from your code using
|
106
|
+
the Ruby logger class from inside your controllers. Example:
|
107
|
+
|
108
|
+
class WeblogController < ActionController::Base
|
109
|
+
def destroy
|
110
|
+
@weblog = Weblog.find(params[:id])
|
111
|
+
@weblog.destroy
|
112
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
The result will be a message in your log file along the lines of:
|
117
|
+
|
118
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
|
119
|
+
|
120
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
121
|
+
|
122
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
|
123
|
+
|
124
|
+
* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
|
125
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
126
|
+
|
127
|
+
These two online (and free) books will bring you up to speed on the Ruby language
|
128
|
+
and also on programming in general.
|
129
|
+
|
130
|
+
|
131
|
+
== Debugger
|
132
|
+
|
133
|
+
Debugger support is available through the debugger command when you start your Mongrel or
|
134
|
+
Webrick server with --debugger. This means that you can break out of execution at any point
|
135
|
+
in the code, investigate and change the model, AND then resume execution!
|
136
|
+
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
|
137
|
+
Example:
|
138
|
+
|
139
|
+
class WeblogController < ActionController::Base
|
140
|
+
def index
|
141
|
+
@posts = Post.find(:all)
|
142
|
+
debugger
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
So the controller will accept the action, run the first line, then present you
|
147
|
+
with a IRB prompt in the server window. Here you can do things like:
|
148
|
+
|
149
|
+
>> @posts.inspect
|
150
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
151
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
152
|
+
>> @posts.first.title = "hello from a debugger"
|
153
|
+
=> "hello from a debugger"
|
154
|
+
|
155
|
+
...and even better is that you can examine how your runtime objects actually work:
|
156
|
+
|
157
|
+
>> f = @posts.first
|
158
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
159
|
+
>> f.
|
160
|
+
Display all 152 possibilities? (y or n)
|
161
|
+
|
162
|
+
Finally, when you're ready to resume execution, you enter "cont"
|
163
|
+
|
164
|
+
|
165
|
+
== Console
|
166
|
+
|
167
|
+
You can interact with the domain model by starting the console through <tt>script/console</tt>.
|
168
|
+
Here you'll have all parts of the application configured, just like it is when the
|
169
|
+
application is running. You can inspect domain models, change values, and save to the
|
170
|
+
database. Starting the script without arguments will launch it in the development environment.
|
171
|
+
Passing an argument will specify a different environment, like <tt>script/console production</tt>.
|
172
|
+
|
173
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
174
|
+
|
175
|
+
== dbconsole
|
176
|
+
|
177
|
+
You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
|
178
|
+
You would be connected to the database with the credentials defined in database.yml.
|
179
|
+
Starting the script without arguments will connect you to the development database. Passing an
|
180
|
+
argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
|
181
|
+
Currently works for mysql, postgresql and sqlite.
|
182
|
+
|
183
|
+
== Description of Contents
|
184
|
+
|
185
|
+
app
|
186
|
+
Holds all the code that's specific to this particular application.
|
187
|
+
|
188
|
+
app/controllers
|
189
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
190
|
+
automated URL mapping. All controllers should descend from ApplicationController
|
191
|
+
which itself descends from ActionController::Base.
|
192
|
+
|
193
|
+
app/models
|
194
|
+
Holds models that should be named like post.rb.
|
195
|
+
Most models will descend from ActiveRecord::Base.
|
196
|
+
|
197
|
+
app/views
|
198
|
+
Holds the template files for the view that should be named like
|
199
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
|
200
|
+
syntax.
|
201
|
+
|
202
|
+
app/views/layouts
|
203
|
+
Holds the template files for layouts to be used with views. This models the common
|
204
|
+
header/footer method of wrapping views. In your views, define a layout using the
|
205
|
+
<tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
|
206
|
+
call <% yield %> to render the view using this layout.
|
207
|
+
|
208
|
+
app/helpers
|
209
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are generated
|
210
|
+
for you automatically when using script/generate for controllers. Helpers can be used to
|
211
|
+
wrap functionality for your views into methods.
|
212
|
+
|
213
|
+
config
|
214
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
215
|
+
|
216
|
+
db
|
217
|
+
Contains the database schema in schema.rb. db/migrate contains all
|
218
|
+
the sequence of Migrations for your schema.
|
219
|
+
|
220
|
+
doc
|
221
|
+
This directory is where your application documentation will be stored when generated
|
222
|
+
using <tt>rake doc:app</tt>
|
223
|
+
|
224
|
+
lib
|
225
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
226
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
227
|
+
|
228
|
+
public
|
229
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
230
|
+
and javascripts. Also contains the dispatchers and the default HTML files. This should be
|
231
|
+
set as the DOCUMENT_ROOT of your web server.
|
232
|
+
|
233
|
+
script
|
234
|
+
Helper scripts for automation and generation.
|
235
|
+
|
236
|
+
test
|
237
|
+
Unit and functional tests along with fixtures. When using the script/generate scripts, template
|
238
|
+
test files will be generated for you and placed in this directory.
|
239
|
+
|
240
|
+
vendor
|
241
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
242
|
+
If the app has frozen rails, those gems also go here, under vendor/rails/.
|
243
|
+
This directory is in the load path.
|