guard-nginx 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5b3a1cb4863c400c165ba7ee33df070a11b533699a4b7776246d11629edb3828
4
+ data.tar.gz: 66af32f85a6b3c75ddfe317230534798f9879056d77a99e4faf11a017f60937d
5
+ SHA512:
6
+ metadata.gz: 617d6591cb44014734a76bd16e4205d769792d03c09b85dae6e166a80ea9b490f547edc9813bfd83bcf0c6b9b5ddfb308d8bac9a541c0734bcd7f057709972e3
7
+ data.tar.gz: c37f39cfb97d6295ec81c1409f484009d535ab0b32d43d3566c8224bea2e0f69918e6f722ae179e8822244a6f6ed39acaae0b0695a3d9969bb7d16287000cb9e
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at frederik@progras.dk. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in guard-nginx.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Frederik Spang
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.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # guard-nginx - An nginx plugin for *your* Guardfile
2
+ [![Gem Version](https://badge.fury.io/rb/guard-nginx.svg)](https://badge.fury.io/rb/guard-nginx)
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'guard-nginx'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install guard-nginx
18
+
19
+ Then add to Guardfile by
20
+
21
+ $ guard init nginx
22
+
23
+ or manually with
24
+
25
+ guard 'nginx' do
26
+ watch(%r{^config/nginx/.*})
27
+ end
28
+
29
+ ## Usage
30
+
31
+ TODO: Write usage instructions here
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/guard-nginx. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the Guard::Nginx project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/guard-nginx/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "guard/nginx"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "guard/nginx/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "guard-nginx"
8
+ spec.version = Guard::NginxVersion::VERSION
9
+ spec.authors = ["Frederik Spang"]
10
+ spec.email = ["frederik@progras.dk"]
11
+
12
+ spec.summary = %q{A guard-plugin for running a local installation of nginx.}
13
+ spec.homepage = "https://progras.dk"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ spec.metadata["source_code_uri"] = "https://github.com/prograsdk/guard-nginx"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_dependency 'guard-compat', '~> 1.2'
36
+
37
+ spec.add_development_dependency "bundler", "~> 1.16"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ spec.add_development_dependency "rspec", "~> 3.0"
40
+ end
@@ -0,0 +1 @@
1
+ require 'guard/nginx'
@@ -0,0 +1,97 @@
1
+ require 'guard/compat/plugin'
2
+ require 'guard/nginx/version'
3
+ require 'guard/nginx/config_processor'
4
+
5
+ module ::Guard
6
+ class Nginx < Plugin
7
+ def initialize(options)
8
+ @value = "Test"
9
+ UI.info "hello path: #{Dir.pwd}"
10
+ Dir.mkdir("#{tmp_path}/config") unless Dir.exist?("#{tmp_path}/config")
11
+ super
12
+ end
13
+
14
+ def start
15
+ # ensure config - create tmp file
16
+ UI.info "Starting Nginx on port #{port}"
17
+ generate_config
18
+
19
+ IO.popen("#{executable} -c #{tmp_path}/config/nginx.conf", 'w+')
20
+ UI.info "Nginx started" if $?.success?
21
+ end
22
+
23
+ def stop
24
+ puts pid
25
+ if pid
26
+ UI.info "Sending TERM signal to Nginx (#{pid})"
27
+ FileUtils.rm "#{tmp_path}/config/nginx.conf"
28
+ Process.kill("TERM", pid)
29
+ true
30
+ end
31
+ end
32
+
33
+ def reload
34
+ UI.info 'reload'
35
+ if pid
36
+ generate_config
37
+
38
+ UI.info "Sending HUP signal to Nginx (reloading #{pid})"
39
+ Process.kill("HUP", pid)
40
+ true
41
+ end
42
+ end
43
+
44
+ def run_all
45
+ reload
46
+ end
47
+
48
+ def run_on_change(paths)
49
+ true
50
+ end
51
+
52
+ private
53
+
54
+ def pidfile_path
55
+ options.fetch(:pidfile) {
56
+ File.expand_path('tmp/pids/nginx.pid', Dir.pwd)
57
+ }
58
+ end
59
+
60
+ def tmp_path
61
+ File.expand_path('tmp', Dir.pwd)
62
+ end
63
+
64
+ def generate_config
65
+ UI.info 'Generating Nginx Config'
66
+ file = ERB.new(
67
+ File.read(
68
+ File.expand_path('nginx/templates/nginx_config.erb', File.dirname(__FILE__))
69
+ ),
70
+ nil,
71
+ '-'
72
+ ).result(
73
+ ConfigProcessor.new({
74
+ port: port,
75
+ use_ssl: true,
76
+ http_port: 3000,
77
+ https_port: 3001,
78
+ server_name: 'localhost'
79
+ }).get_binding
80
+ )
81
+
82
+ File.open("#{tmp_path}/config/nginx.conf", "w") { |f| f.write(file) }
83
+ end
84
+
85
+ def pid
86
+ File.exist?(pidfile_path) && File.read(pidfile_path).to_i
87
+ end
88
+
89
+ def executable
90
+ options.fetch(:executable) { 'nginx' }
91
+ end
92
+
93
+ def port
94
+ options.fetch(:port){ 3000 }
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,29 @@
1
+ class ConfigProcessor
2
+ def initialize(options = {})
3
+ @config = options
4
+ end
5
+
6
+ def config_fetch(key)
7
+ @config.fetch(key.to_sym) { false }
8
+ end
9
+
10
+ def root_path
11
+ Dir.pwd
12
+ end
13
+
14
+ def config_path
15
+ "#{root_path}/config"
16
+ end
17
+
18
+ def tmp_path
19
+ "#{root_path}/tmp"
20
+ end
21
+
22
+ def pid_path
23
+ "#{Dir.pwd}/tmp/pids/nginx.pid"
24
+ end
25
+
26
+ def get_binding
27
+ binding
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ guard :nginx do
2
+ watch(%r{^config/nginx/.*})
3
+ end
@@ -0,0 +1,79 @@
1
+
2
+ pid <%= pid_path %>;
3
+ worker_rlimit_nofile 8192;
4
+ worker_processes 3;
5
+ events {
6
+ worker_connections 1042;
7
+ }
8
+
9
+ http {
10
+ upstream puma_guard_nginx {
11
+ <%= "server unix:#{tmp_path}/sockets/puma.sock;" %>
12
+ }
13
+
14
+ <% if config_fetch(:use_ssl) -%>
15
+ server {
16
+ listen <%= config_fetch(:http_port) %>;
17
+ server_name _;
18
+ rewrite ^(.*) https://$host:3001$1 permanent;
19
+ }
20
+ <% else -%>
21
+ server {
22
+ listen <%= config_fetch(:http_port) %>;
23
+ server_name _;
24
+ }
25
+ <% end -%>
26
+
27
+ server {
28
+ <% if config_fetch(:use_ssl) -%>
29
+ listen <%= config_fetch(:https_port) %> ssl;
30
+ ssl_certificate <%= config_path %>/certificates/server.crt;
31
+ ssl_certificate_key <%= config_path %>/certificates/server.key;
32
+
33
+ ssl_session_timeout 5m;
34
+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
35
+ ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
36
+
37
+ ssl_prefer_server_ciphers on;
38
+ ssl_session_cache shared:SSL:10m;
39
+ ssl_dhparam <%= config_path %>/certificates/dhparam.pem;
40
+ <% else -%>
41
+ listen <%= config_fetch(:http_port) %>;
42
+ <% end -%>
43
+ server_name _;
44
+ root <%= root_path %>/public;
45
+ try_files $uri/index.html $uri @puma_guard_nginx;
46
+
47
+ client_max_body_size 4G;
48
+ keepalive_timeout 10;
49
+
50
+ error_page 500 502 504 /500.html;
51
+ error_page 503 @503;
52
+
53
+ location @puma_guard_nginx {
54
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
55
+ proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
56
+ proxy_set_header Host $http_host;
57
+ proxy_redirect off;
58
+ <% if config_fetch(:use_ssl) -%>
59
+ proxy_set_header X-Forwarded-Proto https;
60
+ <% end -%>
61
+ proxy_pass http://puma_guard_nginx;
62
+ # limit_req zone=one;
63
+ access_log <%= root_path %>/log/nginx.access.log;
64
+ error_log <%= root_path %>/log/nginx.error.log;
65
+ }
66
+
67
+ location = /50x.html {
68
+ root html;
69
+ }
70
+
71
+ location = /404.html {
72
+ root html;
73
+ }
74
+
75
+ if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
76
+ return 405;
77
+ }
78
+ }
79
+ }
@@ -0,0 +1,7 @@
1
+ require 'guard/compat/plugin'
2
+
3
+ module ::Guard
4
+ class NginxVersion
5
+ VERSION = "0.1.1".freeze
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-nginx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Frederik Spang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: guard-compat
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - frederik@progras.dk
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - guard-nginx.gemspec
86
+ - lib/guard-nginx.rb
87
+ - lib/guard/nginx.rb
88
+ - lib/guard/nginx/config_processor.rb
89
+ - lib/guard/nginx/templates/Guardfile
90
+ - lib/guard/nginx/templates/nginx_config.erb
91
+ - lib/guard/nginx/version.rb
92
+ homepage: https://progras.dk
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ source_code_uri: https://github.com/prograsdk/guard-nginx
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.7.6
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A guard-plugin for running a local installation of nginx.
118
+ test_files: []