Skip to content

Commit 1b5afdd

Browse files
committed
Added capistrano support
Prepare deploy Change deploy user Readded Gemfile.lock for capistrano Fixed for capistrano Add assets:precompile to deploy Fix path for assets:precompile fix kill_webrick_server Enhance deployment recipes Do rake assets:precompile in background Fix restart webrick roles Fix restart change location of pidfiles to /var/run.. add recipe for webrick to deploy.rb catch exception if pidfile doesn't exist Oh, we need production mode on server ;-) No need to restart proxy on normal deploy use shared/pids fix assets:precompile-path found Uncomment if you are using Rails' asset pipeline in Capfile ;-) found Uncomment if you are using Rails' asset pipeline in Capfile ;-) Prevent apache from restarting Fix pipline issue anoying :/ f.ck pid-path Beautify 503 ready to merge back to master it sucks Capified! set default rake task
1 parent 388ad75 commit 1b5afdd

19 files changed

+429
-35
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
# IMPORTANT! Never push this files to a public repo!
1414

15+
/config/mongoid.yml
16+
/config/settings.yml
1517
/config/settings/development.yml
1618
/config/settings/production.yml
1719
/config/settings.local.yml
@@ -85,4 +87,3 @@ wat.sublime-workspace
8587
README.html
8688

8789
public/assets/*
88-
Gemfile.lock

Capfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
load 'deploy'
2+
load 'deploy/assets'
3+
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
4+
load 'config/deploy'

DEPLOY.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Deploy with Capistrano
2+
======================
3+
4+
> Capistrano was added March 29, 2012 and is not documented yet.
5+
6+
At the moment we have recipes for the following environemt only
7+
8+
* Debian server
9+
* Apache2
10+
* Proxy-Balancer
11+
* App with Webrick
12+
13+
Stay tuned to this file! Recipes will follow soon for
14+
15+
* Phusion Passenger
16+
* Proxy-Balancer with unicorn
17+
* NGINX
18+
19+
20+
21+

Gemfile

+23-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,34 @@ gem "email_spec", ">= 1.2.1", :group => :test
2121
gem "guard", ">= 0.6.2", :group => :development
2222
case HOST_OS
2323
when /darwin/i
24+
# Original for app-template
25+
# gem 'rb-fsevent', :group => :development
26+
# gem 'growl', :group => :development
27+
# gem 'ruby_gntp', :group => :development
28+
29+
# changed for capistrano
2430
gem 'rb-fsevent', :group => :development
2531
gem 'growl', :group => :development
2632
gem 'ruby_gntp', :group => :development
33+
#gem 'libnotify', :group => :development
34+
#gem 'rb-inotify', :group => :development
35+
gem 'therubyracer', :group => :assets
36+
2737

2838
when /linux/i
29-
gem 'libnotify', :group => :development
30-
gem 'rb-inotify', :group => :development
39+
# Original for app-template
40+
# gem 'libnotify', :group => :development
41+
# gem 'rb-inotify', :group => :development
42+
# gem 'therubyracer', :group => :assets
43+
44+
# changed for capistrano
45+
gem 'rb-fsevent', :group => :development
46+
gem 'growl', :group => :development
47+
gem 'ruby_gntp', :group => :development
48+
#gem 'libnotify', :group => :development
49+
#gem 'rb-inotify', :group => :development
3150
gem 'therubyracer', :group => :assets
51+
3252
when /mswin|windows/i
3353
gem 'rb-fchange', :group => :development
3454
gem 'win32console', :group => :development
@@ -65,6 +85,7 @@ gem 'albino'
6585
gem 'nokogiri'
6686
gem 'simple_form'
6787
gem 'rails_config'
88+
gem 'capistrano'
6889

6990
# Authentication
7091
gem "omniauth", ">= 1.0.2"

Gemfile.lock

+19
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ GEM
3838
bson_ext (1.6.1)
3939
bson (~> 1.6.1)
4040
builder (3.0.0)
41+
capistrano (2.11.2)
42+
highline
43+
net-scp (>= 1.0.0)
44+
net-sftp (>= 2.0.0)
45+
net-ssh (>= 2.0.14)
46+
net-ssh-gateway (>= 1.1.0)
4147
capybara (1.1.2)
4248
mime-types (>= 1.16)
4349
nokogiri (>= 1.3.3)
@@ -104,6 +110,7 @@ GEM
104110
haml (~> 3.0)
105111
railties (~> 3.0)
106112
hashie (1.2.0)
113+
highline (1.6.11)
107114
hike (1.2.1)
108115
i18n (0.6.0)
109116
journey (1.0.3)
@@ -113,6 +120,7 @@ GEM
113120
json (1.6.5)
114121
launchy (2.1.0)
115122
addressable (~> 2.2.6)
123+
libv8 (3.3.10.4)
116124
mail (2.4.4)
117125
i18n (>= 0.4.0)
118126
mime-types (~> 1.16)
@@ -129,6 +137,13 @@ GEM
129137
rspec (~> 2)
130138
multi_json (1.1.0)
131139
multipart-post (1.1.5)
140+
net-scp (1.0.4)
141+
net-ssh (>= 1.99.1)
142+
net-sftp (2.0.5)
143+
net-ssh (>= 2.0.9)
144+
net-ssh (2.3.0)
145+
net-ssh-gateway (1.1.0)
146+
net-ssh (>= 1.99.1)
132147
nokogiri (1.5.2)
133148
oauth (0.4.5)
134149
oauth2 (0.5.2)
@@ -239,6 +254,8 @@ GEM
239254
rack (~> 1.0)
240255
tilt (~> 1.1, != 1.3.0)
241256
syntax (1.0.0)
257+
therubyracer (0.10.0)
258+
libv8 (~> 3.3.10)
242259
thor (0.14.6)
243260
tilt (1.3.3)
244261
treetop (1.4.10)
@@ -260,6 +277,7 @@ DEPENDENCIES
260277
bcrypt-ruby (~> 3.0.0)
261278
bootstrap-sass (~> 2.0.1)
262279
bson_ext (>= 1.5.2)
280+
capistrano
263281
capybara
264282
capybara-webkit
265283
coffee-rails (~> 3.2.1)
@@ -302,5 +320,6 @@ DEPENDENCIES
302320
simple_form
303321
spork
304322
syntax
323+
therubyracer
305324
uglifier (>= 1.0.3)
306325
yard

MODELS.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Models
3+
======
4+
5+
The 'Facility-Idea'
6+
-------------------
7+
8+
A facility has a name (like 'Admin', 'Author') and an access-mask like in the unix-filesystem (rwx)
9+
Facilities are embedded to the user and helper-functions like _can_execute?('Admin')_ will return true or false if the user has this facility.
10+
11+
Next step will be: Models like 'Page' will embed Facilities too in order to support code like this:
12+
13+
```ruby
14+
@page.facilities.create(name: 'user one', access: 'rw-')
15+
if current_user.can_write_on?(@page)
16+
...
17+
end
18+
```
19+
20+
Model Page
21+
----------
22+
23+
* A page has a _parmalink_ which is used as a key -> http://..../permalink
24+
* Title and body can be translated using mongoID `:localize => true`
25+
* Use permalink 'hero' for the "Hero-Page" displayed at the root-path
26+
* Begin permalink with @ will make a page "featured" and displays the page below the hero-page at the root_path.
27+
* Create a page in any language. Save it. Switch language (at the bottom of the screen). Edit the page and translate it.
28+
* Create one page permalinked as 'README' or remove the menu-item from `views/layout/application.haml`

README.md

+11-31
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ Featuring
1212
* Based on Rails 3.2.2
1313
* TTD with RSpec
1414
* Twitter Bootstrap
15+
* Deployment with capistrano
1516

1617
_see:_
1718

1819
* [GitHub/RailsApps](https://github.com/RailsApps/rails3-application-templates)
1920
* [WAT](https://github.com/iboard/wat)
2021

2122

22-
THIS PROJECT IS FOR TESTING PURPOSES ONLY (YET)
23-
YOU MAY USE IT AS A STARTER APP FOR YOUR APPLICATION
24-
BUT DON'T USE IT IN PRODUCTION AS IT IS AT THE MOMENT!
25-
2623
Things done after generating the app from the template
2724
------------------------------------------------------
2825

@@ -41,6 +38,7 @@ Things done after generating the app from the template
4138
* Added: I18n for :en and :de
4239
* Added: Model `Page`
4340
* Added: Confirm registraton mail
41+
* Added: capistrano
4442

4543

4644
Installation
@@ -59,17 +57,23 @@ Installation
5957
Mac OS X (and may be others)
6058
----------------------------
6159

62-
Best you have `brew` installed, 'couse you'll need:
60+
Good to have `brew` installed, 'couse you'll need:
6361

6462
* Qt (for capybara-webkit)
6563
* Mongo
64+
* Gtk (for inotify)
6665
* and other things
6766

6867
```sh
6968
# install with webkit with
7069
rvmsudo gem install capybara-webkit
7170
```
7271

72+
Deployment
73+
==========
74+
75+
see [DEPLOY](deploy.md)
76+
7377

7478
API-Keys
7579
--------
@@ -84,33 +88,9 @@ API-Keys
8488
* [Tumblr](http://www.tumblr.com/oauth/apps)
8589

8690
Models
87-
======
88-
89-
The 'Facility-Idea'
90-
-------------------
91-
92-
A facility has a name (like 'Admin', 'Author') and an access-mask like in the unix-filesystem (rwx)
93-
Facilities are embedded to the user and helper-functions like _can_execute?('Admin')_ will return true or false if the user has this facility.
94-
95-
Next step will be: Models like 'Page' will embed Facilities too in order to support code like this:
96-
97-
```ruby
98-
@page.facilities.create(name: 'user one', access: 'rw-')
99-
if current_user.can_write_on?(@page)
100-
...
101-
end
102-
```
103-
104-
Model Page
105-
----------
106-
107-
* A page has a _parmalink_ which is used as a key -> http://..../permalink
108-
* Title and body can be translated using mongoID `:localize => true`
109-
* Use permalink 'hero' for the "Hero-Page" displayed at the root-path
110-
* Begin permalink with @ will make a page "featured" and displays the page below the hero-page at the root_path.
111-
* Create a page in any language. Save it. Switch language (at the bottom of the screen). Edit the page and translate it.
112-
* Create one page permalinked as 'README' or remove the menu-item from `views/layout/application.haml`
91+
------
11392

93+
See file [MODELS](models.md)
11494

11595
License
11696
=======

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Add your own tasks in files placed in lib/tasks ending in .rake,
33
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
44

5+
task :default => 'tdd:run_all_specs'
56
require File.expand_path('../config/application', __FILE__)
67

78
Wat::Application.load_tasks
9+

TODO.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
TODO
2+
====
3+
4+
* Remove inotify for development and production
5+
* Make sure deploying from MacOSX to Linux works with the
6+
* same Gemfile.lock (Capistrano requirement)
7+
8+
* Write capistrano recipes for Phusion Passenger
9+

config/deploy.rb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require "bundler/capistrano"
2+
3+
# SETUP SECTION =================================================
4+
server "andi.altendorfer.at", :web, :app, primary: true
5+
6+
set :virtual_host, "andi.altendorfer.at"
7+
set :cluster_ports, [3000,3001,3002]
8+
set :bind_ip, "0.0.0.0"
9+
set :application, "andi"
10+
set :user, 'deployer'
11+
set :deploy_to, "/home/#{user}/apps/#{application}"
12+
set :source_repository, "wat"
13+
set :deploy_via, :remote_cache
14+
set :use_sudo, false
15+
16+
set :scm, "git"
17+
set :repository, "[email protected]:iboard/#{source_repository}.git"
18+
set :branch, "capify"
19+
# END SETUP SECTION =============================================
20+
21+
22+
load "config/recipes/base"
23+
24+
# LOAD RECIPES FOR A WEBRICK-SERVER WITH APACHE PROXY-BALANCER
25+
load "config/recipes/virtual_host_proxy_balancer"
26+
load "config/recipes/webrick"
27+
28+
# NOT YET AVAILABLE BUT COMMING SOON
29+
#load "config/recipes/unicorn"
30+
# LOAD RECIPES FOR APACHE AND PHUSION PASSENGER
31+
# disable proxy-balancer-section above when enabling this lines
32+
# load "config/recipes/virtual_host_passenger"
33+
# load "config/recipes/passenger"
34+
35+
36+
default_run_options[:pty] = true
37+
ssh_options[:forward_agent] = true
38+
39+
before "deploy:assets:precompile", "bundle:install"
40+
after "deploy", "deploy:cleanup" # keep 5 versions only
41+

config/mongoid.example.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- encoding : utf-8 -*-
2+
development:
3+
host: localhost
4+
database: wat_development
5+
6+
test:
7+
host: localhost
8+
database: wat_test
9+
10+
# set these environment variables on your prod server
11+
production:
12+
host: localhost
13+
database: wat_development

config/recipes/base.rb

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# @param [String] from - the erb-template to read from
2+
# @param [String] to - where to put the rendered result
3+
def template(from, to)
4+
erb = File.read(File.expand_path("../templates/#{from}",__FILE__))
5+
put ERB.new(erb).result(binding), to
6+
end
7+
8+
9+
namespace :deploy do
10+
11+
desc "Install your server"
12+
task :install do
13+
puts "NO INSTALL RECIPIENT IS DEFINED YET"
14+
puts "SEE #{__FILE__} :deploy:install AND SETUP REQIRED STEPS THERE"
15+
end
16+
17+
desc "Setup the config-files on the server with example-defaults"
18+
task :setup_config, roles: :app do
19+
run "mkdir -p #{shared_path}/config"
20+
put File.read("config/mongoid.example.yml"), "#{shared_path}/config/mongoid.yml"
21+
put File.read("config/test_secrets.yml"), "#{shared_path}/config/secrets.yml"
22+
put File.read("config/settings_sample.yml"), "#{shared_path}/config/settings.yml"
23+
24+
run "mkdir -p #{shared_path}/config/settings"
25+
put File.read("config/settings/production.yml_sample"), "#{shared_path}/config/settings/production.yml"
26+
27+
puts "=============================================================="
28+
puts "EDIT FILES IN #{shared_path} ON YOUR "
29+
puts "SERVER BEFORE deploy:cold"
30+
puts "=============================================================="
31+
end
32+
after "deploy:setup", "deploy:setup_config"
33+
34+
desc "Symlink config-files after update"
35+
task :symlink_config, roles: :app do
36+
run "ln -nfs #{shared_path}/config/mongoid.yml #{release_path}/config/mongoid.yml"
37+
run "ln -nfs #{shared_path}/config/secrets.yml #{release_path}/config/secrets.yml"
38+
run "ln -nfs #{shared_path}/config/settings.yml #{release_path}/config/settings.yml"
39+
run "ln -nfs #{shared_path}/config/settings/production.yml #{release_path}/config/settings/production.yml"
40+
end
41+
after "deploy:finalize_update", "deploy:symlink_config"
42+
43+
[:start, :stop, :restart].each do |t|
44+
desc "#{t} task is a no-op with proxy_balancer"
45+
task t, :roles => :app do ; end
46+
end
47+
48+
end

0 commit comments

Comments
 (0)