baptize 0.1.1 → 0.1.2

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: 6a940dc1a55b7aa62c6b41fe6134e36024d4e713
4
- data.tar.gz: 2ef97b29ab2151e6d59b7a31ed2c2648189a594d
3
+ metadata.gz: 11dedf7433eb9c33188a68b80a8d1b79b1a9bf1f
4
+ data.tar.gz: 5af048e9e82eeafa942d46194b2cc77c72ccf089
5
5
  SHA512:
6
- metadata.gz: 4ffae4ac6b4ccd2101d465e0aef62134768a05c3ce1e64227871d636ac53c471154d2f374c254f7d50c75acc5e4d3e18302109149e341166fa3fc3af5187c33d
7
- data.tar.gz: 28b85c6a1f3a1038d0b462084544d7a564be7b99f968ebbb853dea98a361cdb0264a4bf0f4f2fa792914974113a98b306b40099ddbb239185dc211f497761c12
6
+ metadata.gz: 2da09b4fb58133cfa2756fbd78aaf06c67bb99f4aa6fa426f38f938dc8ec5c1eb6e8ac0bd133ef41bccc518195aaf80bd3a2f2de43544248f8fec0a62fca5998
7
+ data.tar.gz: 1c4a577daa8bf401a315587cc610e08957dffad5903ed520596879e7063d7adf32a9d9e1a323bea4985f107085b35e0b6798b1876cea3e098fbcc453b28c99ca
data/README.markdown CHANGED
@@ -3,129 +3,4 @@ Baptize
3
3
 
4
4
  Baptize is an extension for Capistrano, that allows for server provisioning. The API resembles [Sprinkle](https://github.com/sprinkle-tool/sprinkle), but the underlying implementation is quite different. Where Sprinkle tries to compile a static payload of commands and push to the server, Baptize is executed in runtime. It also reuses much more of Capistrano, than Sprinkle does. Basically, each Baptize package is a capistrano task - Baptize just adds some helpers and fancy dsl on top, to make it look declarative.
5
5
 
6
- Be warned that Baptize is less than a week old at the time of this writing, and it has no test coverage - so it's probably riddled with bugs. That said, I do eat my own dog food, so it's at least somewhat functional.
7
-
8
- Setup
9
- ---
10
-
11
- At some point, I'll probably wrap this procedure in a generator, but for now you'll have to do so manually.
12
-
13
- To get started, create a `Gemfile`:
14
-
15
- ```ruby
16
- source 'https://rubygems.org'
17
- gem 'capistrano', '~> 2.15'
18
- gem 'baptize'
19
- ```
20
-
21
- And a `Capfile`:
22
-
23
- ```ruby
24
- require 'bundler'
25
- require 'capistrano'
26
- require 'baptize'
27
- load_configuration :roles
28
- Dir.glob("#{capistrano_path}/packages/**/*.rb").each do |package|
29
- load(package)
30
- end
31
- Dir.glob("#{capistrano_path}/recipes/**/*.rb").each do |recipe|
32
- load(recipe)
33
- end
34
- ```
35
-
36
- And a couple of folders and files:
37
-
38
- ./capistrano/
39
- ./capistrano/config/
40
- ./capistrano/config/roles.rb # Globally applied configuration. Define roles here.
41
- ./capistrano/config/baptize.rb # Contains config files used by baptize packages. Define policies here.
42
- ./capistrano/packages/ # Put package definitions in here.
43
- ./capistrano/recipes/ # Put regular capistrano tasks in here.
44
- ./capistrano/assets/ # Place auxiliary files here.
45
-
46
- And Finally, run the following command:
47
-
48
- bundle
49
-
50
- Sample configuration
51
- ---
52
-
53
- First define some roles, by opening up `config/roles.rb` - This is just regular Capistrano stuff. For example:
54
-
55
- ```ruby
56
- role :server, "192.168.1.1"
57
- ```
58
-
59
- Next define a policy for the server. Open up `config/baptize.rb` and put this:
60
-
61
- ```ruby
62
- policy :server do
63
- requires :system_update
64
- end
65
- ```
66
-
67
- This defines that the role `:server` needs a package `system_update`.
68
-
69
- You probably should define which login credentials to use as well:
70
-
71
- ```ruby
72
- # ssh login user
73
- set :user, 'ubuntu'
74
- # ssh key location
75
- ssh_options[:keys] = '~/.ssh/aws-key.pem'
76
- # run commands through sudo
77
- set :use_sudo, true
78
- ```
79
-
80
- Note that since this is defined inside `config/baptize.rb`, it won't apply to capistrano recipes outside of baptize. The roles, on the other hand, is globally loaded (That happens in the `Capfile`).
81
-
82
- Better create that packages then. Open up `packages/system_update.rb`:
83
-
84
- ```ruby
85
- package :system_update do
86
- description "System Update"
87
- install do
88
- run 'apt-get update -y'
89
- run 'apt-get upgrade -y'
90
- end
91
- end
92
- ```
93
-
94
- This defines a package, that will upgrade the apt package manager of the target system.
95
-
96
- Deploying policies
97
- ---
98
-
99
- You can now run the following command:
100
-
101
- cap baptize
102
-
103
- Which should make capistrano ssh in to the `:server` role and try to update apt. It'll probably fail, unless you actually have a server running at that IP.
104
-
105
- If you want to just configure a single role, you can do so by running:
106
-
107
- cap baptize:policies:server
108
-
109
- Using Baptize alongside Capistrano
110
- ---
111
-
112
- If you also want to use Capistrano for regular application deployment (what it's actually ment for), you might want to create a file in `config/deploy.rb` to hold settings for this. E.g.:
113
-
114
- ```ruby
115
- set :application, "set your application name here"
116
- set :repository, "set your repository location here"
117
- ```
118
-
119
- And to make sure it is loaded, modify your `Capfile` to include:
120
-
121
- ```ruby
122
- load 'deploy'
123
- load 'deploy/assets' # For using Rails' asset pipeline
124
- before 'deploy' do
125
- load_configuration :deploy
126
- end
127
- ```
128
-
129
- ---
130
-
131
- TODO: There is more to Baptize, but that'll have to wait for now.
6
+ For now, there is virtually no documentation. Have a peek at `sample/` for an idea of how it works.
@@ -17,8 +17,18 @@ module Baptize
17
17
  def execute
18
18
  unless @registry.packages_executed.include? full_name
19
19
  @registry.packages_executed << full_name
20
- @registry.before(self).each do |task|
21
- task.call
20
+ logger.info "Resolving dependencies for #{name}"
21
+ @registry.before(self).each do |dependency|
22
+ logger.debug "--> #{dependency}"
23
+ @registry.resolve_dependency(dependency).tap do |task|
24
+ task.call
25
+ end
26
+ end
27
+ @dependencies.each do |dependency|
28
+ logger.debug "--> #{dependency}"
29
+ @registry.resolve_dependency(dependency).tap do |task|
30
+ task.call
31
+ end
22
32
  end
23
33
  instance_eval(&before_block) if self.before_block
24
34
  if verify_block
@@ -49,8 +59,10 @@ module Baptize
49
59
  logger.info "Nothing to do for package #{name}"
50
60
  end
51
61
  instance_eval(&after_block) if after_block
52
- @registry.after(self).each do |task|
53
- task.call
62
+ @registry.after(self).each do |dependency|
63
+ @registry.resolve_dependency(dependency).tap do |task|
64
+ task.call
65
+ end
54
66
  end
55
67
  end
56
68
  end
@@ -44,11 +44,11 @@ module Baptize
44
44
  SSHKit.config.output_verbosity = Logger::DEBUG
45
45
  end
46
46
  begin
47
- if fetch(:use_sudo)
48
- ssh.send(action, :sudo, *args)
49
- else
50
- ssh.send(action, *args)
47
+ if fetch(:use_bash)
48
+ args = ["bash -c " + args.join(" ; ").shellescape]
51
49
  end
50
+ args.unshift(:sudo) if fetch(:use_sudo)
51
+ ssh.send(action, *args)
52
52
  ensure
53
53
  SSHKit.config.output_verbosity = old_verbosity if old_verbosity
54
54
  end
@@ -32,9 +32,7 @@ module Baptize
32
32
  @befores ||= {}
33
33
  @befores[subject_name] ||= []
34
34
  if other_task
35
- task = packages[other_task] if other_task.kind_of?(String)
36
- raise "Didn't find a package by that name" if task.nil?
37
- @befores[subject_name] << task.method(:execute)
35
+ @befores[subject_name] << other_task
38
36
  elsif block_given?
39
37
  @befores[subject_name] << block
40
38
  end
@@ -45,15 +43,25 @@ module Baptize
45
43
  @afters ||= {}
46
44
  @afters[subject_name] ||= []
47
45
  if other_task
48
- task = packages[other_task] if other_task.kind_of?(String)
49
- raise "Didn't find a package by that name" if task.nil?
50
- @afters[subject_name] << task.method(:execute)
46
+ @afters[subject_name] << other_task
51
47
  elsif block_given?
52
48
  @afters[subject_name] << block
53
49
  end
54
50
  @afters[subject_name]
55
51
  end
56
52
 
53
+ def self.resolve_dependency(mixed)
54
+ if mixed.kind_of?(String) || mixed.kind_of?(Symbol)
55
+ task = packages[mixed.to_s]
56
+ raise "Didn't find a package by that name: '#{mixed}'" if task.nil?
57
+ task.method(:execute)
58
+ elsif mixed.kind_of? PackageDefinition
59
+ mixed.method(:execute)
60
+ else
61
+ mixed
62
+ end
63
+ end
64
+
57
65
  def self.define_package(package_name, &config_block)
58
66
  package = PackageDefinition.new(package_name, self.execution_scope, self)
59
67
  packages[package.full_name] = package
@@ -1,3 +1,3 @@
1
1
  module Baptize
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end # module Baptize
data/lib/baptize.rb CHANGED
@@ -25,4 +25,5 @@ extend Baptize::DSL
25
25
  set_if_empty :logger, Proc.new { Baptize::Registry.logger }
26
26
  set_if_empty :dry_run, true
27
27
  set_if_empty :use_sudo, true
28
+ set_if_empty :use_bash, true
28
29
  set_if_empty :ssh_verbose, !!ENV['VERBOSE']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baptize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Troels Knak-Nielsen