mina-nginx 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fc9f55e13f8c93e65915450dba5af5b713a835f
4
- data.tar.gz: 3ceb413fd582ed68e31e3d50854f2a14f3ae6f5b
3
+ metadata.gz: ea131bbcb4d8565d2bfee03d1bab5b2b17a5c4c8
4
+ data.tar.gz: 5be0493451234e99ddee778988a994bbb4e27681
5
5
  SHA512:
6
- metadata.gz: 925707213e89e846e632c363ec2572cf53e25f2604019324a7de1a83499275fb1e5a5428edf7d8767bcd8d92c5094b91f2516b05ef87f210b906eb428f76f889
7
- data.tar.gz: 0405cf368b7f6ade3a12667a6d0655b6d408585c7594dedc1814d93ac6fa9868dd51249a122fb5d6758fae864ecfb944b68672ee7791c301a49c3c5bb60025ba
6
+ metadata.gz: d971e6222af56fd0e74f3af63e737b7280fde61e968c8d9f16670d5780d991a36c0905e453fd243707819a488293a9a654833add9e0d186abdc17ec406fb9b69
7
+ data.tar.gz: f778b49a2f19603cf6d73f8b7aca9fd625a480f8e85f5ffba885e2c57d860443005dcaa814ed513020fbc4e8ab1f3d2f998e562e0ef8756f155203f6024c7631
data/README.md CHANGED
@@ -5,55 +5,49 @@
5
5
 
6
6
  This gem provides several mina tasks:
7
7
 
8
- mina nginx:link # Symlinking nginx config file
9
- mina nginx:parse # Parse nginx configuration file and upload it to the server
8
+ mina nginx:install # Install template config to host repo for easy overrides
9
+ mina nginx:setup # Install config file to the server's shared dir + symlink
10
+ mina nginx:print # Parse & print the nginx config
11
+
10
12
  mina nginx:reload # Reload Nginx
11
13
  mina nginx:restart # Restart Nginx
12
- mina nginx:setup # Setup Nginx
13
14
  mina nginx:start # Start Nginx
14
15
  mina nginx:status # Status Nginx
15
16
  mina nginx:stop # Stop Nginx
16
17
 
17
18
  ## Installation
18
19
 
19
- Add this line to your application's Gemfile:
20
+ Add this line to your application's Gemfile, then `bundle install`:
20
21
 
21
22
  gem 'mina-nginx', :require => false
22
23
 
23
- And then execute:
24
-
25
- $ bundle
26
-
27
- Or install it yourself as:
28
-
29
- $ gem install mina-nginx
30
-
31
- ## Usage
32
-
33
- Add this to your `config/deploy.rb` file:
24
+ Once installed, add this to your `config/deploy.rb` file:
34
25
 
35
26
  require 'mina/nginx'
36
27
 
37
- Make sure the following settings are set in your `config/deploy.rb`:
28
+ Install the base template to your repo's `lib/mina/templates` directory:
29
+
30
+ $ bundle exec mina nginx:install
38
31
 
39
- * `application` - application name
40
- * `server_name` - your application's server_name in nginx (e.g. example.com)(optional)
41
- * `deploy_to` - deployment path
32
+ Consider variables used by the nginx config, particularly:
42
33
 
43
- Launch new tasks:
34
+ * `application` - application name; defaults to 'application'
35
+ * `nginx_socket_path` - path to socket file used in nginx upstream directive
36
+ * `server_name` - application's nginx server_name (e.g. example.com); defaults to value for `domain`
37
+ * `domain` - fqdn you are deploying to
38
+ * `deploy_to` - deployment path
39
+ * `current_path` - current revision path
44
40
 
45
- ```
46
- $ mina nginx:setup
47
- $ mina nginx:link
48
- ```
41
+ Edit installed template as required.
49
42
 
50
- You can parse an sample configuration file by `mina nginx:parse` on your server.
43
+ ## Recommended Usage
51
44
 
52
- Be sure to edit `shared/config/nginx.conf`, and then:
45
+ 1. Follow install steps above; and
46
+ 2. Invoke `nginx:setup` in your main `setup` task
47
+ 3. Run `nginx:setup` (or base `setup`) to install config changes
53
48
 
54
- ```
55
- $ mina nginx:reload
56
- ```
49
+ n.b. if the config template has not been installed locally, `mina-nginx` will
50
+ fall back to the default template gracefully.
57
51
 
58
52
  ## Contributing
59
53
 
@@ -1,31 +1,48 @@
1
1
  require 'mina/nginx/version'
2
2
 
3
3
  namespace :nginx do
4
- set :nginx_user, 'www-data'
5
- set :nginx_group, 'www-data'
6
- set :nginx_path, '/etc/nginx'
7
- set :nginx_config, -> { "#{fetch(:shared_path)}/config/nginx.conf" }
8
- set :nginx_config_e, -> { "#{fetch(:nginx_path)}/sites-enabled/#{application}.conf" }
4
+ application = fetch :application, 'application'
9
5
 
10
- desc 'Setup Nginx'
11
- task :setup => :environment do
12
- command %(Setup the nginx)
13
- command %(touch #{fetch(:nginx_config)})
14
- comment %(Be sure to edit 'shared/config/nginx.conf'.)
6
+ set :nginx_user, 'www-data'
7
+ set :nginx_group, 'www-data'
8
+ set :nginx_path, '/etc/nginx'
9
+ set :nginx_config, -> { "#{fetch(:shared_path)}/config/nginx.conf" }
10
+ set :nginx_config_e, -> { "#{fetch(:nginx_path)}/sites-enabled/#{application}.conf" }
11
+ set :nginx_socket_path, -> { "#{fetch(:shared_path)}/tmp/puma.sock" }
12
+
13
+ desc 'Install Nginx config to repo'
14
+ task :install => :environment do
15
+ run :local do
16
+ installed_path = path_for_template
17
+
18
+ if File.exist? installed_path
19
+ error! %(file exists; please rm to continue: #{installed_path})
20
+ else
21
+ command %(mkdir -p config/deploy/templates)
22
+ command %(cp #{nginx_template} #{installed_path})
23
+ end
24
+ end
15
25
  end
16
26
 
17
- desc 'Symlinking nginx config file'
18
- task :link => :environment do
19
- comment %(Symlinking nginx config file)
20
- command %(sudo ln -nfs "#{fetch(:nginx_config)}" "#{fetch(:nginx_config_e)}")
27
+ desc 'Print nginx config in local terminal'
28
+ task :print => :environment do
29
+ run :local do
30
+ command %(echo '#{erb nginx_template}')
31
+ end
21
32
  end
22
33
 
23
- desc 'Parse nginx configuration file and upload it to the server.'
24
- task :parse => :environment do
25
- content = erb(nginx_template)
26
- command %(echo '#{content}' > #{fetch(:nginx_config)})
27
- command %(cat #{fetch(:nginx_config)})
28
- comment %(Be sure to edit 'shared/config/nginx.conf'.)
34
+ desc 'Setup Nginx on server'
35
+ task :setup => :environment do
36
+ nginx_config = fetch :nginx_config
37
+ nginx_enabled_config = fetch :nginx_config_e
38
+
39
+ comment %(Installing nginx config file to #{nginx_config})
40
+ command %(echo '#{erb nginx_template}' > #{nginx_config})
41
+
42
+ comment %(Symlinking nginx config file to #{nginx_enabled_config})
43
+ command %(sudo ln -nfs #{nginx_config} #{nginx_enabled_config})
44
+
45
+ invoke :'nginx:restart'
29
46
  end
30
47
 
31
48
  %w(stop start restart reload status).each do |action|
@@ -39,6 +56,15 @@ namespace :nginx do
39
56
  private
40
57
 
41
58
  def nginx_template
42
- File.expand_path('../templates/nginx.conf.erb', __FILE__)
59
+ installed_path = path_for_template
60
+ template_path = path_for_template installed: false
61
+
62
+ File.exist?(installed_path) ? installed_path : template_path
63
+ end
64
+
65
+ def path_for_template installed: true
66
+ installed ?
67
+ File.expand_path('./config/deploy/templates/nginx.conf.erb') :
68
+ File.expand_path('../templates/nginx.conf.erb', __FILE__)
43
69
  end
44
70
  end
@@ -1,5 +1,5 @@
1
1
  module Mina
2
2
  module Nginx
3
- VERSION = '0.0.2'.freeze
3
+ VERSION = '0.0.3'.freeze
4
4
  end
5
5
  end
@@ -1,15 +1,14 @@
1
+ <% application = fetch :application, 'application' %>
2
+ <% socket_path = fetch :nginx_socket_path, '/path/to/web/socket' %>
3
+
1
4
  upstream <%= application %> {
2
- # server www.example.com weight=5;
3
- # server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
4
- # server unix:///path/to/web_socket.sock;
5
- #
6
- server unix:///PATH/TO/WEB_SOCKET fail_timeout=0;
5
+ server unix://<%= socket_path %> fail_timeout=0;
7
6
  }
8
7
 
9
8
  server {
10
9
  listen 80 default deferred;
11
- <%= server_name.to_s.empty? ? "# server_name example.com" : "server_name #{server_name}" %>;
12
- root <%= deploy_to %>/<%= current_path %>/public;
10
+ server_name <%= fetch :server_name, fetch(:domain) %>
11
+ root <%= "#{fetch :deploy_to}/#{fetch :current_path}/public" %>;
13
12
 
14
13
  location ^~ /assets/ {
15
14
  gzip_static on;
@@ -6,7 +6,7 @@ require 'mina/nginx/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'mina-nginx'
8
8
  spec.version = Mina::Nginx::VERSION
9
- spec.authors = ['hbin']
9
+ spec.authors = ['hbin', 'anulman']
10
10
  spec.email = ['huangbin88@foxmail.com']
11
11
  spec.summary = %(Mina tasks for handle with Nginx.)
12
12
  spec.description = %(Configuration and managements Mina tasks for Nginx.)
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-nginx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hbin
8
+ - anulman
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-11-17 00:00:00.000000000 Z
12
+ date: 2017-01-04 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: mina
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  version: '0'
89
90
  requirements: []
90
91
  rubyforge_project:
91
- rubygems_version: 2.5.1
92
+ rubygems_version: 2.6.8
92
93
  signing_key:
93
94
  specification_version: 4
94
95
  summary: Mina tasks for handle with Nginx.