capistrano-nginx 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,18 @@
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
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-nginx.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'capistrano', '> 2.0.0'
8
+ gem 'railties', '> 3.2.0'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ivan Tkalin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ # capistrano-nginx
2
+
3
+ This gem provides two capistrano tasks:
4
+
5
+ * `nginx:setup` -- creates /etc/nginx/sites-available/YOUR\_APP and links it to /etc/nginx/sites-enabled/YOUR\_APP
6
+ * `nginx:reload` -- invokes `/etc/init.d/nginx reload` on server
7
+
8
+ And nginx configuration file generator, that will create local copy of default nginx config for customization.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'capistrano-nginx'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install capistrano-nginx
23
+
24
+ ## Usage
25
+
26
+ Add this to your `config/deploy.rb` file:
27
+
28
+ require 'capistrano/nginx/tasks'
29
+
30
+ Make sure, following variables are defined in your `config/deploy.rb`:
31
+
32
+ * `application` - application name
33
+ * `server_name` - your application's server_name in nginx (e.g. `example.com`)
34
+ * `deploy_to` - deployment path
35
+ * `sudo_user` - user name with sudo privileges (needed to config/restart nginx)
36
+
37
+ Launch new tasks:
38
+
39
+ $ cap nginx:setup
40
+ $ cap nginx:reload
41
+
42
+ If you want to customize nginx configuration, just generate local nginx config before running `nginx:setup`:
43
+
44
+ $ rails generate capistrano:nginx:config
45
+
46
+ And then edit file `config/deploy/nginx_conf.erb` as you like.
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ desc 'Default: run unit tests.'
5
+ task :default => :test
6
+
7
+ desc 'Run tests'
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capistrano/nginx/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ivan Tkalin"]
6
+ gem.email = ["itkalin@gmail.com"]
7
+ gem.description = "Simple nginx management with capistrano"
8
+ gem.summary = "Configuration and managements capistrano tasks for nginx"
9
+ gem.homepage = "https://github.com/ivalkeen/capistrano-nginx"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "capistrano-nginx"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Capistrano::Nginx::VERSION
17
+ end
@@ -0,0 +1 @@
1
+ require "capistrano/nginx/version"
@@ -0,0 +1,22 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :nginx do
3
+ desc "Setup application in nginx"
4
+ task "setup", :role => :web do
5
+ config_file = "config/deploy/nginx_conf.erb"
6
+ unless File.exists?(config_file)
7
+ config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/nginx/templates/_nginx_conf.erb")
8
+ end
9
+ config = ERB.new(File.read(config_file)).result(binding)
10
+ set :user, sudo_user
11
+ put config, "/tmp/#{application}"
12
+ run "#{sudo} mv /tmp/#{application} /etc/nginx/sites-available/#{application}"
13
+ run "#{sudo} ln -fs /etc/nginx/sites-available/#{application} /etc/nginx/sites-enabled/#{application}"
14
+ end
15
+
16
+ desc "Reload nginx configuration"
17
+ task :reload, :role => :web do
18
+ set :user, sudo_user
19
+ run "#{sudo} /etc/init.d/nginx reload"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Nginx
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ To create local nginx configuration file call
2
+
3
+ rails generate capistrano:nginx:config
@@ -0,0 +1,14 @@
1
+ module Capistrano
2
+ module Nginx
3
+ module Generators
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ desc "Create local nginx configuration file for customization"
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def copy_template
9
+ copy_file "_nginx_conf.erb", "config/deploy/nginx_conf.erb"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ upstream <%= application %> {
2
+ server <%= "unix:#{deploy_to}/current/tmp/sockets/unicorn.sock fail_timeout=0" %>;
3
+ }
4
+
5
+ server {
6
+ client_max_body_size 4G;
7
+ server_name <%= server_name %>;
8
+ keepalive_timeout 5;
9
+ root <%= "#{deploy_to}/current/public" %>;
10
+ try_files $uri/index.html $uri.html $uri @<%= application %>;
11
+
12
+ location @<%= application %> {
13
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
14
+ proxy_set_header Host $http_host;
15
+ proxy_redirect off;
16
+ proxy_pass http://<%= application %>;
17
+ }
18
+
19
+ if (-f $document_root/system/maintenance.html) {
20
+ return 503;
21
+ }
22
+
23
+ error_page 500 502 504 /500.html;
24
+ location = /500.html {
25
+ root <%= "#{deploy_to}/current/public" %>;
26
+ }
27
+
28
+ error_page 503 @maintenance;
29
+ location @maintenance {
30
+ rewrite ^(.*)$ /system/maintenance.html break;
31
+ }
32
+ }
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/test_case'
3
+ require 'generators/capistrano/nginx/config_generator'
4
+
5
+ class GeneratorTest < Rails::Generators::TestCase
6
+ tests Capistrano::Nginx::Generators::ConfigGenerator
7
+ destination File.expand_path('../../tmp', __FILE__)
8
+ setup :prepare_destination
9
+ teardown { rm_rf(destination_root) }
10
+
11
+ def test_generates_local_config_file
12
+ run_generator
13
+ assert_file 'config/deploy/nginx_conf.erb'
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ require 'capistrano'
4
+
5
+ class TasksTest < Test::Unit::TestCase
6
+ def setup
7
+ @config = Capistrano::Configuration.new
8
+ Capistrano::Configuration.instance = @config
9
+ task = @config.find_task("nginx:setup")
10
+ load 'capistrano/nginx/tasks.rb'
11
+ end
12
+
13
+ def test_add_setup_task
14
+ namespace = @config.namespaces[:nginx]
15
+ assert_not_nil namespace
16
+ setup_task = namespace.tasks[:setup]
17
+ assert_not_nil setup_task
18
+ end
19
+
20
+ def test_add_reload_task
21
+ namespace = @config.namespaces[:nginx]
22
+ assert_not_nil namespace
23
+ setup_task = namespace.tasks[:reload]
24
+ assert_not_nil setup_task
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'test/unit'
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-nginx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ivan Tkalin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Simple nginx management with capistrano
15
+ email:
16
+ - itkalin@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.markdown
25
+ - Rakefile
26
+ - capistrano-nginx.gemspec
27
+ - lib/capistrano-nginx.rb
28
+ - lib/capistrano/nginx/tasks.rb
29
+ - lib/capistrano/nginx/version.rb
30
+ - lib/generators/capistrano/nginx/USAGE
31
+ - lib/generators/capistrano/nginx/config_generator.rb
32
+ - lib/generators/capistrano/nginx/templates/_nginx_conf.erb
33
+ - test/generator_test.rb
34
+ - test/tasks_test.rb
35
+ - test/test_helper.rb
36
+ homepage: https://github.com/ivalkeen/capistrano-nginx
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ segments:
49
+ - 0
50
+ hash: 327813363107567374
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ segments:
58
+ - 0
59
+ hash: 327813363107567374
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.17
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Configuration and managements capistrano tasks for nginx
66
+ test_files:
67
+ - test/generator_test.rb
68
+ - test/tasks_test.rb
69
+ - test/test_helper.rb