negroku 1.1.14 → 2.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -201
- data/README.rdoc +6 -0
- data/Rakefile +44 -0
- data/bin/negroku +0 -8
- data/features/negroku.feature +8 -0
- data/features/step_definitions/negroku_steps.rb +6 -0
- data/features/support/env.rb +15 -0
- data/lib/negroku/cli/bootstrap.rb +139 -0
- data/lib/negroku/cli/commands/app.rb +39 -0
- data/lib/negroku/cli/commands/negroku.rb +15 -0
- data/lib/negroku/cli.rb +19 -206
- data/lib/negroku/deploy.rb +14 -36
- data/lib/negroku/helpers.rb +6 -83
- data/lib/negroku/i18n.rb +17 -0
- data/lib/negroku/tasks/bower.rake +12 -0
- data/lib/negroku/tasks/bundler.rake +12 -0
- data/lib/negroku/tasks/negroku.rake +48 -0
- data/lib/negroku/tasks/nginx.rake +24 -0
- data/lib/negroku/tasks/nodenv.rake +13 -0
- data/lib/negroku/tasks/rbenv.rake +56 -0
- data/lib/negroku/tasks/unicorn.rake +92 -0
- data/lib/negroku/templates/negroku/Capfile.erb +29 -0
- data/lib/negroku/templates/negroku/deploy.rb.erb +47 -0
- data/lib/negroku/templates/negroku/stage.rb.erb +13 -0
- data/lib/negroku/templates/tasks/unicorn_rails.rb.erb +40 -0
- data/lib/negroku/{tasks/templates/unicorn.erb → templates/tasks/unicorn_rails_activerecord.rb.erb} +5 -5
- data/lib/negroku/version.rb +1 -1
- data/lib/negroku.rb +4 -6
- data/negroku.gemspec +42 -0
- data/negroku.rdoc +5 -0
- data/test/default_test.rb +14 -0
- data/test/test_helper.rb +9 -0
- metadata +252 -51
- data/lib/negroku/capfile.rb +0 -32
- data/lib/negroku/config.rb +0 -36
- data/lib/negroku/tasks/base.rb +0 -29
- data/lib/negroku/tasks/bower.rb +0 -9
- data/lib/negroku/tasks/log.rb +0 -25
- data/lib/negroku/tasks/nginx.rb +0 -61
- data/lib/negroku/tasks/rbenv.rb +0 -27
- data/lib/negroku/tasks/templates/nginx.erb +0 -90
- data/lib/negroku/tasks/unicorn.rb +0 -47
- data/lib/negroku/templates/deploy.rb.erb +0 -24
- data/lib/negroku/templates/production.rb.erb +0 -14
- data/lib/negroku/templates/staging.rb.erb +0 -14
data/lib/negroku/config.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
def saveConfig(action, type, data)
|
4
|
-
# Load the yaml file
|
5
|
-
config_file = File.join(ENV['HOME'], ".negroku")
|
6
|
-
config = getConfig
|
7
|
-
|
8
|
-
# If I need to add some multiple values
|
9
|
-
if action === :add
|
10
|
-
newData = config[type] || []
|
11
|
-
newData.push(data)
|
12
|
-
newData.uniq!
|
13
|
-
config = config.merge({ type => newData })
|
14
|
-
elsif action === :remove
|
15
|
-
#..
|
16
|
-
elsif action === :replace
|
17
|
-
#..
|
18
|
-
end
|
19
|
-
|
20
|
-
File.open(config_file, 'w') do |f|
|
21
|
-
f.write config.to_yaml
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def getConfig
|
26
|
-
# load config from file
|
27
|
-
config_file = File.join(ENV['HOME'], ".negroku")
|
28
|
-
|
29
|
-
# create an empty .negroku file
|
30
|
-
unless File.exist?(config_file)
|
31
|
-
%x(touch #{config_file})
|
32
|
-
end
|
33
|
-
|
34
|
-
# base config
|
35
|
-
YAML.load_file(config_file) || {}
|
36
|
-
end
|
data/lib/negroku/tasks/base.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Wrapper method for quickly loading, rendering ERB templates
|
2
|
-
# and uploading them to the server.
|
3
|
-
def template(from, to)
|
4
|
-
erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
|
5
|
-
put ERB.new(erb).result(binding), to
|
6
|
-
end
|
7
|
-
|
8
|
-
# Wrapper method to set default values for recipes.
|
9
|
-
def set_default(name, *args, &block)
|
10
|
-
set(name, *args, &block) unless exists?(name)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Review and modify the tasks below on a per-app/language/framework basis.
|
14
|
-
namespace :deploy do
|
15
|
-
after "deploy:update_code", "deploy:migrate"
|
16
|
-
|
17
|
-
after "deploy:finalize_update", "deploy:symlink_cache"
|
18
|
-
desc "Symlink temporary cache from shared to the release"
|
19
|
-
task :symlink_cache, :roles => :app do
|
20
|
-
run "ln -nfs '#{shared_path}/tmp/cache' '#{release_path}/tmp/cache'"
|
21
|
-
end
|
22
|
-
|
23
|
-
after "deploy:setup", "deploy:setup_shared"
|
24
|
-
desc "Sets up additional folders/files after deploy:setup."
|
25
|
-
task :setup_shared do
|
26
|
-
run "mkdir -p '#{shared_path}/config'"
|
27
|
-
run "mkdir -p '#{shared_path}/tmp/cache'"
|
28
|
-
end
|
29
|
-
end
|
data/lib/negroku/tasks/bower.rb
DELETED
data/lib/negroku/tasks/log.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
namespace :log do
|
2
|
-
desc "Stream (tail) the application's log."
|
3
|
-
task :app do
|
4
|
-
trap("INT") { puts 'Exit'; exit 0; }
|
5
|
-
stream "tail -f '#{shared_path}/log/#{fetch(:rails_env)}.log'"
|
6
|
-
end
|
7
|
-
|
8
|
-
desc "Stream (tail) the nginx access log."
|
9
|
-
task :nginx_access do
|
10
|
-
trap("INT") { puts 'Exit'; exit 0; }
|
11
|
-
stream "tail -f '/home/#{fetch(:user)}/log/#{fetch(:application)}-nginx-access.log'"
|
12
|
-
end
|
13
|
-
|
14
|
-
desc "Stream (tail) the nginx error log."
|
15
|
-
task :nginx_error do
|
16
|
-
trap("INT") { puts 'Exit'; exit 0; }
|
17
|
-
stream "tail -f '/home/#{fetch(:user)}/log/#{fetch(:application)}-nginx-error.log'"
|
18
|
-
end
|
19
|
-
|
20
|
-
desc "Stream (tail) the unicorn error log."
|
21
|
-
task :unicorn_error do
|
22
|
-
trap("INT") { puts 'Exit'; exit 0; }
|
23
|
-
stream "tail -f '#{fetch(:current_path)}/log/unicorn-error.log'"
|
24
|
-
end
|
25
|
-
end
|
data/lib/negroku/tasks/nginx.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# Define the domains in an Array, these will be embedded in the uploaded nginx configuration file.
|
2
|
-
# Define either the app_server_port or app_server_socket when enabling app_server, else leave it blank.
|
3
|
-
# Places the SSL certs in /home/<user>/ssl/<application>.key and /home/<user>/ssl/<application>.crt when
|
4
|
-
# setting use_ssl to true.
|
5
|
-
# Define the `static_dir`, in Rails this would be `public`.
|
6
|
-
# Feel free to further modify the template to your needs as it doesn't cover every use-case of course,
|
7
|
-
# but tries to get all the common requirements out of the way to lessen research time (if any).
|
8
|
-
|
9
|
-
set_default :domains, ["your.domain.com"]
|
10
|
-
set_default :static_dir, "public"
|
11
|
-
|
12
|
-
set_default :app_server, true
|
13
|
-
#set_default :app_server_port, 8080
|
14
|
-
set_default :app_server_socket, "/home/#{fetch(:user)}/tmp/negroku.#{fetch(:application)}.sock"
|
15
|
-
|
16
|
-
# set_default :use_ssl, true
|
17
|
-
# set_default :ssl_key, "/path/to/local/ssh.key"
|
18
|
-
# set_default :ssl_crt, "/path/to/local/ssh.crt"
|
19
|
-
|
20
|
-
namespace :nginx do
|
21
|
-
# after "deploy:install", "nginx:install"
|
22
|
-
# desc "Install latest stable release of nginx."
|
23
|
-
# task :install, roles: :web do
|
24
|
-
# run "#{sudo} add-apt-repository ppa:nginx/stable"
|
25
|
-
# run "#{sudo} apt-get -y update"
|
26
|
-
# run "#{sudo} apt-get -y install nginx"
|
27
|
-
# end
|
28
|
-
|
29
|
-
after "deploy:setup", "nginx:upload_ssl_certificates"
|
30
|
-
desc "Upload SSL certificates for this application."
|
31
|
-
task :upload_ssl_certificates, roles: :web do
|
32
|
-
if fetch(:use_ssl, nil)
|
33
|
-
run "mkdir -p /home/#{fetch(:user)}/ssl"
|
34
|
-
upload ssl_key, "/home/#{fetch(:user)}/ssl/#{fetch(:application)}.key"
|
35
|
-
upload ssl_crt, "/home/#{fetch(:user)}/ssl/#{fetch(:application)}.crt"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
after "deploy:setup", "nginx:setup"
|
40
|
-
desc "Setup nginx configuration for this application."
|
41
|
-
task :setup, roles: :web do
|
42
|
-
config_file = "config/deploy/nginx.conf.erb"
|
43
|
-
if File.exists?(config_file)
|
44
|
-
config = ERB.new(File.read(config_file)).result(binding)
|
45
|
-
put config, "/tmp/nginx.conf"
|
46
|
-
else
|
47
|
-
template "nginx.erb", "/tmp/nginx.conf"
|
48
|
-
end
|
49
|
-
run "mv /tmp/nginx.conf /etc/nginx/sites-available/#{fetch(:application)}"
|
50
|
-
run "ln -nfs /etc/nginx/sites-available/#{fetch(:application)} /etc/nginx/sites-enabled/#{fetch(:application)}"
|
51
|
-
run "mkdir -p /home/#{fetch(:user)}/log"
|
52
|
-
reload
|
53
|
-
end
|
54
|
-
|
55
|
-
%w[start stop restart reload].each do |command|
|
56
|
-
desc "#{command} Nginx."
|
57
|
-
task command, roles: :web do
|
58
|
-
run "#{sudo} service nginx #{command}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
data/lib/negroku/tasks/rbenv.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
set_default :rbenv_roles, [:app]
|
2
|
-
|
3
|
-
# rbenv vars tasks
|
4
|
-
|
5
|
-
namespace :rbenv do
|
6
|
-
namespace :vars do
|
7
|
-
desc "Show current rbenv vars"
|
8
|
-
task :show, :roles => lambda { rbenv_roles } do
|
9
|
-
run "sh -c 'cd #{shared_path} && cat .rbenv-vars'"
|
10
|
-
end
|
11
|
-
|
12
|
-
desc "Add rbenv vars"
|
13
|
-
task :add, :roles => lambda { rbenv_roles } do
|
14
|
-
cmd = "if awk < #{shared_path}/.rbenv-vars -F= '{print $1}' | grep --quiet -w #{key}; then "
|
15
|
-
cmd += "sed -i 's/^#{key}=.*/#{key}=#{value.to_s.gsub("\/", "\\/").gsub("&", "\\\\&")}/g' #{shared_path}/.rbenv-vars;"
|
16
|
-
cmd += "else echo '#{key}=#{value}' >> #{shared_path}/.rbenv-vars;"
|
17
|
-
cmd += "fi"
|
18
|
-
run cmd
|
19
|
-
end
|
20
|
-
|
21
|
-
after "deploy:finalize_update", "rbenv:vars:symlink"
|
22
|
-
desc "Symlink rbenv-vars file into the current release"
|
23
|
-
task :symlink, :roles => lambda { rbenv_roles } do
|
24
|
-
run "ln -nfs '#{shared_path}/.rbenv-vars' '#{release_path}/.rbenv-vars'"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
# Define App Server Upstream
|
2
|
-
<% if fetch(:app_server, nil) %>
|
3
|
-
upstream <%= fetch(:application) %>-app-server {
|
4
|
-
<% if fetch(:app_server_port, nil) %>
|
5
|
-
server 127.0.0.1:<%= fetch(:app_server_port) %> fail_timeout=0;
|
6
|
-
<% elsif fetch(:app_server_socket, nil) %>
|
7
|
-
server unix:<%= fetch(:app_server_socket) %> fail_timeout=0;
|
8
|
-
<% end %>
|
9
|
-
}
|
10
|
-
<% end %>
|
11
|
-
|
12
|
-
# HTTP Server
|
13
|
-
server {
|
14
|
-
listen 80;
|
15
|
-
server_name <%= fetch(:domains) %>;
|
16
|
-
root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>;
|
17
|
-
|
18
|
-
access_log /home/<%= fetch(:user) %>/log/<%= fetch(:application) %>-nginx-access.log;
|
19
|
-
error_log /home/<%= fetch(:user) %>/log/<%= fetch(:application) %>-nginx-error.log;
|
20
|
-
|
21
|
-
error_page 404 /404.html;
|
22
|
-
location /404.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; }
|
23
|
-
|
24
|
-
error_page 500 /500.html;
|
25
|
-
location /500.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; }
|
26
|
-
|
27
|
-
client_max_body_size 4G;
|
28
|
-
keepalive_timeout 10;
|
29
|
-
|
30
|
-
<% if fetch(:app_server, nil) %>
|
31
|
-
location ^~ /assets/ {
|
32
|
-
gzip_static on;
|
33
|
-
expires max;
|
34
|
-
add_header Cache-Control public;
|
35
|
-
}
|
36
|
-
|
37
|
-
try_files $uri/index.html $uri @<%= fetch(:application) %>-app-server;
|
38
|
-
location @<%= fetch(:application) %>-app-server {
|
39
|
-
proxy_set_header X-Real-IP $remote_addr;
|
40
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
41
|
-
proxy_set_header X-FORWARDED_PROTO http;
|
42
|
-
proxy_set_header Host $http_host;
|
43
|
-
proxy_redirect off;
|
44
|
-
proxy_pass http://<%= fetch(:application) %>-app-server;
|
45
|
-
}
|
46
|
-
<% end %>
|
47
|
-
}
|
48
|
-
|
49
|
-
<% if fetch(:use_ssl, nil) %>
|
50
|
-
# HTTPS Server
|
51
|
-
server {
|
52
|
-
listen 443 deferred;
|
53
|
-
server_name <%= fetch(:domains, ["platan.us", "www.platan.us"]).join(" ") %>;
|
54
|
-
root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>;
|
55
|
-
|
56
|
-
ssl on;
|
57
|
-
ssl_certificate /home/<%= fetch(:user) %>/ssl/<%= fetch(:application) %>.crt;
|
58
|
-
ssl_certificate_key /home/<%= fetch(:user) %>/ssl/<%= fetch(:application) %>.key;
|
59
|
-
|
60
|
-
access_log /home/<%= fetch(:user) %>/log/<%= fetch(:application) %>-nginx-access.log;
|
61
|
-
error_log /home/<%= fetch(:user) %>/log/<%= fetch(:application) %>-nginx-error.log;
|
62
|
-
|
63
|
-
error_page 404 /404.html;
|
64
|
-
location /404.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; }
|
65
|
-
|
66
|
-
error_page 500 /500.html;
|
67
|
-
location /500.html { root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>; }
|
68
|
-
|
69
|
-
client_max_body_size 4G;
|
70
|
-
keepalive_timeout 10;
|
71
|
-
|
72
|
-
<% if fetch(:app_server, nil) %>
|
73
|
-
location ^~ /assets/ {
|
74
|
-
gzip_static on;
|
75
|
-
expires max;
|
76
|
-
add_header Cache-Control public;
|
77
|
-
}
|
78
|
-
|
79
|
-
try_files $uri/index.html $uri @<%= fetch(:application) %>-app-server;
|
80
|
-
location @<%= fetch(:application) %>-app-server {
|
81
|
-
proxy_set_header X-Real-IP $remote_addr;
|
82
|
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
83
|
-
proxy_set_header X-FORWARDED_PROTO https;
|
84
|
-
proxy_set_header Host $http_host;
|
85
|
-
proxy_redirect off;
|
86
|
-
proxy_pass http://<%= fetch(:application) %>-app-server;
|
87
|
-
}
|
88
|
-
<% end %>
|
89
|
-
}
|
90
|
-
<% end %>
|
@@ -1,47 +0,0 @@
|
|
1
|
-
|
2
|
-
# Number of workers (Rule of thumb is 2 per CPU)
|
3
|
-
# Just be aware that every worker needs to cache all classes and thus eat some
|
4
|
-
# of your RAM.
|
5
|
-
set_default :unicorn_workers, 1
|
6
|
-
|
7
|
-
# Workers timeout in the amount of seconds below, when the master kills it and
|
8
|
-
# forks another one.
|
9
|
-
set_default :unicorn_workers_timeout, 30
|
10
|
-
|
11
|
-
# Workers are started with this user
|
12
|
-
# By default we get the user/group set in capistrano.
|
13
|
-
set_default :unicorn_user, nil
|
14
|
-
|
15
|
-
# The wrapped bin to start unicorn
|
16
|
-
set_default :unicorn_bin, 'bin/unicorn'
|
17
|
-
set_default :unicorn_socket, fetch(:app_server_socket)
|
18
|
-
|
19
|
-
# Defines where the unicorn pid will live.
|
20
|
-
set_default(:unicorn_pid) { File.join(current_path, "tmp", "pids", "unicorn.pid") }
|
21
|
-
|
22
|
-
# Preload app for fast worker spawn
|
23
|
-
set_default :unicorn_preload, true
|
24
|
-
|
25
|
-
set_default(:unicorn_config_path) { "#{shared_path}/config" }
|
26
|
-
|
27
|
-
# Unicorn
|
28
|
-
#------------------------------------------------------------------------------
|
29
|
-
# Load unicorn tasks
|
30
|
-
require "capistrano-unicorn"
|
31
|
-
|
32
|
-
namespace :unicorn do
|
33
|
-
after "deploy:setup", "unicorn:setup"
|
34
|
-
desc "Setup unicorn configuration for this application."
|
35
|
-
task :setup, roles: :app do
|
36
|
-
template "unicorn.erb", "/tmp/unicorn.rb"
|
37
|
-
run "mv /tmp/unicorn.rb #{shared_path}/config/"
|
38
|
-
end
|
39
|
-
|
40
|
-
after "deploy:cold", "unicorn:start"
|
41
|
-
after 'deploy:restart', 'unicorn:restart'
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
# after 'deploy:setup' do
|
46
|
-
# unicorn.setup if Capistrano::CLI.ui.agree("Create unicorn configuration file? [Yn]")
|
47
|
-
# end if is_using_unicorn
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# Set server stages
|
2
|
-
set :stages, %w(production staging)
|
3
|
-
set :default_stage, "staging"
|
4
|
-
require 'capistrano/ext/multistage'
|
5
|
-
|
6
|
-
# Server-side information.
|
7
|
-
set :application, "<%= data[:application_name] %>"
|
8
|
-
set :user, "deploy"
|
9
|
-
set :deploy_to, "/home/#{user}/applications/#{application}"
|
10
|
-
|
11
|
-
# Repository (if any) configuration.
|
12
|
-
set :deploy_via, :remote_cache
|
13
|
-
set :repository, "<%= data[:repo] %>"
|
14
|
-
# set :git_enable_submodules, 1
|
15
|
-
|
16
|
-
# Database
|
17
|
-
# set :migrate_env, "migration"
|
18
|
-
|
19
|
-
# Unicorn
|
20
|
-
set :unicorn_workers, 1
|
21
|
-
|
22
|
-
# Cleanup after deploy
|
23
|
-
set :keep_releases, 3
|
24
|
-
after "deploy", "deploy:cleanup"
|
@@ -1,14 +0,0 @@
|
|
1
|
-
## PRODUCTION CONFIGURATION
|
2
|
-
|
3
|
-
# Servers and their roles.
|
4
|
-
server "<%= data[:production_server] %>", :web, :app, :db, primary: true
|
5
|
-
|
6
|
-
# Web server configuration
|
7
|
-
set :domains, "<%= data[:production_domains] %>"
|
8
|
-
|
9
|
-
# Source
|
10
|
-
set :branch, "production" # Optional, defaults to master
|
11
|
-
# set :remote, "origin" # Optional, defaults to origin
|
12
|
-
|
13
|
-
# Rails
|
14
|
-
# set :rails_env, "production" # Optional, defaults to production
|
@@ -1,14 +0,0 @@
|
|
1
|
-
## STAGING CONFIGURATION
|
2
|
-
|
3
|
-
# Servers and their roles.
|
4
|
-
server "<%= data[:staging_server] %>", :web, :app, :db, primary: true
|
5
|
-
|
6
|
-
# Web server configuration
|
7
|
-
set :domains, "<%= data[:staging_domains] %>"
|
8
|
-
|
9
|
-
# Source
|
10
|
-
set :branch, "production" # Optional, defaults to master
|
11
|
-
# set :remote, "origin" # Optional, defaults to origin
|
12
|
-
|
13
|
-
# Rails
|
14
|
-
# set :rails_env, "staging" # Optional, defaults to production
|