capistrano-o2web-recipes 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1d33e1f3422222b0cee3e5beababaa445d28f4d
4
+ data.tar.gz: 93f1c650d723e332610c2376e337812b2f4fe515
5
+ SHA512:
6
+ metadata.gz: 9685fb12a6de1856b937b48ba0634ccbf2e6afd0fff1cbaa3a549823bab29834809a4ec55f4c4faeade9409474c374c34e5497870592c6efe59dcce4a7e12aec
7
+ data.tar.gz: 8f64fd4d03386f8eb4735e4f48b88a0f7199e14fdea9fe195da4c93b583d09c0f7f068daacec0f6031bc9bf7471533596530497745282f9c1eed4af3c7292104
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /vendor/ruby
19
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in *.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Patrice Lebel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # Capistrano::O2webRecipes
2
+
3
+ Common Capistrano Recipes used by O2Web.
4
+
5
+ Works *only* with Capistrano 3+.
6
+
7
+ ### Installation
8
+
9
+ Add this to `Gemfile`:
10
+
11
+ group :development do
12
+ gem 'capistrano', '~> 3.1'
13
+ gem 'capistrano-rails', '~> 1.1'
14
+ gem 'capistrano-o2web-recipes', '~> 0.0.1'
15
+ end
16
+
17
+ And then:
18
+
19
+ $ bundle install
20
+
21
+ ### Setup and usage
22
+
23
+ Add this line to `Capfile`, after `require 'capistrano/rails/assets'`
24
+
25
+ require 'capistrano/o2web_recipes'
26
+
27
+ To install Nginx config files, run:
28
+
29
+ $ rails g capistrano:o2web_recipes:install
30
+
31
+ Available tasks:
32
+
33
+ ```bash
34
+ cap [stage] git:update_repo_url # Update new git repo url
35
+ cap [stage] tmp_cache:clear # Clear file system tmp cache
36
+ cap [stage] files:server_to_local # Import public files
37
+ cap [stage] files:local_to_server # Export public files
38
+ cap [stage] files:private:server_to_local # Import private file
39
+ cap [stage] files:private:local_to_server # Export private files
40
+ cap [stage] db:server_to_local # Sync local DB with server DB
41
+ cap [stage] db:local_to_server # Sync server DB with local DB
42
+ cap [stage] nginx:local_to_server # Export nginx configuration files
43
+ ```
44
+
45
+ Also, tasks from 'capistrano3-nginx' are available.
46
+
47
+ Configurations can be customized in your deploy file with:
48
+
49
+ ```ruby
50
+ set :server, 'example.com'
51
+ set :admin_name, 'admin'
52
+ set :deployer_name, 'deployer'
53
+ set :files_public_dirs, fetch(:files_public_dirs, []).push(*%W[
54
+ system
55
+ ])
56
+ set :files_private_dirs, fetch(:files_private_dirs, []).push(*%W[
57
+ ])
58
+ set :nginx_workers, 1
59
+ set :nginx_assets_dirs, fetch(:nginx_assets_dirs, []).push(*%W[
60
+ assets
61
+ system
62
+ ])
63
+ set :nginx_max_body_size, '10m'
64
+ ```
65
+
66
+ ### TODO
67
+
68
+ 1. Use stages (staging/production) to scope Nginx config file to allow multiple stages on the same server.
69
+ 1. Lose the dependency to capistrano3-nginx gem.
70
+ 1. Log rotate
71
+ 1. Monit
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/o2web_recipes/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "capistrano-o2web-recipes"
8
+ gem.version = Capistrano::O2webRecipes::VERSION
9
+ gem.authors = ["Patrice Lebel"]
10
+ gem.email = ["patrice@lebel.com"]
11
+ gem.description = "Common Capistrano Recipes used by O2Web."
12
+ gem.summary = "Common Capistrano Recipes used by O2Web."
13
+ gem.homepage = "https://github.com/o2web/capistrano-o2web-recipes"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "capistrano", ">= 3.1"
21
+ gem.add_dependency "capistrano3-nginx", "~> 2.0"
22
+ gem.add_dependency "yaml_db"
23
+ gem.add_development_dependency "rake"
24
+ end
File without changes
@@ -0,0 +1 @@
1
+ load File.expand_path("../tasks/o2web_recipes.rake", __FILE__)
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module O2webRecipes
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,133 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :files_public_dirs, ['system']
4
+ set :files_private_dirs, []
5
+
6
+ set :nginx_workers, 1
7
+ set :nginx_assets_dirs, %w[assets system]
8
+ set :nginx_max_body_size, '10m'
9
+ end
10
+ end
11
+
12
+ namespace :git do
13
+ desc 'Update new git repo url'
14
+ task :update_repo_url do
15
+ on roles :app do
16
+ within repo_path do
17
+ execute :git, 'remote', 'set-url', 'origin', fetch(:repo_url)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ namespace :tmp_cache do
24
+ desc 'Clear file system tmp cache'
25
+ task :clear do
26
+ on roles :app do
27
+ within current_path do
28
+ with rails_env: fetch(:stage) do
29
+ execute :rake, 'tmp:cache:clear'
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ namespace :files do
37
+ def send_files(type, server, root = 'public')
38
+ raise "No server given" if !server
39
+ system "rsync --progress -rue 'ssh -p #{fetch(:port)}' #{root}/#{type} #{server.user}@#{server.hostname}:#{shared_path}/#{root}/"
40
+ end
41
+
42
+ def get_files(type, server, root = 'public')
43
+ raise "No server given" if !server
44
+ puts "Importing #{type}. Please wait..."
45
+ system "rsync --progress -rue 'ssh -p #{fetch(:port)}' #{server.user}@#{server.hostname}:#{shared_path}/#{root}/#{type} ./#{root}/"
46
+ end
47
+
48
+ desc 'Import public files'
49
+ task :server_to_local do
50
+ on roles :app do |host|
51
+ fetch(:files_public_dirs).each do |type|
52
+ get_files type, host
53
+ end
54
+ end
55
+ end
56
+
57
+ desc 'Export public files'
58
+ task :local_to_server do
59
+ on roles :app do |host|
60
+ fetch(:files_public_dirs).each do |type|
61
+ send_files type, host
62
+ end
63
+ end
64
+ end
65
+
66
+ namespace :private do
67
+ desc 'Import private files'
68
+ task :server_to_local do
69
+ on roles :app do |host|
70
+ fetch(:files_private_dirs).each do |type|
71
+ get_files type, host, 'private'
72
+ end
73
+ end
74
+ end
75
+
76
+ desc 'Export private files'
77
+ task :local_to_server do
78
+ on roles :app do |host|
79
+ fetch(:files_private_dirs).each do |type|
80
+ send_files type, host, 'private'
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ namespace :db do
88
+ desc "Sync local DB with server DB"
89
+ task :server_to_local do
90
+ on roles(:app) do |role|
91
+ within current_path do
92
+ with rails_env: fetch(:stage) do
93
+ execute :rake, 'db:data:dump'
94
+ end
95
+ run_locally do
96
+ execute :rsync, "-avzO -e 'ssh -p #{fetch(:port)}' --exclude='.DS_Store' #{role.user}@#{role.hostname}:#{current_path}/db/data.yml db/data.yml"
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ desc "Sync server DB with local DB"
103
+ task :local_to_server do
104
+ on roles(:app) do |role|
105
+ run_locally do
106
+ execute :rsync, "-avzO -e 'ssh -p #{fetch(:port)}' --exclude='.DS_Store' db/data.yml #{role.user}@#{role.hostname}:#{current_path}/db/data.yml"
107
+ end
108
+ within current_path do
109
+ with rails_env: fetch(:stage) do
110
+ execute :rake, 'db:data:load'
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ namespace :nginx do
118
+ def upload(server, source, destination)
119
+ File.open(source, 'w') do |f|
120
+ f.puts ERB.new(File.read("#{source}.erb")).result
121
+ end
122
+ system "rsync --rsync-path='sudo rsync' -avzO -e 'ssh -p #{fetch(:port)}' '#{source}' #{fetch(:admin_name)}@#{server.hostname}:#{destination}"
123
+ FileUtils.rm_f source
124
+ end
125
+
126
+ desc 'Export nginx configuration files'
127
+ task :local_to_server do
128
+ on roles :app do |host|
129
+ upload host, 'config/nginx.conf', '/etc/nginx/nginx.conf'
130
+ upload host, 'config/nginx.app.conf', '/etc/nginx/sites-available/default'
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,13 @@
1
+ module Capistrano
2
+ module O2webRecipes
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc "Install Nginx config files (templates)"
7
+
8
+ def copy_files
9
+ directory 'config'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,80 @@
1
+ ##
2
+ # You should look at the following URL's in order to grasp a solid understanding
3
+ # of Nginx configuration files in order to fully unleash the power of Nginx.
4
+ # http://wiki.nginx.org/Pitfalls
5
+ # http://wiki.nginx.org/QuickStart
6
+ # http://wiki.nginx.org/Configuration
7
+ #
8
+ # Generally, you will want to move this file somewhere, and start with a clean
9
+ # file but keep this around for reference. Or just disable in sites-enabled.
10
+ #
11
+ # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
12
+ ##
13
+
14
+ # Default server configuration
15
+ #
16
+ server {
17
+ listen 80 default_server;
18
+ listen [::]:80 default_server ipv6only=on;
19
+
20
+ # SSL configuration
21
+ #
22
+ # listen 443 ssl default_server;
23
+ # listen [::]:443 ssl default_server;
24
+ #
25
+ # Self signed certs generated by the ssl-cert package
26
+ # Don't use them in a production server!
27
+ #
28
+ # include snippets/snakeoil.conf;
29
+
30
+ server_name <%= fetch(:server) %>;
31
+ passenger_enabled on;
32
+ rails_env <%= fetch(:stage) %>;
33
+ root <%= fetch(:deploy_to) %>/current/public;
34
+
35
+ <% if fetch(:stage) == :production -%>
36
+ # listen 443 ssl;
37
+ # ssl_certificate /etc/ssl/certs/<%= fetch(:server) %>.chained.crt;
38
+ # ssl_certificate_key /etc/ssl/private/<%= fetch(:server) %>.key;
39
+ <% end -%>
40
+
41
+ client_max_body_size <%= fetch(:nginx_max_body_size) %>;
42
+
43
+ error_page 500 502 503 504 /50x.html;
44
+ location = /50x.html {
45
+ root html;
46
+ }
47
+
48
+ location ~ ^/(<%= fetch(:nginx_assets_dirs).join('|') %>)/ {
49
+ gzip_static on;
50
+ expires max;
51
+ add_header Cache-Control public;
52
+ break;
53
+ }
54
+ }
55
+
56
+ server {
57
+ listen 80;
58
+
59
+ server_name www.<%= fetch(:server) %>;
60
+ return 301 $scheme://<%= fetch(:server) %>$request_uri;
61
+ }
62
+
63
+ # Virtual Host configuration for example.com
64
+ #
65
+ # You can move that to a different file under sites-available/ and symlink that
66
+ # to sites-enabled/ to enable it.
67
+ #
68
+ #server {
69
+ # listen 80;
70
+ # listen [::]:80;
71
+ #
72
+ # server_name example.com;
73
+ #
74
+ # root /var/www/example.com;
75
+ # index index.html;
76
+ #
77
+ # location / {
78
+ # try_files $uri $uri/ =404;
79
+ # }
80
+ #}
@@ -0,0 +1,102 @@
1
+ user <%= fetch(:deployer_name) %>;
2
+ worker_processes <%= fetch(:nginx_workers) %>;
3
+ pid /run/nginx.pid;
4
+
5
+ events {
6
+ worker_connections 768;
7
+ # multi_accept on;
8
+ }
9
+
10
+ http {
11
+
12
+ ##
13
+ # Basic Settings
14
+ ##
15
+
16
+ sendfile on;
17
+ tcp_nopush on;
18
+ tcp_nodelay on;
19
+ keepalive_timeout 65;
20
+ types_hash_max_size 2048;
21
+ # server_tokens off;
22
+
23
+ # server_names_hash_bucket_size 64;
24
+ # server_name_in_redirect off;
25
+
26
+ include /etc/nginx/mime.types;
27
+ default_type application/octet-stream;
28
+
29
+ ##
30
+ # SSL Settings
31
+ ##
32
+
33
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
34
+ ssl_prefer_server_ciphers on;
35
+
36
+ ##
37
+ # Logging Settings
38
+ ##
39
+
40
+ access_log /var/log/nginx/access.log;
41
+ error_log /var/log/nginx/error.log;
42
+
43
+ ##
44
+ # Gzip Settings
45
+ ##
46
+
47
+ gzip on;
48
+ gzip_disable "msie6";
49
+
50
+ gzip_vary on;
51
+ gzip_proxied any;
52
+ gzip_comp_level 6;
53
+ gzip_buffers 16 8k;
54
+ gzip_http_version 1.1;
55
+ gzip_types
56
+ text/plain
57
+ text/css
58
+ text/xml
59
+ text/javascript
60
+ application/json
61
+ application/javascript
62
+ application/xml
63
+ application/xml+rss;
64
+
65
+ ##
66
+ # Phusion Passenger config
67
+ ##
68
+ # Uncomment it if you installed passenger or passenger-enterprise
69
+ ##
70
+
71
+ passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
72
+ passenger_ruby /home/<%= fetch(:deployer_name) %>/.rbenv/shims/ruby;
73
+
74
+ ##
75
+ # Virtual Host Configs
76
+ ##
77
+
78
+ include /etc/nginx/conf.d/*.conf;
79
+ include /etc/nginx/sites-enabled/*;
80
+ }
81
+
82
+
83
+ #mail {
84
+ # # See sample authentication script at:
85
+ # # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
86
+ #
87
+ # # auth_http localhost/auth.php;
88
+ # # pop3_capabilities "TOP" "USER";
89
+ # # imap_capabilities "IMAP4rev1" "UIDPLUS";
90
+ #
91
+ # server {
92
+ # listen localhost:110;
93
+ # protocol pop3;
94
+ # proxy on;
95
+ # }
96
+ #
97
+ # server {
98
+ # listen localhost:143;
99
+ # protocol imap;
100
+ # proxy on;
101
+ # }
102
+ #}
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-o2web-recipes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patrice Lebel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano3-nginx
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yaml_db
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Common Capistrano Recipes used by O2Web.
70
+ email:
71
+ - patrice@lebel.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.md
79
+ - README.md
80
+ - Rakefile
81
+ - capistrano-o2web-recipes.gemspec
82
+ - lib/capistrano-o2web-assets.rb
83
+ - lib/capistrano/o2web_recipes.rb
84
+ - lib/capistrano/o2web_recipes/version.rb
85
+ - lib/capistrano/tasks/o2web_recipes.rake
86
+ - lib/generators/capistrano/o2web_recipes/install/USAGE.md
87
+ - lib/generators/capistrano/o2web_recipes/install/install_generator.rb
88
+ - lib/generators/capistrano/o2web_recipes/install/templates/config/nginx.app.conf.erb
89
+ - lib/generators/capistrano/o2web_recipes/install/templates/config/nginx.conf.erb
90
+ homepage: https://github.com/o2web/capistrano-o2web-recipes
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.5
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Common Capistrano Recipes used by O2Web.
113
+ test_files: []
114
+ has_rdoc: