capistrano_rails_recipes 0.1.22 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +82 -7
- data/lib/capistrano_rails_recipes/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d54893e78d434d2f87d88feba28111e57b238cc9
|
4
|
+
data.tar.gz: 83e61b16c862acd66051fc896f3da26cb2362831
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e542e51886d21d212af19b102f1de08b76be0db788d622499e8b7351f4616192adb082a93b9c828d06381fa82577e6c7ed4ff962d54e7cead5ca3cb058c4e14a
|
7
|
+
data.tar.gz: 096c4c626d574b6903305327c107305b804d2195e407027862846f586e999fa6a561a2549ab1f235c794704664ec902fd3130f995248319f4e7a958d3d015b46
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Capistrano recipes for Rails
|
2
2
|
|
3
3
|
We deploy a lot of Rails applications and our developers have to solve similar problems each time during the deployment: how to run workers, how to generate crontab, how to precompile assets faster and so on. This collection of recipes helps us to solve them.
|
4
4
|
|
@@ -6,20 +6,29 @@ Recipe use:
|
|
6
6
|
|
7
7
|
* [`foreman`][foreman] + [`foreman_export_runitu`][runitu] to generate runit scripts with the Procfile
|
8
8
|
* [`whenever`][whenever] to generate crontab
|
9
|
-
* [`
|
9
|
+
* [`nginx`][nginx] as proxy server
|
10
10
|
|
11
|
-
It also consider that you use *
|
11
|
+
It also consider that you use *rbenv* on the server.
|
12
12
|
|
13
13
|
##Installation
|
14
14
|
|
15
|
-
gem '
|
15
|
+
gem 'capistrano_rails_recipes', :require => false
|
16
16
|
|
17
17
|
Capfile example:
|
18
18
|
|
19
|
-
require "
|
19
|
+
require "capistrano_rails_recipes/capistrano"
|
20
20
|
|
21
21
|
set :repository, "git@github.com:..."
|
22
|
-
set :application, "
|
22
|
+
set :application, "my_application"
|
23
|
+
set :user, 'deploy'
|
24
|
+
set :branch, 'master'
|
25
|
+
set :deploy_to, "/path/to/app"
|
26
|
+
set :use_sudo, false
|
27
|
+
|
28
|
+
server 'web.example.com', :web, :app, :worker, :crontab
|
29
|
+
role :db, 'web.example.com', primary: true
|
30
|
+
|
31
|
+
OR
|
23
32
|
|
24
33
|
task :production do
|
25
34
|
role :web, "web.example.com"
|
@@ -35,6 +44,14 @@ Capfile example:
|
|
35
44
|
|
36
45
|
As you can see, we use use roles to bind the tasks, and there are some additions to roles and additional roles:
|
37
46
|
|
47
|
+
**deploy:setup** creates all necessary folders and symlinks to files:
|
48
|
+
config/nginx.conf -> /opt/nginx/conf/sites-enabled/my_application
|
49
|
+
creates deploy_to/shared/config folder
|
50
|
+
creates deploy_to/services folder
|
51
|
+
copies config/database.example.yml -> shared/config/database.yml
|
52
|
+
|
53
|
+
Run **deploy:setup** before your first deploy. See below how to configure services.
|
54
|
+
|
38
55
|
**web** compiles assets if content of `app/assets` was changed since last deploy (add FORCE=1 to force the assets compilation)
|
39
56
|
|
40
57
|
**app** all files from `shared/config` is being symlinked to `current/config` like:
|
@@ -48,7 +65,7 @@ As you can see, we use use roles to bind the tasks, and there are some additions
|
|
48
65
|
|
49
66
|
**worker** Procfile exports runit configs to `deploy_to/application/services`
|
50
67
|
|
51
|
-
On **deploy:restart**
|
68
|
+
On **deploy:restart** runit workers is being restarted.
|
52
69
|
|
53
70
|
You can use some extra `cap` tasks:
|
54
71
|
|
@@ -60,6 +77,63 @@ You can use some extra `cap` tasks:
|
|
60
77
|
|
61
78
|
To run succesfully together with system wide rbenv, all you tasks in Procfile must be started with `rbenv exec`
|
62
79
|
|
80
|
+
##Configuring services
|
81
|
+
|
82
|
+
To run services just create Procfile in root of your app.
|
83
|
+
|
84
|
+
Procfile example:
|
85
|
+
|
86
|
+
sidekiq: rbenv exec bundle exec sidekiq -L sidekiq.log
|
87
|
+
web: rbenv exec bundle exec unicorn -c config/unicorn.rb -E production
|
88
|
+
|
89
|
+
Also you need to configure runit to monitor deploy_to/services folder.
|
90
|
+
|
91
|
+
##Nginx config file example for Unicorn
|
92
|
+
|
93
|
+
upstream unicorn_my_application {
|
94
|
+
server unix:/tmp/unicorn.my_application.sock fail_timeout=0;
|
95
|
+
}
|
96
|
+
|
97
|
+
server {
|
98
|
+
listen 80;
|
99
|
+
server_name web.example.com;
|
100
|
+
root deploy_to/current/public;
|
101
|
+
|
102
|
+
location ^~ /assets/ {
|
103
|
+
gzip_static on;
|
104
|
+
expires max;
|
105
|
+
add_header Cache-Control public;
|
106
|
+
}
|
107
|
+
|
108
|
+
try_files $uri/index.html $uri @unicorn;
|
109
|
+
location @unicorn {
|
110
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
111
|
+
proxy_set_header Host $http_host;
|
112
|
+
proxy_redirect off;
|
113
|
+
proxy_pass http://unicorn_my_application;
|
114
|
+
}
|
115
|
+
|
116
|
+
error_page 500 502 503 504 /500.html;
|
117
|
+
client_max_body_size 4G;
|
118
|
+
keepalive_timeout 10;
|
119
|
+
}
|
120
|
+
|
121
|
+
Change **deploy_to** and **my_application** to your actual values.
|
122
|
+
|
123
|
+
##Unicorn config file example
|
124
|
+
|
125
|
+
root = "deploy_to/current"
|
126
|
+
working_directory root
|
127
|
+
pid "#{root}/tmp/pids/unicorn.pid"
|
128
|
+
stderr_path "#{root}/log/unicorn.log"
|
129
|
+
stdout_path "#{root}/log/unicorn.log"
|
130
|
+
|
131
|
+
listen "/tmp/unicorn.my_application.sock"
|
132
|
+
worker_processes 5
|
133
|
+
timeout 30
|
134
|
+
|
135
|
+
Change **deploy_to** and **my_application** to your actual values.
|
136
|
+
|
63
137
|
##Capistrano
|
64
138
|
|
65
139
|
Default variables:
|
@@ -90,3 +164,4 @@ To enable silent mode, add `ENV['CAP_SILENT_MODE']` before the `require 'capistr
|
|
90
164
|
[runitu]: https://github.com/evrone/foreman_export_runitu
|
91
165
|
[whenever]: https://github.com/javan/whenever
|
92
166
|
[unicorn]: http://unicorn.bogomips.org/
|
167
|
+
[nginx]: http://nginx.org/
|