Showing with 17 additions and 7 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 manifests/config.pp
  3. +6 −2 templates/r10k.yaml.erb
  4. +8 −5 templates/webhook.erb
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pkg
spec/fixtures/
spec/fixtures/manifests/site.pp
.DS_Store
*.swp
2 changes: 2 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@
'basedir' => $r10k_basedir,
},
}
$source_keys = keys($r10k_sources)
} else {
validate_hash($sources)

$r10k_sources = $sources
$source_keys = keys($r10k_sources)
}

file { 'r10k.yaml':
Expand Down
8 changes: 6 additions & 2 deletions templates/r10k.yaml.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
:cachedir: <%= @cachedir %>
<% unless @r10k_sources.empty? -%>
:sources:
<%# The splitting/joining monkeybusiness trims the YAML document header: `---` -%>
<%= @r10k_sources.to_yaml.split("\n")[1..-1].join("\n") %>
<% @source_keys.sort.each do |source| -%>
<%=source-%>:
<% @r10k_sources[source].sort.each do |key,value| -%>
<%=key-%>: "<%=value%>"
<% end -%>
<% end -%>
<% end %>
<%# The Array boxing/flattening ensures we don't get bitten by bug #15813 -%>
<% unless [@purgedirs].flatten.empty? -%>
Expand Down
13 changes: 8 additions & 5 deletions templates/webhook.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ class Server < Sinatra::Base
raise Sinatra::NotFound
end

post '/deploy' do
post '/payload' do
protected!
deploy()
request.body.rewind # in case someone already read it
data = JSON.parse request.body.read
branch = data['ref'].split("/").last
deploy(branch)
end

not_found do
Expand All @@ -66,7 +69,7 @@ class Server < Sinatra::Base
if USE_MCO
mco()
else
Process.detach(fork{ exec "#{DEPLOYCMD} &"}
Process.detach(fork{ exec "#{DEPLOYCMD} &"})
end
{:status => :success, :message => "Deploying environments."}.to_json
rescue
Expand All @@ -80,7 +83,7 @@ class Server < Sinatra::Base
client = rpcclient('r10k', :exit_on_failure => false,:options => options)
client.discovery_timeout = DISCOVER_TIMEOUT
client.timeout = CLIENT_TIMEOUT
result = client.send('sync',{})
result = client.send('deploy',branch)
end # end deploy()


Expand All @@ -93,7 +96,7 @@ class Server < Sinatra::Base

def authorized?
@auth ||= Rack::Auth::Basic::Request.new(request.env)
@auth.provided? && @auth.basic? && @auth.credentials &&
@auth.provided? && @auth.basic? && @auth.credentials &&
@auth.credentials == [USER, PASS]
end #end authorized?
end #end helpers
Expand Down