alpha_omega 1.5.7 → 1.5.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/alpha_omega/utils.rb +2 -3
- data/libexec/aohelper +96 -5
- data/libexec/aohelper.template +96 -5
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.8
|
data/lib/alpha_omega/utils.rb
CHANGED
@@ -13,7 +13,6 @@ $node_filter = nil
|
|
13
13
|
module AlphaOmega
|
14
14
|
def self.node_defaults(node, env_pod, node_name)
|
15
15
|
node_name = node_name.split(".").first
|
16
|
-
|
17
16
|
node["node_name"] = node_name
|
18
17
|
|
19
18
|
# defaults
|
@@ -29,6 +28,7 @@ module AlphaOmega
|
|
29
28
|
|
30
29
|
# enrich with opsdb
|
31
30
|
node.deep_merge!($opsdb[env_pod][node_name]) if $opsdb[env_pod].key? node_name
|
31
|
+
node.deep_merge!($opsdb[env_pod][:nodes][node_name]) if $opsdb[env_pod].key?(:nodes) && $opsdb[env_pod][:nodes].key?(node_name)
|
32
32
|
|
33
33
|
node["run_list"] = node["run_list"].clone # TODO without a clone, node.run_list also updates pods_config.env_pod.run_list
|
34
34
|
|
@@ -164,8 +164,7 @@ module AlphaOmega
|
|
164
164
|
config.set :current_pod, $this_pod
|
165
165
|
|
166
166
|
this_host = ENV['_AO_THIS_HOST'] || Socket.gethostname.chomp.split(".")[0]
|
167
|
-
|
168
|
-
dna = YAML.load(File.read("#{dna_base}.yaml"))
|
167
|
+
dna = YAML.load(File.read("#{node_home}/pods/#{$this_pod}/#{this_host}.yaml"))
|
169
168
|
this_node = self.node_defaults(dna, $this_pod, this_host)
|
170
169
|
$this_host = this_node
|
171
170
|
|
data/libexec/aohelper
CHANGED
@@ -1,30 +1,121 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
+
set -e
|
3
4
|
shome="$(cd -P -- "$(dirname -- "$BASH_SOURCE")/.." && pwd -P)"
|
4
5
|
|
5
6
|
function ryaml {
|
6
|
-
ruby -ryaml -e '
|
7
|
+
ruby -ryaml -e '
|
8
|
+
def ps x
|
9
|
+
unless x.nil?
|
10
|
+
puts (x.class == String || x.class == Fixnum) ? x : x.to_yaml
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
ps ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[acc.class == Array ? key.to_i : key] }
|
15
|
+
|
16
|
+
' "$@" 2>&-
|
17
|
+
}
|
18
|
+
|
19
|
+
function verify_ruby {
|
20
|
+
local ruby_runner="$*";
|
21
|
+
|
22
|
+
# verify ruby version matches deploy descriptor
|
23
|
+
local ruby_version_platform="$($ruby_runner ruby -e 'puts "#{RUBY_VERSION} #{RUBY_PLATFORM}"' 2>&-)"
|
24
|
+
local version_ruby="${ruby_version_platform%% *}"
|
25
|
+
local platform_ruby="${ruby_version_platform##* }"
|
26
|
+
|
27
|
+
if [[ -n "$app_ruby_version" ]]; then
|
28
|
+
if [[ "$version_ruby" != "$app_ruby_version" ]]; then
|
29
|
+
return 1
|
30
|
+
fi
|
31
|
+
fi
|
32
|
+
|
33
|
+
if [[ -n "$app_ruby_platform" ]]; then
|
34
|
+
if [[ "$platform_ruby" != "$app_ruby_platform" ]]; then
|
35
|
+
return 1
|
36
|
+
fi
|
37
|
+
fi
|
38
|
+
|
39
|
+
if [[ -n "$not_app_ruby_platform" ]]; then
|
40
|
+
if [[ "$platform_ruby" = "$not_app_ruby_platform" ]]; then
|
41
|
+
return 1
|
42
|
+
fi
|
43
|
+
fi
|
44
|
+
}
|
45
|
+
|
46
|
+
function fatal_ruby {
|
47
|
+
local ruby_loader="$*"
|
48
|
+
: ${ruby_loader:=ruby}
|
49
|
+
|
50
|
+
echo "Expecting $ruby_loader to have:" 1>&2
|
51
|
+
if [[ -n "$app_ruby_version" ]]; then
|
52
|
+
echo " version $app_ruby_version" 1>&2
|
53
|
+
fi
|
54
|
+
|
55
|
+
if [[ -n "$app_ruby_platform" ]]; then
|
56
|
+
echo " platform $app_ruby_platform" 1>&2
|
57
|
+
fi
|
58
|
+
|
59
|
+
if [[ -n "$not_app_ruby_platform" ]]; then
|
60
|
+
echo " not platform $not_app_ruby_platform" 1>&2
|
61
|
+
|
62
|
+
fi
|
63
|
+
|
64
|
+
exit 1
|
7
65
|
}
|
8
66
|
|
9
67
|
function main {
|
68
|
+
# load ruby configuration from deploy descriptor
|
10
69
|
local app_ruby="$(ryaml $shome/config/deploy.yml app_ruby)"
|
70
|
+
local app_ruby_version="$(ryaml $shome/config/deploy.yml app_ruby_version)"
|
71
|
+
local app_ruby_platform="$(ryaml $shome/config/deploy.yml app_ruby_platform)"
|
72
|
+
local not_app_ruby_platform="$(ryaml $shome/config/deploy.yml not_app_ruby_platform)"
|
11
73
|
local ruby_loader="$(ryaml $shome/config/deploy.yml ruby_loader)"
|
12
74
|
local ruby_runner="$ruby_loader $app_ruby"
|
13
|
-
|
75
|
+
local chef_path="$(ryaml $shome/config/deploy.yml chef_path)"
|
14
76
|
|
77
|
+
# if ruby loader is rvm-exec, try to find it
|
15
78
|
if [[ "$ruby_loader" = "rvm-exec" ]]; then
|
79
|
+
PATH="$PATH:/usr/local/rvm/bin:$HOME/.rvm/bin"
|
16
80
|
local pth_rvm="$(type -f $ruby_loader 2>&- | awk '{print $3}')"
|
17
|
-
if [[ -x "$pth_rvm" ]]; then
|
81
|
+
if [[ ! -x "$pth_rvm" ]]; then
|
82
|
+
# if rvm-exec not found, don't both with ruby version management
|
83
|
+
ruby_runner=""
|
84
|
+
fi
|
85
|
+
fi
|
86
|
+
|
87
|
+
if [[ ! -d "$chef_path" ]]; then
|
88
|
+
# proxied deploy, so relax rvm rquirements, just check current ruby
|
89
|
+
if verify_ruby; then
|
90
|
+
# current ruby is OK
|
91
|
+
ruby_runner=""
|
18
92
|
true
|
19
93
|
else
|
20
|
-
ruby_runner
|
94
|
+
if [[ -n "$ruby_runner" ]]; then
|
95
|
+
# check with configured ruby loader
|
96
|
+
if ! verify_ruby "$ruby_runner"; then
|
97
|
+
# ruby loader is not loading the right ruby
|
98
|
+
fatal_ruby $ruby_runner
|
99
|
+
fi
|
100
|
+
else
|
101
|
+
# no configured ruby loader, current ruby is not loading the right ruby
|
102
|
+
fatal_ruby
|
103
|
+
fi
|
104
|
+
fi
|
105
|
+
else
|
106
|
+
# in operations environments, must use ruby loader
|
107
|
+
if !verify_ruby "$ruby_runner"; then
|
108
|
+
# ruby loader is not loading the right ruby
|
109
|
+
fatal_ruby $ruby_runner
|
21
110
|
fi
|
22
111
|
fi
|
23
112
|
|
24
113
|
if ! $ruby_runner bundle check 2>&- > /dev/null; then
|
25
114
|
$ruby_runner bundle install --local --quiet --path vendor/bundle
|
26
115
|
fi
|
27
|
-
|
116
|
+
|
117
|
+
# pass deploy command and arguments to ao script in alpha_omega gem
|
118
|
+
echo $ruby_runner bundle exec ao "${BASH_SOURCE##*/}" "$@"
|
28
119
|
}
|
29
120
|
|
30
121
|
main "$@"
|
data/libexec/aohelper.template
CHANGED
@@ -1,30 +1,121 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
+
set -e
|
3
4
|
shome="$(cd -P -- "$(dirname -- "$BASH_SOURCE")/.." && pwd -P)"
|
4
5
|
|
5
6
|
function ryaml {
|
6
|
-
ruby -ryaml -e '
|
7
|
+
ruby -ryaml -e '
|
8
|
+
def ps x
|
9
|
+
unless x.nil?
|
10
|
+
puts (x.class == String || x.class == Fixnum) ? x : x.to_yaml
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
ps ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[acc.class == Array ? key.to_i : key] }
|
15
|
+
|
16
|
+
' "$@" 2>&-
|
17
|
+
}
|
18
|
+
|
19
|
+
function verify_ruby {
|
20
|
+
local ruby_runner="$*";
|
21
|
+
|
22
|
+
# verify ruby version matches deploy descriptor
|
23
|
+
local ruby_version_platform="$($ruby_runner ruby -e 'puts "#{RUBY_VERSION} #{RUBY_PLATFORM}"' 2>&-)"
|
24
|
+
local version_ruby="${ruby_version_platform%% *}"
|
25
|
+
local platform_ruby="${ruby_version_platform##* }"
|
26
|
+
|
27
|
+
if [[ -n "$app_ruby_version" ]]; then
|
28
|
+
if [[ "$version_ruby" != "$app_ruby_version" ]]; then
|
29
|
+
return 1
|
30
|
+
fi
|
31
|
+
fi
|
32
|
+
|
33
|
+
if [[ -n "$app_ruby_platform" ]]; then
|
34
|
+
if [[ "$platform_ruby" != "$app_ruby_platform" ]]; then
|
35
|
+
return 1
|
36
|
+
fi
|
37
|
+
fi
|
38
|
+
|
39
|
+
if [[ -n "$not_app_ruby_platform" ]]; then
|
40
|
+
if [[ "$platform_ruby" = "$not_app_ruby_platform" ]]; then
|
41
|
+
return 1
|
42
|
+
fi
|
43
|
+
fi
|
44
|
+
}
|
45
|
+
|
46
|
+
function fatal_ruby {
|
47
|
+
local ruby_loader="$*"
|
48
|
+
: ${ruby_loader:=ruby}
|
49
|
+
|
50
|
+
echo "Expecting $ruby_loader to have:" 1>&2
|
51
|
+
if [[ -n "$app_ruby_version" ]]; then
|
52
|
+
echo " version $app_ruby_version" 1>&2
|
53
|
+
fi
|
54
|
+
|
55
|
+
if [[ -n "$app_ruby_platform" ]]; then
|
56
|
+
echo " platform $app_ruby_platform" 1>&2
|
57
|
+
fi
|
58
|
+
|
59
|
+
if [[ -n "$not_app_ruby_platform" ]]; then
|
60
|
+
echo " not platform $not_app_ruby_platform" 1>&2
|
61
|
+
|
62
|
+
fi
|
63
|
+
|
64
|
+
exit 1
|
7
65
|
}
|
8
66
|
|
9
67
|
function main {
|
68
|
+
# load ruby configuration from deploy descriptor
|
10
69
|
local app_ruby="$(ryaml $shome/config/deploy.yml app_ruby)"
|
70
|
+
local app_ruby_version="$(ryaml $shome/config/deploy.yml app_ruby_version)"
|
71
|
+
local app_ruby_platform="$(ryaml $shome/config/deploy.yml app_ruby_platform)"
|
72
|
+
local not_app_ruby_platform="$(ryaml $shome/config/deploy.yml not_app_ruby_platform)"
|
11
73
|
local ruby_loader="$(ryaml $shome/config/deploy.yml ruby_loader)"
|
12
74
|
local ruby_runner="$ruby_loader $app_ruby"
|
13
|
-
|
75
|
+
local chef_path="$(ryaml $shome/config/deploy.yml chef_path)"
|
14
76
|
|
77
|
+
# if ruby loader is rvm-exec, try to find it
|
15
78
|
if [[ "$ruby_loader" = "rvm-exec" ]]; then
|
79
|
+
PATH="$PATH:/usr/local/rvm/bin:$HOME/.rvm/bin"
|
16
80
|
local pth_rvm="$(type -f $ruby_loader 2>&- | awk '{print $3}')"
|
17
|
-
if [[ -x "$pth_rvm" ]]; then
|
81
|
+
if [[ ! -x "$pth_rvm" ]]; then
|
82
|
+
# if rvm-exec not found, don't both with ruby version management
|
83
|
+
ruby_runner=""
|
84
|
+
fi
|
85
|
+
fi
|
86
|
+
|
87
|
+
if [[ ! -d "$chef_path" ]]; then
|
88
|
+
# proxied deploy, so relax rvm rquirements, just check current ruby
|
89
|
+
if verify_ruby; then
|
90
|
+
# current ruby is OK
|
91
|
+
ruby_runner=""
|
18
92
|
true
|
19
93
|
else
|
20
|
-
ruby_runner
|
94
|
+
if [[ -n "$ruby_runner" ]]; then
|
95
|
+
# check with configured ruby loader
|
96
|
+
if ! verify_ruby "$ruby_runner"; then
|
97
|
+
# ruby loader is not loading the right ruby
|
98
|
+
fatal_ruby $ruby_runner
|
99
|
+
fi
|
100
|
+
else
|
101
|
+
# no configured ruby loader, current ruby is not loading the right ruby
|
102
|
+
fatal_ruby
|
103
|
+
fi
|
104
|
+
fi
|
105
|
+
else
|
106
|
+
# in operations environments, must use ruby loader
|
107
|
+
if !verify_ruby "$ruby_runner"; then
|
108
|
+
# ruby loader is not loading the right ruby
|
109
|
+
fatal_ruby $ruby_runner
|
21
110
|
fi
|
22
111
|
fi
|
23
112
|
|
24
113
|
if ! $ruby_runner bundle check 2>&- > /dev/null; then
|
25
114
|
$ruby_runner bundle install --local --quiet --path vendor/bundle
|
26
115
|
fi
|
27
|
-
|
116
|
+
|
117
|
+
# pass deploy command and arguments to ao script in alpha_omega gem
|
118
|
+
echo $ruby_runner bundle exec ao "${BASH_SOURCE##*/}" "$@"
|
28
119
|
}
|
29
120
|
|
30
121
|
main "$@"
|