Skip to content

Commit

Permalink
Merge pull request #1 from chef-partners/mattray/alpha
Browse files Browse the repository at this point in the history
Initial release
  • Loading branch information
mattray committed Apr 19, 2016
2 parents 8fbc77e + 499c4fe commit f140386
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 4 deletions.
70 changes: 70 additions & 0 deletions .kitchen.local.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
driver:
name: gce
project: chef-marketplace-dev
zone: us-central1-a
preemptible: true
email: [email protected]
tags:
- mesosphere
- test-kitchen
service_account_scopes:
- devstorage.read_write
- userinfo.email

transport:
username: mray
ssh_key:
- ~/.ssh/google_compute_engine

platforms:
- name: centos-7.2
driver:
image_name: centos-7

suites:
- name: default
run_list:
- recipe[dcos::default]
attributes:
dcos:
master_list: ['127.0.0.1']
- name: gm1
run_list:
- recipe[dcos::default]
attributes:
dcos:
ip-detect: 'gce'
dcos_role: 'master'
master_list: ['10.240.0.2', '10.240.0.3', '10.240.0.4']
- name: gm2
run_list:
- recipe[dcos::default]
attributes:
dcos:
ip-detect: 'gce'
dcos_role: 'master'
master_list: ['10.240.0.2', '10.240.0.3', '10.240.0.4']
- name: gm3
run_list:
- recipe[dcos::default]
attributes:
dcos:
dcos_role: 'master'
master_list: ['10.240.0.2', '10.240.0.3', '10.240.0.4']
- name: gs1
run_list:
- recipe[dcos::default]
attributes:
dcos:
ip-detect: 'gce'
dcos_role: 'slave'
master_list: ['10.240.0.2', '10.240.0.3', '10.240.0.4']
- name: gs2
run_list:
- recipe[dcos::default]
attributes:
dcos:
ip-detect: 'gce'
dcos_role: 'slave'
master_list: ['10.240.0.2', '10.240.0.3', '10.240.0.4']
4 changes: 3 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ platforms:
suites:
- name: default
run_list:
- recipe[mesosphere::default]
- recipe[dcos::default]
attributes:
dcos:
master_list: ['127.0.0.1']
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Style/FileName:
Exclude:
- 'recipes/_ip-detect.rb'

LineLength:
Enabled: false
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: ruby
sudo: false

addons:
apt:
sources:
- chef-current-precise
packages:
- chefdk

# Ensure we make ChefDK's Ruby the default
before_script:
- eval "$(/opt/chefdk/bin/chef shell-init bash)"
script:
- /opt/chefdk/embedded/bin/chef --version
- /opt/chefdk/embedded/bin/rubocop --version
- /opt/chefdk/embedded/bin/rubocop
- /opt/chefdk/embedded/bin/foodcritic --version
- /opt/chefdk/embedded/bin/foodcritic . --exclude spec
- /opt/chefdk/embedded/bin/rspec --version
- /opt/chefdk/embedded/bin/rspec
3 changes: 3 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://supermarket.chef.io'

metadata
57 changes: 55 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,70 @@
[![Build Status](https://travis-ci.org/chef-partners/dcos-cookbook.svg?branch=master)](https://travis-ci.org/chef-partners/dcos-cookbook)

Description
===========

Manage deployment and configuration of underlying Mesosphere installation.
Manage deployment and configuration of underlying Mesosphere DCOS installation.

Requirements
------------

Attributes
Only Red Hat or CentOS 7.x are currently supported.

Usage
==========

The behavior of this cookbook is managed by attributes documented in the [attributes file](attributes/default.rb). The `node['dcos']['dcos_role']` attribute controls the DCOS role to apply to the node (default is `master`). The `node['dcos']['master_list']` must be set to specify the list of DCOS master node IPv4 addresses to connect at startup (this must be an odd number of masters).

Roles
----------

You can create a Chef Role and apply it to nodes as necessary to specify `master`, `slave` and `slave-public` as appropriate. Any additional configuration should probably be set as override attributes in an Environment to ensure all nodes receive those global settings.

### Example Role dcos_master.rb ###
````ruby
name "dcos_master"
description "DCOS master role"
run_list "recipe[dcos]"
default_attributes "dcos" => {
"dcos_role" => "master"
"master_list" => [ "10.0.2.10" ]
}
````

### Example Role dcos_slave.rb ###
````ruby
name "dcos_slave"
description "DCOS slave role"
run_list "recipe[dcos]"
default_attributes "dcos" => {
"dcos_role" => "slave"
"master_list" => [ "10.0.2.10" ]
}
````

Recipe
=======

default
-------

Installs the prerequisites for the Mesosphere DCOS installation, including packages, groups and Docker with OverlayFS enabled. It then downloads and runs the installation package with the settings configured by the node's attributes.

Testing
=======

ChefSpec
--------
There is basic coverage for the default recipe.

InSpec
------
TBD

Test Kitchen
------------
The included [.kitchen.yml](.kitchen.yml) runs the default master deployment in a generic fashion. The included [.kitchen.local.yml.example](.kitchen.local.yml.example) shows alternate settings for running multi-master with slaves on GCE (you will have to rename and update accordingly).

License and Author
==================

Expand Down
37 changes: 37 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Author:: Matt Ray <[email protected]>
# Cookbook Name:: dcos
#
# Copyright 2016 Chef Software, Inc
#
# 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.
#

default['dcos']['dcos_version'] = 'stable'
default['dcos']['dcos_role'] = 'master' # 'master', 'slave' or 'slave_public'

default['dcos']['cluster_name'] = 'DCOS'
default['dcos']['master_discovery'] = 'static'
default['dcos']['exhibitor_storage_backend'] = 'static'
default['dcos']['bootstrap_url'] = 'file:///root/genconf/serve'

# determine how to generate the genconf/ip-detect script
# 'aws' or 'gce' will use the local ipv4 address from the metadata service
# otherwise use 'eth0', 'eth1', etc. and it will get the ipaddress associated
# with node['network']['interface'][VALUE]
default['dcos']['ip-detect'] = 'eth0'

# ipv4 only, must be odd number 1-9
default['dcos']['master_list'] = []
# upstream DNS for MesosDNS
default['dcos']['resolvers'] = ['8.8.8.8', '8.8.4.4']
6 changes: 6 additions & 0 deletions files/default/aws
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# Example ip-detect script using an external authority
# Uses the AWS Metadata Service to get the node's internal
# ipv4 address

curl -fsSL http://169.254.169.254/latest/meta-data/local-ipv4
6 changes: 6 additions & 0 deletions files/default/gce
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# Example ip-detect script using an external authority
# Uses the GCE metadata server to get the node's internal
# ipv4 address

curl -fsSl -H "Metadata-Flavor: Google" http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/ip
8 changes: 7 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
name 'mesosphere'
name 'dcos'
maintainer 'Chef Software, Inc.'
maintainer_email '[email protected]'
license 'Apache 2.0'
description 'Installs/Configures Mesosphere'
long_description 'Installs/Configures Mesosphere'
version '0.1.0'

source_url 'https://github.com/chef-partners/dcos-cookbook' if
respond_to?(:source_url)
issues_url 'https://github.com/chef-partners/dcos-cookbook/issues' if
respond_to?(:issues_url)

supports 'centos'
supports 'oracle'
supports 'redhat'
supports 'scientific'

depends 'docker', '~> 2.0'
depends 'selinux', '~> 0.9.0'
45 changes: 45 additions & 0 deletions recipes/_ip-detect.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Cookbook Name:: dcos
# Recipe:: _ip-detect
#
# Copyright 2016, Chef Software, Inc.
#
# 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.
#

# generates a genconf/ip-detect script based on the node['dcos']['ip-detect']
# https://docs.mesosphere.com/archived-dcos-enterprise-edition/installing-enterprise-edition-1-5/create-a-script-for-ip-address-discovery/

if node['dcos']['ip-detect'].eql? 'aws'
cookbook_file '/root/genconf/ip-detect' do
source 'aws'
mode '0755'
end
elsif node['dcos']['ip-detect'].eql? 'gce'
cookbook_file '/root/genconf/ip-detect' do
source 'gce'
mode '0755'
end
else
# find the ipaddress for that interface
interface = node['dcos']['ip-detect']
addresses = node['network']['interfaces'][interface]['addresses']
addresses.select do |ip, data|
template '/root/genconf/ip-detect' do
source 'ip-detect.erb'
only_if { data['family'].eql?('inet') }
mode '0755'
variables(ip: ip)
end
end
end
81 changes: 81 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#
# Cookbook Name:: dcos
# Recipe:: default
#
# Copyright 2016, Chef Software, Inc.
#
# 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.
#

# Prereqs
selinux_state 'SELinux Permissive' do
action :permissive
end

service 'firewalld' do
action [:stop, :disable]
end

package 'unzip'

package 'ipset'

group 'nogroup'

# Install docker with overlayfs
docker_service 'default' do
storage_driver 'overlay'
action [:create, :start]
end

# Note this link does not have versioning, so using it will always be the latest
# DCOS from 'testing' and this URL might change in the future.
# https://s3.amazonaws.com/downloads.mesosphere.io/dcos/stable/dcos_generate_config.sh
remote_file '/root/dcos_generate_config.sh' do
source 'https://downloads.mesosphere.io/dcos/testing/continuous/dcos_generate_config.sh'
mode '0755'
end

directory '/root/genconf' do
mode '0755'
end

template '/root/genconf/config.yaml' do
source 'config.yaml.erb'
end

# generate the /root/genconf/ip-detect script
include_recipe 'dcos::_ip-detect'

execute 'dcos-genconf' do
command '/root/dcos_generate_config.sh --genconf'
user 'root'
cwd '/root'
not_if do
File.exist?('/root/genconf/cluster_packages.json')
end
end

file '/root/genconf/serve/dcos_install.sh' do
mode '0755'
subscribes :create, 'execute[dcos-genconf]', :immediately
action :nothing
end

execute 'dcos_install' do
command "/root/genconf/serve/dcos_install.sh #{node['dcos']['dcos_role']}"
user 'root'
cwd '/root'
subscribes :run, 'file[/root/genconf/serve/dcos_install.sh]', :immediately
action :nothing
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'chefspec'
require 'chefspec/berkshelf'
Loading

0 comments on commit f140386

Please sign in to comment.