nginxinator 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nginxinator/built-in.rb +20 -0
- data/lib/nginxinator/config.rb +94 -11
- data/lib/nginxinator/examples/Capfile +1 -1
- data/lib/nginxinator/examples/config/deploy/staging.rb +6 -10
- data/lib/nginxinator/examples/config/deploy.rb +7 -20
- data/lib/nginxinator/nginx.rb +27 -21
- data/lib/nginxinator.rb +1 -0
- metadata +13 -12
@@ -0,0 +1,20 @@
|
|
1
|
+
set :webserver_log_level, "info"
|
2
|
+
set :webserver_config_files, ["nginx.conf", "ssl.crt", "ssl.key", "mime.types"]
|
3
|
+
set :webserver_data_path, -> { current_path }
|
4
|
+
set :webserver_logs_path, -> { shared_path.join('log') }
|
5
|
+
set :webserver_config_path, -> { shared_path.join('nginx') }
|
6
|
+
set :webserver_socket_path, -> { shared_path.join('run') }
|
7
|
+
set :webserver_templates_path, "templates/nginx"
|
8
|
+
set :webserver_container_name, -> { "#{fetch(:domain)}-nginx-#{fetch(:webserver_publish_ports).join('-')}" }
|
9
|
+
set :webserver_ports_options, -> { fetch(:webserver_publish_ports).collect { |p| ["--publish", "0.0.0.0:#{p}:#{p}"] }.flatten }
|
10
|
+
|
11
|
+
def webserver_run(host)
|
12
|
+
execute("docker", "run", "--detach", "--tty",
|
13
|
+
"--name", fetch(:webserver_container_name),
|
14
|
+
"--volume", "#{fetch(:deploy_to)}:#{fetch(:deploy_to)}:rw",
|
15
|
+
"--entrypoint", "/usr/sbin/nginx",
|
16
|
+
"--restart", "always",
|
17
|
+
fetch(:webserver_ports_options),
|
18
|
+
fetch(:webserver_image_name),
|
19
|
+
"-c", shared_path.join('nginx', 'nginx.conf'))
|
20
|
+
end
|
data/lib/nginxinator/config.rb
CHANGED
@@ -1,24 +1,107 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module TaskEnhancements
|
3
|
+
alias_method :nginx_original_default_tasks, :default_tasks
|
4
|
+
def default_tasks
|
5
|
+
nginx_original_default_tasks + [
|
6
|
+
"nginxinator:write_built_in",
|
7
|
+
"nginxinator:write_example_configs",
|
8
|
+
"nginxinator:write_example_configs:in_place"
|
9
|
+
]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
1
14
|
namespace :nginxinator do
|
2
15
|
|
3
|
-
|
16
|
+
set :example, "_example"
|
17
|
+
|
18
|
+
desc "Write example config files (with '_example' appended to their names)."
|
4
19
|
task :write_example_configs do
|
5
20
|
run_locally do
|
6
|
-
execute "mkdir", "-p", "config/deploy",
|
21
|
+
execute "mkdir", "-p", "config/deploy", fetch(:webserver_templates_path, 'templates/nginx')
|
7
22
|
{
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
23
|
+
"examples/Capfile" => "Capfile#{fetch(:example)}",
|
24
|
+
"examples/config/deploy.rb" => "config/deploy#{fetch(:example)}.rb",
|
25
|
+
"examples/config/deploy/staging.rb" => "config/deploy/staging#{fetch(:example)}.rb",
|
26
|
+
"examples/Dockerfile" => "#{fetch(:webserver_templates_path, 'templates/nginx')}/Dockerfile#{fetch(:example)}",
|
27
|
+
"examples/nginx.conf.erb" => "#{fetch(:webserver_templates_path, 'templates/nginx')}/nginx#{fetch(:example)}.conf.erb",
|
28
|
+
"examples/ssl.crt.erb" => "#{fetch(:webserver_templates_path, 'templates/nginx')}/ssl.crt#{fetch(:example)}.erb",
|
29
|
+
"examples/ssl.key.erb" => "#{fetch(:webserver_templates_path, 'templates/nginx')}/ssl.key#{fetch(:example)}.erb",
|
30
|
+
"examples/mime.types.erb" => "#{fetch(:webserver_templates_path, 'templates/nginx')}/mime.types#{fetch(:example)}.erb"
|
16
31
|
}.each do |source, destination|
|
17
32
|
config = File.read(File.dirname(__FILE__) + "/#{source}")
|
18
33
|
File.open("./#{destination}", 'w') { |f| f.write(config) }
|
19
34
|
info "Wrote '#{destination}'"
|
20
35
|
end
|
21
|
-
|
36
|
+
unless fetch(:example).empty?
|
37
|
+
info "Now remove the '#{fetch(:example)}' portion of their names or diff with existing files and add the needed lines."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Write example config files (will overwrite any existing config files).'
|
43
|
+
namespace :write_example_configs do
|
44
|
+
task :in_place do
|
45
|
+
set :example, ""
|
46
|
+
Rake::Task['nginxinator:write_example_configs'].invoke
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'Write a file showing the built-in overridable settings.'
|
51
|
+
task :write_built_in do
|
52
|
+
run_locally do
|
53
|
+
{
|
54
|
+
'built-in.rb' => 'built-in.rb',
|
55
|
+
}.each do |source, destination|
|
56
|
+
config = File.read(File.dirname(__FILE__) + "/#{source}")
|
57
|
+
File.open("./#{destination}", 'w') { |f| f.write(config) }
|
58
|
+
info "Wrote '#{destination}'"
|
59
|
+
end
|
60
|
+
info "Now examine the file and copy-paste into your deploy.rb or <stage>.rb and customize."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# These are the only two tasks using :preexisting_ssh_user
|
65
|
+
namespace :deployment_user do
|
66
|
+
#desc "Setup or re-setup the deployment user, idempotently"
|
67
|
+
task :setup do
|
68
|
+
on roles(:all) do |h|
|
69
|
+
on "#{fetch(:preexisting_ssh_user)}@#{h}" do |host|
|
70
|
+
as :root do
|
71
|
+
deployment_user_setup(fetch(:webserver_templates_path))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
task :deployment_user do
|
79
|
+
on roles(:all) do |h|
|
80
|
+
on "#{fetch(:preexisting_ssh_user)}@#{h}" do |host|
|
81
|
+
as :root do
|
82
|
+
if unix_user_exists?(fetch(:deployment_username))
|
83
|
+
info "User #{fetch(:deployment_username)} already exists. You can safely re-setup the user with 'nginxinator:deployment_user:setup'."
|
84
|
+
else
|
85
|
+
Rake::Task['nginxinator:deployment_user:setup'].invoke
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
task :webserver_user do
|
93
|
+
on roles(:app) do
|
94
|
+
as :root do
|
95
|
+
unix_user_add(fetch(:webserver_username)) unless unix_user_exists?(fetch(:webserver_username))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
task :file_permissions => [:deployment_user, :webserver_user] do
|
101
|
+
on roles(:app) do
|
102
|
+
as :root do
|
103
|
+
setup_file_permissions
|
104
|
+
end
|
22
105
|
end
|
23
106
|
end
|
24
107
|
|
@@ -1,13 +1,9 @@
|
|
1
|
+
##### nginxinator
|
2
|
+
### ------------------------------------------------------------------
|
1
3
|
set :domain, "my-app.example.com"
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
role :web, fetch(:user_host)
|
6
|
-
role :db, fetch(:user_host)
|
7
|
-
|
8
|
-
|
9
|
-
# nginxinator
|
10
|
-
#--------------------------------------------------------------------------
|
4
|
+
server fetch(:domain),
|
5
|
+
:user => fetch(:deployment_username),
|
6
|
+
:roles => ["app", "web", "db"]
|
11
7
|
set :webserver_publish_ports, ["80", "443"]
|
12
8
|
set :webserver_image_name, "snarlysodboxer/nginx:0.0.0"
|
13
|
-
|
9
|
+
### ------------------------------------------------------------------
|
@@ -1,27 +1,14 @@
|
|
1
|
-
# config valid only for Capistrano 3.1
|
1
|
+
# config valid only for Capistrano 3.2.1
|
2
2
|
lock '3.2.1'
|
3
3
|
|
4
|
+
##### nginxinator
|
5
|
+
### ------------------------------------------------------------------
|
6
|
+
set :application, "my_app_name"
|
4
7
|
set :preexisting_ssh_user, ENV['USER']
|
5
8
|
set :deployment_username, "deployer"
|
6
9
|
set :webserver_username, "www-data"
|
7
|
-
set :
|
8
|
-
set :
|
9
|
-
set :webserver_logs_path, shared_path.join('log')
|
10
|
-
set :webserver_config_path, shared_path.join('nginx')
|
11
|
-
set :webserver_socket_path, shared_path.join('run')
|
12
|
-
set :webserver_writeable_dirs, [shared_path.join('run'), shared_path.join('log')]
|
10
|
+
set :webserver_owned_dirs, [shared_path.join('tmp', 'cache'), shared_path.join('public', 'assets')]
|
11
|
+
set :webserver_writeable_dirs, [shared_path.join('run'), shared_path.join('tmp'), shared_path.join('log')]
|
13
12
|
set :webserver_executable_dirs, [shared_path.join('bundle', 'bin')]
|
14
13
|
set :ignore_permissions_dirs, [shared_path.join('postgres'), shared_path.join('nginx')]
|
15
|
-
|
16
|
-
set :webserver_ports_options, -> { fetch(:webserver_publish_ports).collect { |p| ["--publish", "0.0.0.0:#{p}:#{p}"] }.flatten }
|
17
|
-
set :webserver_docker_run_command, -> { [
|
18
|
-
"--detach", "--tty",
|
19
|
-
"--name", fetch(:webserver_container_name),
|
20
|
-
"--volume", "#{fetch(:deploy_to)}:#{fetch(:deploy_to)}:rw",
|
21
|
-
"--entrypoint", "/usr/sbin/nginx",
|
22
|
-
"--restart", "always",
|
23
|
-
fetch(:webserver_ports_options),
|
24
|
-
fetch(:webserver_image_name),
|
25
|
-
"-c", shared_path.join('nginx', 'nginx.conf')
|
26
|
-
].flatten }
|
27
|
-
set :local_templates_path, "templates/nginx"
|
14
|
+
### ------------------------------------------------------------------
|
data/lib/nginxinator/nginx.rb
CHANGED
@@ -1,24 +1,30 @@
|
|
1
1
|
namespace :nginx do
|
2
2
|
|
3
|
+
task :ensure_setup => ['nginxinator:deployment_user', 'nginxinator:webserver_user', 'deployinator:sshkit_umask'] do
|
4
|
+
SSHKit.config.output_verbosity = fetch(:webserver_log_level)
|
5
|
+
end
|
6
|
+
|
3
7
|
desc "Idempotently setup an Nginx instance."
|
4
|
-
task :setup => [
|
8
|
+
task :setup => [:ensure_setup] do
|
5
9
|
Rake::Task['nginx:open_firewall'].invoke
|
6
10
|
# 'on', 'run_locally', 'as', 'execute', 'info', 'warn', and 'fatal' are from SSHKit
|
7
|
-
on roles(:app) do
|
11
|
+
on roles(:app) do |host|
|
8
12
|
as :root do
|
9
13
|
set :config_file_changed, false
|
10
14
|
Rake::Task['nginx:install_config_files'].invoke
|
11
|
-
Rake::Task['
|
12
|
-
|
13
|
-
|
15
|
+
Rake::Task['nginxinator:file_permissions'].invoke
|
16
|
+
name = fetch(:webserver_container_name)
|
17
|
+
unless container_exists?(name)
|
18
|
+
warn "Starting a new container named #{name} on #{host}"
|
19
|
+
webserver_run(host)
|
14
20
|
else
|
15
|
-
unless container_is_running?(
|
16
|
-
start_container(
|
21
|
+
unless container_is_running?(name)
|
22
|
+
start_container(name)
|
17
23
|
else
|
18
24
|
if fetch(:config_file_changed)
|
19
|
-
restart_container(
|
25
|
+
restart_container(name)
|
20
26
|
else
|
21
|
-
info "No config file changes for #{
|
27
|
+
info "No config file changes for #{name} and it is already running; we're setup!"
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
@@ -27,34 +33,35 @@ namespace :nginx do
|
|
27
33
|
end
|
28
34
|
|
29
35
|
desc "Check the status of the Nginx instance."
|
30
|
-
task :status => [
|
36
|
+
task :status => [:ensure_setup] do
|
31
37
|
on roles(:app) do
|
32
38
|
info ""
|
33
|
-
|
34
|
-
|
39
|
+
name = fetch(:webserver_container_name)
|
40
|
+
if container_exists?(name)
|
41
|
+
info "#{name} exists on #{fetch(:domain)}"
|
35
42
|
info ""
|
36
|
-
if container_is_running?(
|
37
|
-
info "#{
|
43
|
+
if container_is_running?(name)
|
44
|
+
info "#{name} is running on #{fetch(:domain)}"
|
38
45
|
info ""
|
39
46
|
else
|
40
|
-
info "#{
|
47
|
+
info "#{name} is not running on #{fetch(:domain)}"
|
41
48
|
info ""
|
42
49
|
end
|
43
50
|
else
|
44
|
-
info "#{
|
51
|
+
info "#{name} does not exist on #{fetch(:domain)}"
|
45
52
|
info ""
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
50
|
-
task :install_config_files => [
|
51
|
-
require 'erb'
|
57
|
+
task :install_config_files => [:ensure_setup] do
|
58
|
+
require 'erb' unless defined?(ERB)
|
52
59
|
on roles(:app) do
|
53
60
|
as 'root' do
|
54
61
|
execute "mkdir", "-p", fetch(:webserver_socket_path),
|
55
62
|
fetch(:webserver_logs_path), fetch(:webserver_config_path)
|
56
63
|
fetch(:webserver_config_files).each do |config_file|
|
57
|
-
template_path = File.expand_path("#{fetch(:
|
64
|
+
template_path = File.expand_path("#{fetch(:webserver_templates_path)}/#{config_file}.erb")
|
58
65
|
generated_config_file = ERB.new(File.new(template_path).read).result(binding)
|
59
66
|
upload! StringIO.new(generated_config_file), "/tmp/#{config_file}.file"
|
60
67
|
unless test "diff", "-q", "/tmp/#{config_file}.file", "#{fetch(:webserver_config_path)}/#{config_file}"
|
@@ -65,7 +72,6 @@ namespace :nginx do
|
|
65
72
|
execute "rm", "/tmp/#{config_file}.file"
|
66
73
|
end
|
67
74
|
end
|
68
|
-
#execute("chown", "-R", "#{fetch(:deployment_user_id)}:#{fetch(:webserver_user_id)}", fetch(:webserver_config_path))
|
69
75
|
execute("chown", "-R", "root:root", fetch(:webserver_config_path))
|
70
76
|
execute "find", fetch(:webserver_config_path), "-type", "d", "-exec", "chmod", "2775", "{}", "+"
|
71
77
|
execute "find", fetch(:webserver_config_path), "-type", "f", "-exec", "chmod", "0600", "{}", "+"
|
@@ -73,7 +79,7 @@ namespace :nginx do
|
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
76
|
-
task :open_firewall do
|
82
|
+
task :open_firewall => [:ensure_setup] do
|
77
83
|
on roles(:app) do
|
78
84
|
as "root" do
|
79
85
|
if test "bash", "-c", "\"ufw", "status", "&>" "/dev/null\""
|
data/lib/nginxinator.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nginxinator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,14 +9,14 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 3.2.1
|
22
22
|
type: :runtime
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 3.2.1
|
30
30
|
- !ruby/object:Gem::Dependency
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.1.
|
37
|
+
version: 0.1.3
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,13 +42,13 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.1.
|
45
|
+
version: 0.1.3
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: rake
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: 10.3.2
|
54
54
|
type: :runtime
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 10.3.2
|
62
62
|
- !ruby/object:Gem::Dependency
|
@@ -64,7 +64,7 @@ dependencies:
|
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 1.5.1
|
70
70
|
type: :runtime
|
@@ -72,10 +72,10 @@ dependencies:
|
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 1.5.1
|
78
|
-
description:
|
78
|
+
description: Deploy Nginx instances using Capistrano and Docker
|
79
79
|
email: davidamick@ctisolutionsinc.com
|
80
80
|
executables: []
|
81
81
|
extensions: []
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/nginxinator/nginx.rb
|
86
86
|
- lib/nginxinator/config.rb
|
87
87
|
- lib/nginxinator/check.rb
|
88
|
+
- lib/nginxinator/built-in.rb
|
88
89
|
- lib/nginxinator/examples/Capfile
|
89
90
|
- lib/nginxinator/examples/config/deploy.rb
|
90
91
|
- lib/nginxinator/examples/config/deploy/staging.rb
|
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
114
|
- !ruby/object:Gem::Version
|
114
115
|
version: '0'
|
115
116
|
requirements:
|
116
|
-
- Docker
|
117
|
+
- Docker ~> 1.3.1
|
117
118
|
rubyforge_project:
|
118
119
|
rubygems_version: 1.8.23.2
|
119
120
|
signing_key:
|