Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #9 from codenamephp/dev
Browse files Browse the repository at this point in the history
[RELEASE 1.0.0]
  • Loading branch information
bastianschwarz committed Aug 25, 2018
2 parents e4da2ea + 360c2f7 commit a28fc2d
Show file tree
Hide file tree
Showing 18 changed files with 298 additions and 43 deletions.
9 changes: 8 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ verifier:
name: inspec

platforms:
- name: debian-9.2
- name: debian-9.3

suites:
- name: default
Expand All @@ -19,3 +19,10 @@ suites:
inspec_tests:
- test/smoke/default
attributes:
- name: "5.6"
run_list:
- recipe[codenamephp_mysql::5.6]
verifier:
inspec_tests:
- test/smoke/5.6
attributes:
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ AllCops:
Exclude:
- 'bin/**'
- 'bundler/**'
- 'vendor/**'

Layout/EndOfLine:
EnforcedStyle: lf

Metrics/LineLength:
Max: 160
Expand Down
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ addons:
install:
- sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
- eval "$(chef shell-init bash)"
- chef --version
- cookstyle --version
- foodcritic --version
- openssl aes-256-cbc -K $encrypted_4c0189a98bd3_key -iv $encrypted_4c0189a98bd3_iv -in codenamephp.pem.enc -out codenamephp.pem -d
- gem install github_changelog_generator

script:
- chef exec rake
- chef exec rake ci

before_deploy:
- openssl aes-256-cbc -K $encrypted_4c0189a98bd3_key -iv $encrypted_4c0189a98bd3_iv -in codenamephp.pem.enc -out codenamephp.pem -d
- git config --local user.name "Travis CI"
- git config --local user.email "travis@codename-php.de"
- git remote set-url --push origin "https://$GH_TOKEN@github.com/codenamephp/chef.cookbook.mysql.git"
deploy:
- provider: script
on:
Expand Down
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Rake documentation:changelog",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/vendor/rake",
"showDebuggerOutput": true,
"stopOnEntry": true,
"useBundler": true,
"args": [
"documentation:changelog"
]
}
]
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,17 @@ Add the cookbook to your runlist, e.g. in a role:
]
}
```

## Cookbooks

### Default
The default cookbook just installs the mysql-server and mysql-client package from whatever source is configured in the os. It also makes sure the mysql service is enabled
and started and installs a configuration template that makes sure each innodb table is it's own file since all tables in a single file tends to cause huge db files as the
disk space is never freed if a table is deleted.

### 5.6
The 5.6 cookbook adds the official oracle apt repository for version 5.6 before installing the mysql-server and mysql client package. It also makes sure the mysql service is enabled
and started and installs a configuration template that makes sure each innodb table is it's own file since all tables in a single file tends to cause huge db files as the
disk space is never freed if a table is deleted.

[chef-mysql]: https://supermarket.chef.io/cookbooks/mysql
73 changes: 64 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,33 @@ def use_dokken?
ENV['USE_DOKKEN'] || ci?
end

def concurrency
ENV['CONCURRENCY'] || 1
end

task default: %w[style unit integration]
task ci: %w[default documentation]

namespace :git do
desc 'Setting up git for pushing'
task :setup do
sh 'git config --local user.name "Travis CI"'
sh 'git config --local user.email "travis@codename-php.de"'
sh 'git remote set-url --push origin "https://' + ENV['GH_TOKEN'].to_s + '@github.com/codenamephp/chef.cookbook.mysql.git"', verbose: false do |ok, status|
unless ok
raise "Command failed with status (#{status.exitstatus}): " \
'git remote set-url --push origin "https://[GITHUB_TOKEN_HIDDEN]@github.com/codenamephp/chef.cookbook.mysql.git"'
end
end
end
end

namespace :style do
require 'rubocop/rake_task'
desc 'Run Ruby style checks using rubocop'
RuboCop::RakeTask.new(:ruby)
RuboCop::RakeTask.new(:ruby) do |task|
task.options = ['-a']
end

require 'foodcritic'
desc 'Run Chef style checks using foodcritic'
Expand Down Expand Up @@ -57,31 +78,65 @@ namespace :integration do
# @param regexp [String] regular expression to match against instance names.
# @param loader_config [Hash] loader configuration options.
# @return void
def run_kitchen(action, regexp, loader_config = {})
def run_kitchen(action, regexp, concurrency, loader_config = {})
action = 'test' if action.nil?
require 'kitchen'
Kitchen.logger = Kitchen.default_file_logger
config = { loader: Kitchen::Loader::YAML.new(loader_config) }
kitchen_instances(regexp, config).each { |i| i.send(action) }

call_threaded(kitchen_instances(regexp, config), action, concurrency)
end

# Calls a method on a list of objects in concurrent threads.
#
# @param objects [Array] list of objects.
# @param method_name [#to_s] method to call on the objects.
# @param concurrency [Integer] number of objects to call the method on concurrently.
# @return void
def call_threaded(objects, method_name, concurrency)
puts "method_name: #{method_name}, concurrency: #{concurrency}"
threads = []
raise 'concurrency must be > 0' if concurrency < 1
objects.each do |obj|
sleep 3 until threads.map(&:alive?).count(true) < concurrency
threads << Thread.new { obj.method(method_name).call }
end
threads.map(&:join)
end

desc 'Run Test Kitchen integration tests using vagrant'
task :vagrant, %i[regexp action] do |_t, args|
run_kitchen(args.action, args.regexp)
task :vagrant, [:regexp, :action, :concurrency] do |_t, args|
args.with_defaults(regexp: 'all', action: 'test', concurrency: concurrency)
run_kitchen(args.action, args.regexp, args.concurrency.to_i)
end

desc 'Run Test Kitchen integration tests using dokken'
task :dokken, %i[regexp action] do |_t, args|
run_kitchen(args.action, args.regexp, local_config: '.kitchen.dokken.yml')
task :dokken, [:regexp, :action, :concurrency] do |_t, args|
args.with_defaults(regexp: 'all', action: 'test', concurrency: concurrency)
run_kitchen(args.action, args.regexp, args.concurrency.to_i, local_config: '.kitchen.dokken.yml')
end
end

desc 'Run Test Kitchen integration tests'
task :integration, %i[regexp action] => ci? || use_dokken? ? %w[integration:dokken] : %w[integration:vagrant]
task :integration, %i[regexp action concurrency] => ci? || use_dokken? ? %w[integration:dokken] : %w[integration:vagrant]

namespace :documentation do
desc 'Generate changelog from current commit message'
task changelog_commit: ['git:setup'] do
match = Regexp.new('\[RELEASE\s([\d\.]+)\]').match(ENV['TRAVIS_COMMIT_MESSAGE'])
unless match.nil?
sh 'github_changelog_generator --future-release ' + match[1].to_s
sh 'git status'
sh 'git add CHANGELOG.md && git commit --allow-empty -m"[skip ci] Updated changelog" && git push origin ' + ENV['TRAVIS_BRANCH']
end
end
end
desc 'Run the documentation cycle'
task documentation: %w[documentation:changelog_commit]

namespace :release do
desc 'Tag and release to supermarket with stove'
task :stove do
task stove: ['git:setup'] do
sh 'chef exec stove --username codenamephp --key ./codenamephp.pem'
end

Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
maintainer_email 'bastian@codename-php.de'
license 'Apache-2.0'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.0.9'
version '1.0.0'
chef_version '>= 13.0' if respond_to?(:chef_version)
issues_url 'https://github.com/codenamephp/chef.cookbook.mysql/issues'
source_url 'https://github.com/codenamephp/chef.cookbook.mysql'
Expand Down
24 changes: 24 additions & 0 deletions recipes/5.6.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Cookbook:: .
# Recipe:: 5.6
#
# Copyright:: 2018, The Authors, All Rights Reserved.

apt_repository 'oracle mysql' do
uri 'http://repo.mysql.com/apt/debian'
repo_name 'oracle-mysql'
components ['mysql-apt-config', 'mysql-5.6', 'mysql-tools']
keyserver 'pgp.mit.edu'
key '5072E1F5'
deb_src true
end

package 'mysql-server'
package 'mysql-client'

service 'mysql' do
action %i[start enable]
end

include_recipe '::service'
include_recipe '::innodb_file_per_table'
13 changes: 2 additions & 11 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,5 @@
package 'mysql-server'
package 'mysql-client'

service 'mysql' do
action %i[start enable]
end

template '/etc/mysql/conf.d/50-innodb.cnf' do
source 'innodb.erb'
owner 'root'
group 'root'
action :create
notifies :restart, 'service[mysql]', :immediately
end
include_recipe '::service'
include_recipe '::innodb_file_per_table'
15 changes: 15 additions & 0 deletions recipes/innodb_file_per_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Cookbook:: .
# Recipe:: innodb_file_per_table
#
# Copyright:: 2018, The Authors, All Rights Reserved.

include_recipe '::service'

template '/etc/mysql/conf.d/50-innodb.cnf' do
source 'innodb.erb'
owner 'root'
group 'root'
action :create
notifies :restart, 'service[mysql]', :immediately
end
9 changes: 9 additions & 0 deletions recipes/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Cookbook:: .
# Recipe:: 5.6
#
# Copyright:: 2018, The Authors, All Rights Reserved.

service 'mysql' do
action %i[start enable]
end
38 changes: 38 additions & 0 deletions spec/unit/recipes/5.6_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Cookbook:: codenamephp_mysql
# Spec:: 5.6
#
# Copyright:: 2018, The Authors, All Rights Reserved.

require 'spec_helper'

describe 'codenamephp_mysql::5.6' do
context 'When all attributes are default' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
let(:template) { chef_run.template('/etc/mysql/conf.d/50-innodb.cnf') }

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end

it 'adds the apt repo' do
expect(chef_run).to add_apt_repository('oracle mysql')
end

it 'installs mysql-server from package' do
expect(chef_run).to install_package('mysql-server')
end

it 'installs mysql-client from package' do
expect(chef_run).to install_package('mysql-client')
end

it 'includes the service recipe' do
expect(chef_run).to include_recipe('codenamephp_mysql::service')
end

it 'includes the innodb_file_per_table recipe' do
expect(chef_run).to include_recipe('codenamephp_mysql::innodb_file_per_table')
end
end
end
14 changes: 4 additions & 10 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@
expect(chef_run).to install_package('mysql-client')
end

it 'makes sure the service is started and enabled' do
expect(chef_run).to enable_service('mysql')
expect(chef_run).to start_service('mysql')
it 'includes the service recipe' do
expect(chef_run).to include_recipe('codenamephp_mysql::service')
end

it 'adds innodb config template and restarts mysql service immediately' do
expect(chef_run).to create_template('/etc/mysql/conf.d/50-innodb.cnf').with(
source: 'innodb.erb',
user: 'root',
group: 'root'
)
expect(template).to notify('service[mysql]').to(:restart).immediately
it 'includes the innodb_file_per_table recipe' do
expect(chef_run).to include_recipe('codenamephp_mysql::innodb_file_per_table')
end
end
end
27 changes: 27 additions & 0 deletions spec/unit/recipes/innodb_file_per_table_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Cookbook:: .
# Spec:: innodb_file_per_table
#
# Copyright:: 2018, The Authors, All Rights Reserved.

require 'spec_helper'

describe 'codenamephp_mysql::innodb_file_per_table' do
context 'When all attributes are default' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }
let(:template) { chef_run.template('/etc/mysql/conf.d/50-innodb.cnf') }

it 'includes the service recipe' do
expect(chef_run).to include_recipe('codenamephp_mysql::service')
end

it 'adds innodb config template and restarts mysql service immediately' do
expect(chef_run).to create_template('/etc/mysql/conf.d/50-innodb.cnf').with(
source: 'innodb.erb',
user: 'root',
group: 'root'
)
expect(template).to notify('service[mysql]').to(:restart).immediately
end
end
end
22 changes: 22 additions & 0 deletions spec/unit/recipes/service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Cookbook:: codenamephp_mysql
# Spec:: default
#
# Copyright:: 2017, The Authors, All Rights Reserved.

require 'spec_helper'

describe 'codenamephp_mysql::service' do
context 'When all attributes are default' do
let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

it 'converges successfully' do
expect { chef_run }.to_not raise_error
end

it 'makes sure the service is started and enabled' do
expect(chef_run).to enable_service('mysql')
expect(chef_run).to start_service('mysql')
end
end
end
Loading

0 comments on commit a28fc2d

Please sign in to comment.