Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: LISA conference hacking #88

Merged
merged 10 commits into from
Dec 11, 2014
16 changes: 9 additions & 7 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ provisioner:
name: chef_zero

platforms:
- name: ubuntu-12.04
- name: ubuntu-14.04
- name: ubuntu-12.04
- name: ubuntu-10.04
- name: centos-7.0
- name: centos-6.5
attributes:
golang:
install_dir: '/usr'
- name: centos-5.10
run_list:
- recipe[yum-repoforge::default]
attributes:
golang:
install_dir: '/usr'

suites:
- name: default
Expand All @@ -29,6 +25,12 @@ suites:
bind_interface: eth0
advertise_interface: eth0
encrypt: CGXC2NsXW4AvuB4h5ODYzQ==
- name: source
run_list:
- recipe[consul::default]
attributes:
consul:
install_method: source
- name: runit
run_list:
- recipe[consul::default]
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# 0.5.0
<<<<<<< HEAD
# 0.6.0
* Add support for TLS, and gossip encryption

New features:
- Add [Chef Provisioning][7] recipe for bootstrapping a cluster.
- Add LWRP for defining [an event watch][8] (thanks [@ericfode][9]

# 0.4.4
* Adds server list to a consul instance running as a cluster with a `bootstrap_expect` value greater than one.

Expand Down Expand Up @@ -56,3 +61,6 @@ Source and binary installation recipes.
[4]: http://acrmp.github.io/foodcritic/
[5]: https://github.com/romesh-mccullough
[6]: https://github.com/bbatsov/rubocop
[7]: https://github.com/opscode/chef-provisioning
[8]: http://www.consul.io/docs/commands/watch.html
[9]: https://github.com/ericfode
45 changes: 32 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ consul-cookbook
[![Build Status](http://img.shields.io/travis/johnbellone/consul-cookbook.svg)][5]
[![Code Coverage](http://img.shields.io/coveralls/johnbellone/consul-cookbook.svg)][6]

Installs and configures [Consul][1].
Installs and configures [Consul][1] client, server and UI.

## Supported Platforms

- CentOS 5.10, 6.5, 7.0
- RHEL 5.10, 6.5, 7.0
- Ubuntu 12.04, 14.04
- Ubuntu 10.04, 12.04, 14.04

## Attributes

Expand Down Expand Up @@ -331,14 +331,31 @@ Following attributes, if exist in the [encrypted databag][7], override the node
</table>

## Usage
The easiest way to bootstrap a cluster is to use the cluster recipe
and use [Chef provisioning][8] which is a relatively new
extension. This extension allows you to use any driver and easily
stand up a cluster. Once the [Chef Development Kit][9] has been
installed you can run the following command to provision a cluster.

```ruby
gem install chef-provisioning chef-provisioning-fog
export CHEF_DRIVER=fog:AWS
chef-client -z cluster.rb
```

### consul::default
Please follow the [Chef provisioning README][10] which provides more
detailed information about provisioning. You'll need to configure
your credentials prior to provisioning.

This uses the binary installation recipe by default. It also starts consul at boot time.
### consul::default
The default recipe will install the Consul agent using the
`consul::install_binary` recipe. It will also configure and
start consul at the machine boot.

### consul::install_binary

Include `consul::install_binary` in your node's `run_list`:
If you only wish to simply install the binary from the official
mirror you simply include `consul::install_binary` in your node's
`run_list`:

```json
{
Expand All @@ -349,8 +366,10 @@ Include `consul::install_binary` in your node's `run_list`:
```

### consul::install_source

Include `consul::install_source` in your node's `run_list`:
Instead if you wish to install Consul from source you simply need
to include `consul::install_source` in your node's `run_list`. This
will also configure the Go language framework on the node to build
the application.

```json
{
Expand All @@ -361,10 +380,8 @@ Include `consul::install_source` in your node's `run_list`:
```

### consul::ui

This installs the UI into a specified directory.

Include `consul::ui` in your node's `run_list`:
Installing the separate Consul UI simply requires you to include
the `consul::ui` recipe in your node's `run_list`.

```json
{
Expand Down Expand Up @@ -440,4 +457,6 @@ Created and maintained by [John Bellone][3] [@johnbellone][2] (<jbellone@bloombe
[5]: http://travis-ci.org/johnbellone/consul-cookbook
[6]: https://coveralls.io/r/johnbellone/consul-cookbook
[7]: https://docs.getchef.com/essentials_data_bags.html

[8]: https://github.com/opscode/chef-provisioning
[9]: https://github.com/opscode/chef-dk
[10]: https://github.com/opscode/chef-provisioning/blob/master/README.md
2 changes: 1 addition & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

default['consul']['base_url'] = 'https://dl.bintray.com/mitchellh/consul/'
default['consul']['base_url'] = "https://dl.bintray.com/mitchellh/consul/%{version}.zip"
default['consul']['version'] = '0.4.1'
default['consul']['install_method'] = 'binary'
default['consul']['install_dir'] = '/usr/local/bin'
Expand Down
37 changes: 37 additions & 0 deletions cluster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Copyright 2014 John Bellone <jbellone@bloomberg.net>
# Copyright 2014 Bloomberg Finance L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
num_quorum = ENV.fetch('CONSUL_QUORUM', 3)

batch = machine_batch do
1.upto(num_quorum).each do |index|
machine "consul-#{index}" do
recipe 'consul::default'
attributes(consul: { service_mode: 'cluster' })
end
end
end

include_recipe 'chef-sugar::default'
node.default['consul']['servers'] = batch.machines.each { |m| best_ip_for(m.node) }

machine 'consul-ui' do
recipe 'consul::ui'
attributes(consul: {
service_mode: 'client',
servers: node['consul']['servers']
})
end
7 changes: 5 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
maintainer 'John Bellone'
maintainer_email 'jbellone@bloomberg.net'
license 'Apache v2.0'
description 'Installs/Configures consul'
long_description 'Installs/Configures consul'
description 'Installs/Configures Consul client, server and UI.'
long_description 'Installs/Configures Consul client, server and UI.'
version '0.6.0'

recipe 'consul', 'Installs and starts consul service.'
Expand All @@ -17,9 +17,12 @@
supports name, '~> 5.10'
end

supports 'ubuntu', '= 10.04'
supports 'ubuntu', '= 12.04'
supports 'ubuntu', '= 14.04'

suggests 'chef-provisioning'

depends 'ark'
depends 'golang', '~> 1.3.0'
depends 'runit'
Expand Down
2 changes: 1 addition & 1 deletion recipes/install_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
path node['consul']['install_dir']
version node['consul']['version']
checksum install_checksum
url ::URI.join(node['consul']['base_url'], "#{install_version}.zip").to_s
url node['consul']['base_url'] % { version: install_version }

This comment was marked as outdated.

action :dump
end

Expand Down
2 changes: 1 addition & 1 deletion recipes/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
home_dir node['consul']['ui_dir']
version node['consul']['version']
checksum install_checksum
url ::URI.join(node['consul']['base_url'], "#{install_version}.zip").to_s
url node['consul']['base_url'] % { version: install_version }
end
2 changes: 1 addition & 1 deletion spec/unit/attributes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
let(:chef_run) { ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04').converge(described_recipe) }

context 'sets default attributes' do
it { expect(chef_run.node.consul.base_url).to eq('https://dl.bintray.com/mitchellh/consul/') }
it { expect(chef_run.node.consul.base_url).to eq("https://dl.bintray.com/mitchellh/consul/%{version}.zip") }
end
end
6 changes: 0 additions & 6 deletions spec_helper.rb

This file was deleted.