beans_rails 0.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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 80beans
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "beans_rails"
8
+ gem.summary = %Q{the 80beans rails project template (and generator)}
9
+ gem.description = %Q{the 80beans rails project template (and generator)}
10
+ gem.email = "jeff@80beans.com"
11
+ gem.homepage = "http://github.com/80beans/beans_rails"
12
+ gem.authors = ["Jeff Kreeftmeijer"]
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
16
+ end
17
+
18
+ require 'rake/testtask'
19
+ Rake::TestTask.new(:test) do |test|
20
+ test.libs << 'lib' << 'test'
21
+ test.pattern = 'test/**/*_test.rb'
22
+ test.verbose = true
23
+ end
24
+
25
+ begin
26
+ require 'rcov/rcovtask'
27
+ Rcov::RcovTask.new do |test|
28
+ test.libs << 'test'
29
+ test.pattern = 'test/**/*_test.rb'
30
+ test.verbose = true
31
+ end
32
+ rescue LoadError
33
+ task :rcov do
34
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
35
+ end
36
+ end
37
+
38
+ task :test => :check_dependencies
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION')
45
+ version = File.read('VERSION')
46
+ else
47
+ version = ""
48
+ end
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "beans_rails #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
55
+
56
+ Jeweler::GemcutterTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{beans_rails}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jeff Kreeftmeijer"]
12
+ s.date = %q{2009-12-08}
13
+ s.default_executable = %q{beans_rails}
14
+ s.description = %q{the 80beans rails project template (and generator)}
15
+ s.email = %q{jeff@80beans.com}
16
+ s.executables = ["beans_rails"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "beans_rails.gemspec",
27
+ "beans_rails.rb",
28
+ "bin/beans_rails",
29
+ "templates/.gitignore",
30
+ "templates/Capfile",
31
+ "templates/Gemfile",
32
+ "templates/config/database.yml",
33
+ "templates/config/deploy.rb",
34
+ "templates/deploy/beans_server.rb",
35
+ "templates/deploy/config/staging.yml",
36
+ "templates/deploy/production.rb",
37
+ "templates/deploy/staging.rb",
38
+ "templates/deploy/templates/database.erb",
39
+ "templates/deploy/templates/public_keys.txt",
40
+ "templates/deploy/templates/staging_vhost.erb"
41
+ ]
42
+ s.homepage = %q{http://github.com/80beans/beans_rails}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.5}
46
+ s.summary = %q{the 80beans rails project template (and generator)}
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ else
54
+ end
55
+ else
56
+ end
57
+ end
data/beans_rails.rb ADDED
@@ -0,0 +1,65 @@
1
+ TEMPLATES_DIR = 'http://github.com/80beans/beans_rails/raw/bundler/templates/'
2
+
3
+ class Rails::TemplateRunner
4
+ def app_name
5
+ File.basename(root)
6
+ end
7
+
8
+ def template_file(template, replace = {})
9
+ replace = {:app_name => app_name}.merge(replace)
10
+ contents = open(File.join(TEMPLATES_DIR, template)).read
11
+ replace.keys.each { |key| contents.gsub!("{{#{key.to_s}}}", replace[key]) }
12
+ file(template, contents)
13
+ end
14
+ end
15
+
16
+ # removing unnecessary files
17
+
18
+ ['README', 'doc/*', 'log/*', 'test', 'public/index.html', 'public/images/rails.png'].each { |file| run "rm -rf #{file}" }
19
+
20
+ # create the needed directories
21
+ ['config', 'deploy', 'deploy/config', 'deploy/templates'].each { |dir| run "mkdir #{dir}"}
22
+
23
+ # install bundler
24
+
25
+ gem 'bundler'
26
+ rake "gems:install", :sudo => true
27
+
28
+ # copy the .gitignore, database.yml and Gemfile to the app
29
+
30
+ ['Gemfile', '.gitignore', 'config/database.yml' ].each { |file| template_file(file) }
31
+
32
+ # bundle the gems
33
+
34
+ run 'gem bundle'
35
+
36
+ # generating rspec stuff
37
+
38
+ generate :rspec
39
+
40
+ # capistrano
41
+
42
+ if yes?('Add capistrano configuration?')
43
+ [
44
+ 'Capfile',
45
+ 'config/deploy.rb',
46
+ 'deploy/beans_server.rb',
47
+ 'deploy/production.rb',
48
+ 'deploy/staging.rb',
49
+ 'deploy/config/staging.yml',
50
+ 'deploy/templates/database.erb',
51
+ 'deploy/templates/public_keys.txt',
52
+ 'deploy/templates/staging_vhost.erb'
53
+ ].each { |file| template_file(file) }
54
+ end
55
+
56
+ # git
57
+
58
+ git :init
59
+ git :add => "."
60
+ git :commit => "-a -m 'Initial commit'"
61
+
62
+ if yes?("Push to remote git repository? (The repository #{app_name} must be configured in Gitosis)") then
63
+ git :remote => "add origin git@git.80beans.net:#{app_name}.git"
64
+ git :push => 'origin master:refs/heads/master'
65
+ end
data/bin/beans_rails ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV.empty?
4
+ puts "Usage: #{$0} /path/to/your/app [options]"
5
+ else
6
+ exec 'rails', '-m', File.expand_path('../../beans_rails.rb', __FILE__), *ARGV
7
+ end
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ tmp
3
+ db/schema.rb
4
+ log/*
5
+ public/uploads
6
+ public/stylesheets/*.css
7
+ bin/*
8
+ vendor/gems/*
9
+ !vendor/gems/cache/
data/templates/Capfile ADDED
@@ -0,0 +1,3 @@
1
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
2
+ Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
3
+ load 'config/deploy'
data/templates/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ gem 'rails', '2.3.5'
2
+ gem 'capistrano'
3
+ gem 'capistrano-ext'
4
+ gem 'haml'
5
+ gem 'paperclip'
6
+ gem 'rspec'
7
+ gem 'rspec-rails'
8
+ gem 'will_paginate'
@@ -0,0 +1,12 @@
1
+ development:
2
+ adapter: mysql
3
+ encoding: utf8
4
+ database: {{app_name}}_dev
5
+ username: root
6
+ password:
7
+ test:
8
+ adapter: mysql
9
+ encoding: utf8
10
+ database: {{app_name}}_test
11
+ username: root
12
+ password:
@@ -0,0 +1,47 @@
1
+ set :default_stage, 'staging'
2
+
3
+ require 'erb'
4
+ require 'capistrano/ext/multistage' # needs the capistrano-ext gem
5
+ require 'config/deploy/beans_server'
6
+
7
+ set :application, '{{app_name}}'
8
+
9
+ set :scm, :git
10
+ set :repository, "git@git.80beans.net:#{application}"
11
+ set :git_enable_submodules, true
12
+ set :deploy_via, :remote_cache
13
+ set :use_sudo, false
14
+ default_run_options[:pty] = true
15
+ ssh_options[:forward_agent] = true
16
+ ssh_options[:username] = application
17
+
18
+
19
+ set :deploy_to, "/home/#{application}/app"
20
+
21
+ task :tail do
22
+ run "tail -f #{deploy_to}/shared/log/production.log"
23
+ end
24
+
25
+ namespace :deploy do
26
+
27
+ task :finalize_update, :roles => :app do
28
+ run "ln -s #{shared_path}/log #{release_path}/log"
29
+ run "ln -s #{shared_path}/tmp #{release_path}/tmp"
30
+ run "ln -s #{shared_path}/uploads #{release_path}/public/uploads"
31
+ end
32
+
33
+ task :start, :roles => :app do
34
+ run "touch #{current_path}/tmp/restart.txt"
35
+ end
36
+
37
+ task :restart, :roles => :app do
38
+ run "touch #{current_path}/tmp/restart.txt"
39
+ end
40
+ end
41
+
42
+ task :create_symlinked_folders do
43
+ run "mkdir -p #{shared_path}/tmp"
44
+ run "mkdir -p #{shared_path}/uploads"
45
+ end
46
+
47
+ after "deploy:setup", :create_symlinked_folders
@@ -0,0 +1,97 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :beans do
3
+
4
+ desc "Configures staging server"
5
+ task :configure, :roles => :app do
6
+ working_directory = current_path
7
+
8
+ @service_name = application
9
+ @server_info = YAML.load(File.read(File.join(File.dirname(__FILE__), 'config', "#{rails_env}.yml")))
10
+ @application_name = "#{application}_#{rails_env}"
11
+ @home_path = "/home/#{@application_name}"
12
+ original_ssh_username = ssh_options[:username]
13
+ ssh_options[:username] = Capistrano::CLI.ui.ask("Username that has sudo rights: ")
14
+
15
+ create_user
16
+ create_htpasswd
17
+ create_vhost
18
+ create_database
19
+ end
20
+
21
+ desc "Generates SSH key for Git Repository"
22
+ task :generate_ssh_key, :roles => :web do
23
+ run "ssh-keygen -q -f #{@home_path}/.ssh/id_rsa -P '' -t dsa"
24
+ show_ssh_key
25
+ end
26
+
27
+ desc "Displays SSH Key for application"
28
+ task :show_ssh_key, :roles => :web do
29
+ key = capture "ssh-keygen -y -f #{@home_path}/.ssh/id_rsa"
30
+ puts "===== SSH KEY =====\n"
31
+ puts key
32
+ puts "==================="
33
+ end
34
+
35
+ desc "Creates the user for the application"
36
+ task :create_user, :roles => :web do
37
+
38
+ sudo "useradd -d #{@home_path} -m -G www-data #{@application_name}"
39
+
40
+ public_keys = File.read(File.join(File.dirname(__FILE__), 'templates', "public_keys.txt"))
41
+
42
+ put public_keys, "#{application}-public_keys.txt"
43
+ sudo "mkdir #{@home_path}/.ssh"
44
+ sudo "cp #{application}-public_keys.txt #{@home_path}/.ssh/authorized_keys"
45
+ sudo "chown -R #{@application_name}:#{@application_name} #{@home_path}/.ssh"
46
+ sudo "rm -rf #{application}-public_keys.txt"
47
+ end
48
+
49
+ desc "Creates htpasswd user"
50
+ task :create_htpasswd, :roles => :web do
51
+ htpasswd_user = Capistrano::CLI.ui.ask("httpasswd user: ")
52
+ htpasswd_pass = Capistrano::CLI.ui.ask("httpasswd pass: ")
53
+ httpasswd_file = "#{@home_path}/.htpasswd"
54
+
55
+ sudo "htpasswd -cb #{httpasswd_file} #{htpasswd_user} #{htpasswd_pass}"
56
+ end
57
+
58
+ desc "Creates an Apache virtual host configuration file"
59
+ task :create_vhost, :roles => :web do
60
+ server_name = @server_info['apache']['base_hostname'] ? "#{application}.#{@server_info['apache']['base_hostname']}" : Capistrano::CLI.ui.ask("Server hostname: ")
61
+ public_path = "#{current_path}/public"
62
+ application_name = @application_name
63
+
64
+ template = File.read(File.join(File.dirname(__FILE__), 'templates', "#{rails_env}_vhost.erb"))
65
+ buffer = ERB.new(template).result(binding)
66
+
67
+ put buffer, "#{application}-apache-vhost.conf"
68
+ sudo "cp #{application}-apache-vhost.conf #{@server_info['apache']['vhost_dir']}/#{application}.conf"
69
+ sudo "rm -rf #{application}-apache-vhost.conf"
70
+ restart_apache
71
+ end
72
+
73
+ desc "Restart apache"
74
+ task :restart_apache, :roles => :web do
75
+ sudo "/etc/init.d/apache2 restart"
76
+ end
77
+
78
+ desc "Create database"
79
+ task :create_database, :roles => :db do
80
+ db_name = "#{application}_#{rails_env}"
81
+
82
+ db_user = application.length < 16 ? application : Capistrano::CLI.ui.ask("Mysql username to long! Mysql username for application: ")
83
+ db_pass = Capistrano::CLI.ui.ask("Mysql password for application user #{db_user}: ")
84
+
85
+ mysql_user = @server_info['mysql']['user'] ? @server_info['mysql']['user'] : Capistrano::CLI.ui.ask("Mysql username for db creation: ")
86
+ mysql_pass = @server_info['mysql']['pass'] ? @server_info['mysql']['pass'] : Capistrano::CLI.ui.ask("Mysql password for #{mysql_user}: ")
87
+
88
+
89
+ template = File.read(File.join(File.dirname(__FILE__), 'templates', "database.erb"))
90
+ buffer = ERB.new(template).result(binding)
91
+
92
+ put buffer, "#{application}-database.sql"
93
+ sudo "mysql -u#{mysql_user} -p#{mysql_pass} < #{application}-database.sql"
94
+ sudo "rm -rf #{application}-database.conf"
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,7 @@
1
+ apache:
2
+ vhost_dir: /etc/apache2/sites-enabled
3
+ base_hostname: staging.80beans.net
4
+
5
+ mysql:
6
+ user: root
7
+ pass:
@@ -0,0 +1,6 @@
1
+ set :username, "#{application}_production"
2
+ set :branch, 'master'
3
+
4
+ set :rails_env, 'production'
5
+
6
+ ssh_options[:username] = username
@@ -0,0 +1,11 @@
1
+ set :username, "#{application}_staging"
2
+ set :branch, 'master'
3
+ set :deploy_to, "/home/#{application}_staging/app"
4
+
5
+ set :rails_env, 'staging'
6
+
7
+ role :app, 'staging.80beans.net'
8
+ role :web, 'staging.80beans.net'
9
+ role :db, 'staging.80beans.net', :primary => true
10
+
11
+ ssh_options[:username] = username
@@ -0,0 +1,2 @@
1
+ CREATE DATABASE <%= db_name %>;
2
+ GRANT ALL PRIVILEGES ON <%= db_name %>.* TO <%= db_user %> IDENTIFIED BY '<%= db_pass %>' WITH GRANT OPTION;
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA5MbbNLFpM06Z7IsBGYGjQ9IKDKbFaxV3fRVoPBm3h3fvJXuZbm7u76CthbAThRLbchFYLI3UilWIG9F2fNVkt1EEUE32Pcm7RRoVHAbQmoK8vgwQv8u96i1fz57xwfyjErkuzUTTpV9P2UgC0+NBIAR34vefQZp3G8WEBHyzQDQYTy6lw4ek2zTK/whtBP4PkYF2vNdyYBofgHi4XRJ0R44PRYFX0znlDAI7ELg4bOq26FvvBdd50NT5OwzXb0GtAjqESfS/MOPoz6D0Nm2t1iJY8QJE85uki7z4Gdmr9FOxuEbLSgtuoEi2tiilQdSaDHxtu3ndIBJo3ia7AqY2ww== robertbeekman@robert-beekmans-macbook-5.local
@@ -0,0 +1,26 @@
1
+ <VirtualHost *:80>
2
+ AddDefaultCharset UTF-8
3
+
4
+ ServerName <%= server_name %>
5
+ DocumentRoot <%= public_path %>
6
+
7
+ ErrorLog /var/log/apache2/<% application_name %>/error.log
8
+ CustomLog /var/log/apache2/<% application_name %>/access.log combined
9
+
10
+ RailsEnv staging
11
+
12
+ <Directory "<%= public_path %>/">
13
+ Options FollowSymLinks
14
+ AllowOverride None
15
+ Order allow,deny
16
+ Allow from all
17
+ </Directory>
18
+
19
+ <Location "/">
20
+ AuthName "Stats"
21
+ AuthType Basic
22
+ AuthUserFile /home/<%= application_name %>/.htpasswd
23
+ Require valid-user
24
+ </Location>
25
+
26
+ </VirtualHost>
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beans_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Kreeftmeijer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-08 00:00:00 +01:00
13
+ default_executable: beans_rails
14
+ dependencies: []
15
+
16
+ description: the 80beans rails project template (and generator)
17
+ email: jeff@80beans.com
18
+ executables:
19
+ - beans_rails
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ files:
25
+ - .document
26
+ - .gitignore
27
+ - LICENSE
28
+ - Rakefile
29
+ - VERSION
30
+ - beans_rails.gemspec
31
+ - beans_rails.rb
32
+ - bin/beans_rails
33
+ - templates/.gitignore
34
+ - templates/Capfile
35
+ - templates/Gemfile
36
+ - templates/config/database.yml
37
+ - templates/config/deploy.rb
38
+ - templates/deploy/beans_server.rb
39
+ - templates/deploy/config/staging.yml
40
+ - templates/deploy/production.rb
41
+ - templates/deploy/staging.rb
42
+ - templates/deploy/templates/database.erb
43
+ - templates/deploy/templates/public_keys.txt
44
+ - templates/deploy/templates/staging_vhost.erb
45
+ has_rdoc: true
46
+ homepage: http://github.com/80beans/beans_rails
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: the 80beans rails project template (and generator)
73
+ test_files: []
74
+