Skip to content

Commit

Permalink
Merged change fb246415-a7a1-4e85-8b1a-702a623769ba
Browse files Browse the repository at this point in the history
From review branch _reviews/master/mjohno-master/3 into master

Signed-off-by: mcquinc <claire@chef.io>

Reviewed-by: afiunes <afiunes@getchef.com>
Reviewed-by: duffieldt <tom@getchef.com>
Reviewed-by: jmink <jmink@getchef.com>
Reviewed-by: mcquinc <claire@chef.io>
  • Loading branch information
Delivery Server committed Nov 13, 2015
2 parents 9942805 + 69f178c commit d4ef22c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ should have a key named git)
}
```

### deploy
By default deploy will trigger a `chef-client` run thought push-jobs to all
the nodes that belong to the current environment in delivery and have the
modified cookbook(s) in their run_list. You can customize the search query.

```json
{
"delivery-truck": {
"deploy": {
"search": "recipes:my_push_jobs"
}
}
}
```

## Skipped Phases
The following phases have no content and can be skipped: functional,
quality, security and smoke.
Expand Down
16 changes: 16 additions & 0 deletions libraries/helpers_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ module Helpers
module Deploy
extend self

# Read the Delivery Config to see if the user has indicated an
# specific deployment search query to use
#
# @param [Chef::Node] Chef Node object
# @return [String] The deployment search query
def deployment_search_query(node)
node['delivery']['config']['delivery-truck']['deploy']['search']
rescue
'recipes:*push-jobs*'
end

def delivery_chef_server_search(type, query)
results = []
DeliverySugar::ChefServer.new.with_server_config do
Expand All @@ -34,5 +45,10 @@ module DSL
def delivery_chef_server_search(type, query)
DeliveryTruck::Helpers::Deploy.delivery_chef_server_search(type, query)
end

# Check config.json to get deployment search query
def deployment_search_query
DeliveryTruck::Helpers::Deploy.deployment_search_query(node)
end
end
end
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license 'Apache 2.0'
description 'Delivery build_cookbook for your cookbooks!'

version '1.100.8'
version '1.100.9'

source_url 'https://github.com/chef-cookbooks/delivery-truck'
issues_url 'https://github.com/chef-cookbooks/delivery-truck/issues'
Expand Down
2 changes: 1 addition & 1 deletion recipes/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
unless search_terms.empty?
search_query = "(#{search_terms.join(' OR ')}) " \
"AND chef_environment:#{delivery_environment} " \
"AND recipes:push-jobs*"
"AND #{deployment_search_query}"

my_nodes = delivery_chef_server_search(:node, search_query)

Expand Down
21 changes: 21 additions & 0 deletions spec/unit/libraries/helpers_deploy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

describe DeliveryTruck::Helpers::Deploy do
let(:node) { Chef::Node.new }

describe '.deployment_search_query' do
context 'when config value is unset' do
it 'returns default search query' do
expect(described_class.deployment_search_query(node)).to eql('recipes:*push-jobs*')
end
end

context 'when config value is set' do
let(:custom_search){ 'cool:attributes OR awful:constraints' }
it 'returns the custom search query' do
node.default['delivery']['config']['delivery-truck']['deploy']['search'] = custom_search
expect(described_class.deployment_search_query(node)).to eql(custom_search)
end
end
end
end
22 changes: 21 additions & 1 deletion spec/unit/recipes/deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def initialize(name)
end

let(:search_query) do
"(#{recipe_list}) AND chef_environment:union AND recipes:push-jobs*"
"(#{recipe_list}) AND chef_environment:union AND recipes:*push-jobs*"
end
let(:node_list) { [MyFakeNode.new("node1"), MyFakeNode.new("node2")] }

Expand All @@ -52,6 +52,26 @@ def initialize(name)
:nodes => node_list
)
end

context "and the user sets a different search query" do
before do
allow(DeliveryTruck::Helpers::Deploy).to receive(:deployment_search_query)
.and_return('recipes:my_cool_push_jobs_cookbook AND more:constraints')
end
let(:search_query) do
"(#{recipe_list}) AND chef_environment:union AND recipes:my_cool_push_jobs_cookbook AND more:constraints"
end
it "deploy only that cookbook with the special search query" do
expect(DeliveryTruck::Helpers::Deploy).to receive(:delivery_chef_server_search)
.with(:node, search_query)
.and_return(node_list)
expect(chef_run).to run_ruby_block('update the union environment')
expect(chef_run).to dispatch_delivery_push_job("deploy_Secret").with(
:command => 'chef-client',
:nodes => node_list
)
end
end
end

context "when multiple cookbooks have been modified" do
Expand Down

0 comments on commit d4ef22c

Please sign in to comment.