mana 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -1
- data/lib/mana/capistrano.rb +55 -26
- data/lib/mana/remote_cache_subdir.rb +21 -0
- data/lib/mana/version.rb +1 -1
- data/mana.gemspec +0 -1
- data/templates/config/deploy.rb +21 -3
- metadata +3 -18
data/README.md
CHANGED
@@ -4,6 +4,8 @@ Configuration management with Chef & Capistrano
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
+
### Step 1
|
8
|
+
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
9
11
|
gem 'mana'
|
@@ -16,10 +18,32 @@ Or install it yourself as:
|
|
16
18
|
|
17
19
|
$ gem install mana
|
18
20
|
|
19
|
-
|
21
|
+
### Step 2
|
22
|
+
|
23
|
+
Init project with Chef, Capistrano and Vagrant configs:
|
20
24
|
|
21
25
|
rake mana:install
|
22
26
|
|
27
|
+
Edit `config/deploy.rb` to provide application name, SCM repository etc. and Chef cookbook params.
|
28
|
+
|
29
|
+
Edit `Vagrantfile` to match your available Vagrant boxes and personal taste.
|
30
|
+
|
31
|
+
Edit Chef cookbooks under `config/deploy/cookbooks` directory to add software.
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
Setup all software on server:
|
36
|
+
|
37
|
+
cap <stage> mana:setup
|
38
|
+
|
39
|
+
where `<stage>` is server name. Individual stages can be added in `config/deploy/` directory.
|
40
|
+
See default `vagrant` stage for details.
|
41
|
+
|
42
|
+
Use ordinary `cap deploy`-like stuff for later deploys and `cap mana:install` for configuration upgrades.
|
43
|
+
|
44
|
+
Use `cap -T mana` to see useful stuff added after this.
|
45
|
+
|
46
|
+
|
23
47
|
## Contributing
|
24
48
|
|
25
49
|
1. Fork it
|
data/lib/mana/capistrano.rb
CHANGED
@@ -1,40 +1,57 @@
|
|
1
1
|
require 'roundsman/capistrano'
|
2
|
-
require 'capistrano_colors'
|
3
2
|
require 'capistrano/ext/multistage'
|
3
|
+
require 'capistrano/recipes/deploy/strategy/remote_cache'
|
4
|
+
require 'mana/remote_cache_subdir'
|
4
5
|
|
5
6
|
Capistrano::Configuration.default_io_proc = ->(ch, stream, out){
|
6
|
-
next if out.strip.empty?
|
7
|
+
next if out.strip.empty? # skipping extensive blank lines
|
7
8
|
level = stream == :err ? :important : :info
|
8
9
|
ch[:options][:logger].send(level, out.strip, "#{stream} :: #{ch[:server]}")
|
9
10
|
}
|
10
11
|
|
11
12
|
Capistrano::Configuration.instance(:must_exist).load do
|
12
|
-
|
13
|
+
|
13
14
|
# Convinient defaults
|
14
|
-
|
15
|
+
|
15
16
|
set(:deploy_to) { "/opt/#{fetch(:application)}" }
|
16
17
|
set :scm, 'git'
|
17
18
|
set :deploy_via, :remote_cache
|
18
19
|
set :use_sudo, false
|
19
|
-
|
20
|
+
|
20
21
|
default_run_options[:pty] = true
|
21
22
|
ssh_options[:forward_agent] = true
|
22
|
-
|
23
|
+
|
24
|
+
set :strategy, RemoteCacheSubdir.new(self)
|
25
|
+
|
23
26
|
# Roundsman fine-tuning
|
24
27
|
|
25
|
-
set :chef_version, '10.
|
28
|
+
set :chef_version, '~> 10.18.2'
|
26
29
|
set :cookbooks_directory, 'config/deploy/cookbooks'
|
27
|
-
set :stream_roundsman_output, false
|
28
|
-
set :ruby_install_script do
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
set :stream_roundsman_output, false # todo check why is this needed
|
31
|
+
set :ruby_install_script do
|
32
|
+
if fetch(:ruby_version) == :brightbox
|
33
|
+
%Q{
|
34
|
+
apt-get install -y python-software-properties
|
35
|
+
apt-add-repository -y ppa:brightbox/ruby-ng
|
36
|
+
apt-get update
|
37
|
+
apt-get install -y ruby1.9.3
|
38
|
+
gem install bundler
|
39
|
+
}
|
40
|
+
else
|
41
|
+
%Q{
|
42
|
+
set -e
|
43
|
+
cd #{roundsman_working_dir}
|
44
|
+
rm -rf ruby-build
|
45
|
+
git clone -q https://github.com/sstephenson/ruby-build.git
|
46
|
+
cd ruby-build
|
47
|
+
./install.sh
|
48
|
+
CONFIGURE_OPTS='--disable-install-rdoc' ruby-build #{fetch(:ruby_version)} #{fetch(:ruby_install_dir)}
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
36
53
|
# Mana
|
37
|
-
|
54
|
+
|
38
55
|
namespace :mana do
|
39
56
|
desc 'Complete update of all software'
|
40
57
|
task :default do
|
@@ -44,23 +61,23 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
44
61
|
install
|
45
62
|
deploy.migrations
|
46
63
|
end
|
47
|
-
|
64
|
+
|
48
65
|
desc 'Bootstrap chef and ruby'
|
49
66
|
task :bootstrap do
|
50
67
|
roundsman.install.default
|
51
68
|
roundsman.chef.install
|
52
69
|
end
|
53
|
-
|
70
|
+
|
54
71
|
desc 'Install & update software'
|
55
72
|
task :install do
|
56
73
|
roundsman.chef.default
|
57
74
|
end
|
58
|
-
|
75
|
+
|
59
76
|
desc 'Show install log'
|
60
77
|
task :log do
|
61
78
|
sudo "cat /tmp/roundsman/cache/chef-stacktrace.out"
|
62
79
|
end
|
63
|
-
|
80
|
+
|
64
81
|
desc 'Complete setup'
|
65
82
|
task :setup do
|
66
83
|
upgrade
|
@@ -71,28 +88,40 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
71
88
|
deploy.seed
|
72
89
|
sudo 'monit reload'
|
73
90
|
end
|
74
|
-
|
91
|
+
|
75
92
|
desc 'Upgrade software'
|
76
93
|
task :upgrade do
|
77
94
|
sudo "DEBIAN_FRONTEND=noninteractive #{fetch(:package_manager)} -yq update"
|
78
95
|
sudo "DEBIAN_FRONTEND=noninteractive #{fetch(:package_manager)} -yq upgrade"
|
79
96
|
end
|
80
|
-
|
97
|
+
|
81
98
|
desc "Open SSH connection to server"
|
82
99
|
task :ssh do
|
83
100
|
host = roles[:app].servers.first # silly approach
|
84
101
|
exec "ssh -L 3737:localhost:3737 #{fetch(:user)}@#{host}" # forward monit status server port
|
85
102
|
end
|
103
|
+
|
104
|
+
desc "Watch Rails log"
|
105
|
+
task :watchlog do
|
106
|
+
begin
|
107
|
+
run "tail -n 100 -f #{fetch(:shared_path)}/log/#{rails_env}.log", pty: true do |_, stream, data|
|
108
|
+
puts "[#{channel[:host]}][#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}] #{data}"
|
109
|
+
break if stream == :err
|
110
|
+
end
|
111
|
+
rescue Interrupt
|
112
|
+
exit
|
113
|
+
end
|
114
|
+
end
|
86
115
|
end
|
87
|
-
|
116
|
+
|
88
117
|
# More convinience
|
89
|
-
|
118
|
+
|
90
119
|
namespace :deploy do
|
91
120
|
desc 'Update the database with seed data'
|
92
121
|
task :seed, roles: :db, only: {primary: true} do
|
93
122
|
run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}"
|
94
123
|
end
|
95
|
-
|
124
|
+
|
96
125
|
desc "Restart unicorn"
|
97
126
|
task :restart_unicorn, roles: :app, except: {no_release: true} do
|
98
127
|
sudo "service #{fetch(:application)}-web restart"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class RemoteCacheSubdir < Capistrano::Deploy::Strategy::RemoteCache
|
2
|
+
private
|
3
|
+
|
4
|
+
def repository_cache_subdir
|
5
|
+
if configuration[:deploy_subdir] then
|
6
|
+
File.join(repository_cache, configuration[:deploy_subdir])
|
7
|
+
else
|
8
|
+
repository_cache
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_repository_cache
|
13
|
+
logger.trace "copying the cached version to #{configuration[:release_path]}"
|
14
|
+
if copy_exclude.empty?
|
15
|
+
run "cp -RPp #{repository_cache_subdir} #{configuration[:release_path]} && #{mark}"
|
16
|
+
else
|
17
|
+
exclusions = copy_exclude.map { |e| "--exclude=\"#{e}\"" }.join(' ')
|
18
|
+
run "rsync -lrpt #{exclusions} #{repository_cache_subdir}/* #{configuration[:release_path]} && #{mark}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/mana/version.rb
CHANGED
data/mana.gemspec
CHANGED
data/templates/config/deploy.rb
CHANGED
@@ -1,17 +1,35 @@
|
|
1
|
-
|
1
|
+
#TODO: change this to application name
|
2
|
+
set :application, 'application'
|
2
3
|
|
3
|
-
|
4
|
+
#TODO: change this to repository
|
5
|
+
set :repository, 'git@github.com:author/application.git'
|
6
|
+
|
7
|
+
# set :deploy_subdir, ''
|
4
8
|
|
5
9
|
set :default_stage, :vagrant
|
6
10
|
|
11
|
+
# Uses Brightbox Next Generation Ruby Packages
|
12
|
+
# http://wiki.brightbox.co.uk/docs:ruby-ng
|
13
|
+
# by default.
|
14
|
+
# Change to specific version in ruby-build format
|
15
|
+
# if exact version needed.
|
16
|
+
set :ruby_version, :brightbox
|
7
17
|
set :care_about_ruby_version, false
|
8
18
|
|
9
|
-
set :postgresql,
|
19
|
+
set :postgresql,
|
20
|
+
version: '9.1',
|
21
|
+
listen_all: false #TODO: changes this to `true` for TCP connectivity
|
10
22
|
|
11
23
|
set :monit,
|
12
24
|
notify_email: 'admin@application.com', #TODO: change this to your email to receive monit alerts
|
13
25
|
poll_period: 30
|
14
26
|
|
27
|
+
set :railsapp,
|
28
|
+
server_names: '_' #TODO: change this to domain name(s) of the project
|
29
|
+
|
30
|
+
# For other options look into cookbooks/*/attributes/default.rb
|
31
|
+
# and other cookbook sources.
|
32
|
+
|
15
33
|
set :run_list, %w(
|
16
34
|
recipe[monit]
|
17
35
|
recipe[monit::ssh]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: capistrano_colors
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
description: Configuration management with Chef & Capistrano
|
63
47
|
email:
|
64
48
|
- ilia@flamefork.ru
|
@@ -103,6 +87,7 @@ files:
|
|
103
87
|
- lib/mana.rb
|
104
88
|
- lib/mana/capistrano.rb
|
105
89
|
- lib/mana/railtie.rb
|
90
|
+
- lib/mana/remote_cache_subdir.rb
|
106
91
|
- lib/mana/version.rb
|
107
92
|
- lib/tasks/mana.rake
|
108
93
|
- mana.gemspec
|