infrataster-plugin-mysql 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9510ccfbc8f7ee0fc8eddd7e2660f75a578cd1d2
4
+ data.tar.gz: 4d5e3a0cca48315622e605dae06c431b147fe8b4
5
+ SHA512:
6
+ metadata.gz: 6b08b28369e556bf55d761a1a7364dac767c330a7ff59fc17ef2943bc61a114da28d6713581943819e5d5eb9156d51c409bf11c2a546065fe1ffb983eb5f6786
7
+ data.tar.gz: 4a560a8093ddaa74783b524b18dcd12b60d1b7d1f68ff286232b5459cdad660bbf81cdffb61357119bfa78372d8f08e6c2c8dd521c60d07d813351f64b456a3d
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in infrataster-plugin-mysql.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryota Arai
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # infrataster-plugin-mysql
2
+
3
+ MySQL plugin for [Infrataster](https://github.com/ryotarai/infrataster)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Gemfile:
8
+
9
+ gem 'infrataster-plugin-mysql'
10
+
11
+ And then add the following line to your spec\_helper.rb:
12
+
13
+ require 'infrataster-plugin-mysql'
14
+
15
+ ## Usage
16
+
17
+ ```ruby
18
+ describe server(:db) do
19
+ describe mysql_query('SHOW STATUS') do
20
+ it 'returns positive uptime' do
21
+ row = results.find {|r| r['Variable_name'] == 'Uptime' }
22
+ expect(row['Value'].to_i).to be > 0
23
+
24
+ # `results` is a instance of `Mysql2::Result`
25
+ # See: https://github.com/brianmario/mysql2
26
+ end
27
+ end
28
+ end
29
+ ```
30
+
31
+ You can specify username and password by options passed to `Infrataster::Server.define`:
32
+
33
+ ```ruby
34
+ Infrataster::Server.define(
35
+ # ...
36
+ mysql: {user: 'app', password: 'app'}
37
+ )
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( https://github.com/[my-github-username]/infrataster-plugin-mysql/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create a new Pull Request
@@ -0,0 +1,36 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ ENV['VAGRANT_CWD'] = File.expand_path('spec/')
5
+
6
+ def exec_and_abort_if_fail(cmd)
7
+ system cmd
8
+ unless $?.exitstatus == 0
9
+ $stderr.puts "'#{cmd}' failed."
10
+ abort
11
+ end
12
+ end
13
+
14
+ desc 'Prepare and run tests'
15
+ task :spec => ['spec:prepare', 'spec:integration']
16
+
17
+ namespace :spec do
18
+ RSpec::Core::RakeTask.new("integration") do |task|
19
+ task.pattern = "./spec/{,/*/**}/*_spec.rb"
20
+ end
21
+
22
+ desc 'Prepare'
23
+ task :prepare do
24
+ exec_and_abort_if_fail '/usr/bin/vagrant up'
25
+ end
26
+
27
+ desc 'Provision'
28
+ task :provision do
29
+ exec_and_abort_if_fail '/usr/bin/vagrant provision'
30
+ end
31
+
32
+ desc 'Clean'
33
+ task :clean do
34
+ exec_and_abort_if_fail '/usr/bin/vagrant destroy -f'
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "infrataster-plugin-mysql"
4
+ spec.version = '0.1.0'
5
+ spec.authors = ["Ryota Arai"]
6
+ spec.email = ["ryota.arai@gmail.com"]
7
+ spec.summary = %q{MySQL plugin for Infrataster}
8
+ spec.homepage = ""
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files -z`.split("\x0")
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency "infrataster"
17
+ spec.add_runtime_dependency "mysql2"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.6"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rspec"
22
+ end
@@ -0,0 +1,3 @@
1
+ require 'infrataster/resources/mysql_query_resource'
2
+ require 'infrataster/contexts/mysql_query_context'
3
+
@@ -0,0 +1,28 @@
1
+ require 'infrataster'
2
+ require 'mysql2'
3
+
4
+ module Infrataster
5
+ module Contexts
6
+ class MysqlQueryContext < BaseContext
7
+ def results
8
+ options = {port: 3306, user: 'root', password: ''}
9
+ if server.options[:mysql]
10
+ options = options.merge(server.options[:mysql])
11
+ end
12
+
13
+ server.open_gateway_on_from_server(options[:port]) do |address, new_port|
14
+ client = Mysql2::Client.new(
15
+ host: address,
16
+ port: new_port,
17
+ username: options[:user],
18
+ password: options[:password],
19
+ )
20
+ client.query(resource.query)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+
@@ -0,0 +1,22 @@
1
+ require 'infrataster'
2
+
3
+ module Infrataster
4
+ module Resources
5
+ class MysqlQueryResource < BaseResource
6
+ Error = Class.new(StandardError)
7
+
8
+ attr_reader :query
9
+
10
+ def initialize(query, options = {})
11
+ @query = query
12
+ @options = options
13
+ end
14
+
15
+ def to_s
16
+ "mysql '#{@query}'"
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1 @@
1
+ .vagrant
@@ -0,0 +1,18 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ config.vm.box = "hashicorp/precise64"
9
+
10
+ config.vm.network "private_network", ip: "192.168.44.20"
11
+
12
+ config.vm.provision "chef_solo" do |chef|
13
+ chef.cookbooks_path = [File.expand_path('../cookbooks', __FILE__)]
14
+ chef.add_recipe "apt-mirror"
15
+ chef.add_recipe "db"
16
+ chef.json = {}
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ execute "sed -i -e 's| \\(http[^ ]\\+\\)| mirror://mirrors.ubuntu.com/mirrors.txt|g' /etc/apt/sources.list"
2
+
3
+ execute "apt-get update && touch /tmp/apt-get-updated" do
4
+ not_if { File.exist?('/tmp/apt-get-updated') }
5
+ end
6
+
@@ -0,0 +1,127 @@
1
+ #
2
+ # The MySQL database server configuration file.
3
+ #
4
+ # You can copy this to one of:
5
+ # - "/etc/mysql/my.cnf" to set global options,
6
+ # - "~/.my.cnf" to set user-specific options.
7
+ #
8
+ # One can use all long options that the program supports.
9
+ # Run program with --help to get a list of available options and with
10
+ # --print-defaults to see which it would actually understand and use.
11
+ #
12
+ # For explanations see
13
+ # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
14
+
15
+ # This will be passed to all mysql clients
16
+ # It has been reported that passwords should be enclosed with ticks/quotes
17
+ # escpecially if they contain "#" chars...
18
+ # Remember to edit /etc/mysql/debian.cnf when changing the socket location.
19
+ [client]
20
+ port = 3306
21
+ socket = /var/run/mysqld/mysqld.sock
22
+
23
+ # Here is entries for some specific programs
24
+ # The following values assume you have at least 32M ram
25
+
26
+ # This was formally known as [safe_mysqld]. Both versions are currently parsed.
27
+ [mysqld_safe]
28
+ socket = /var/run/mysqld/mysqld.sock
29
+ nice = 0
30
+
31
+ [mysqld]
32
+ #
33
+ # * Basic Settings
34
+ #
35
+ user = mysql
36
+ pid-file = /var/run/mysqld/mysqld.pid
37
+ socket = /var/run/mysqld/mysqld.sock
38
+ port = 3306
39
+ basedir = /usr
40
+ datadir = /var/lib/mysql
41
+ tmpdir = /tmp
42
+ lc-messages-dir = /usr/share/mysql
43
+ skip-external-locking
44
+ #
45
+ # Instead of skip-networking the default is now to listen only on
46
+ # localhost which is more compatible and is not less secure.
47
+ bind-address = 0.0.0.0
48
+ #
49
+ # * Fine Tuning
50
+ #
51
+ key_buffer = 16M
52
+ max_allowed_packet = 16M
53
+ thread_stack = 192K
54
+ thread_cache_size = 8
55
+ # This replaces the startup script and checks MyISAM tables if needed
56
+ # the first time they are touched
57
+ myisam-recover = BACKUP
58
+ #max_connections = 100
59
+ #table_cache = 64
60
+ #thread_concurrency = 10
61
+ #
62
+ # * Query Cache Configuration
63
+ #
64
+ query_cache_limit = 1M
65
+ query_cache_size = 16M
66
+ #
67
+ # * Logging and Replication
68
+ #
69
+ # Both location gets rotated by the cronjob.
70
+ # Be aware that this log type is a performance killer.
71
+ # As of 5.1 you can enable the log at runtime!
72
+ #general_log_file = /var/log/mysql/mysql.log
73
+ #general_log = 1
74
+ #
75
+ # Error log - should be very few entries.
76
+ #
77
+ log_error = /var/log/mysql/error.log
78
+ #
79
+ # Here you can see queries with especially long duration
80
+ #log_slow_queries = /var/log/mysql/mysql-slow.log
81
+ #long_query_time = 2
82
+ #log-queries-not-using-indexes
83
+ #
84
+ # The following can be used as easy to replay backup logs or for replication.
85
+ # note: if you are setting up a replication slave, see README.Debian about
86
+ # other settings you may need to change.
87
+ #server-id = 1
88
+ #log_bin = /var/log/mysql/mysql-bin.log
89
+ expire_logs_days = 10
90
+ max_binlog_size = 100M
91
+ #binlog_do_db = include_database_name
92
+ #binlog_ignore_db = include_database_name
93
+ #
94
+ # * InnoDB
95
+ #
96
+ # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
97
+ # Read the manual for more InnoDB related options. There are many!
98
+ #
99
+ # * Security Features
100
+ #
101
+ # Read the manual, too, if you want chroot!
102
+ # chroot = /var/lib/mysql/
103
+ #
104
+ # For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
105
+ #
106
+ # ssl-ca=/etc/mysql/cacert.pem
107
+ # ssl-cert=/etc/mysql/server-cert.pem
108
+ # ssl-key=/etc/mysql/server-key.pem
109
+
110
+
111
+
112
+ [mysqldump]
113
+ quick
114
+ quote-names
115
+ max_allowed_packet = 16M
116
+
117
+ [mysql]
118
+ #no-auto-rehash # faster start of mysql but no tab completition
119
+
120
+ [isamchk]
121
+ key_buffer = 16M
122
+
123
+ #
124
+ # * IMPORTANT: Additional settings that can override those from this file!
125
+ # The files must end with '.cnf', otherwise they'll be ignored.
126
+ #
127
+ !includedir /etc/mysql/conf.d/
@@ -0,0 +1,13 @@
1
+ package 'mysql-server'
2
+
3
+ service 'mysql' do
4
+ action :start
5
+ supports :restart => true
6
+ end
7
+
8
+ cookbook_file '/etc/mysql/my.cnf' do
9
+ notifies :restart, 'service[mysql]'
10
+ end
11
+
12
+ execute "mysql -uroot -e \"GRANT ALL PRIVILEGES ON *.* TO 'app'@'%' IDENTIFIED BY 'app';\""
13
+
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe server(:db) do
4
+ describe mysql_query('SHOW STATUS') do
5
+ it 'responds uptime' do
6
+ row = results.find {|r| r['Variable_name'] == 'Uptime' }
7
+ expect(row['Value'].to_i).to be > 0
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,21 @@
1
+ require 'infrataster/rspec'
2
+ require 'infrataster-plugin-mysql'
3
+
4
+ Infrataster::Server.define(
5
+ :db,
6
+ '192.168.44.20',
7
+ vagrant: true,
8
+ mysql: {user: 'app', password: 'app'},
9
+ )
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infrataster-plugin-mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryota Arai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: infrataster
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mysql2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - ryota.arai@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - infrataster-plugin-mysql.gemspec
97
+ - lib/infrataster-plugin-mysql.rb
98
+ - lib/infrataster/contexts/mysql_query_context.rb
99
+ - lib/infrataster/resources/mysql_query_resource.rb
100
+ - spec/.gitignore
101
+ - spec/Vagrantfile
102
+ - spec/cookbooks/apt-mirror/recipes/default.rb
103
+ - spec/cookbooks/db/files/default/my.cnf
104
+ - spec/cookbooks/db/recipes/default.rb
105
+ - spec/mysql_query_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: ''
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: MySQL plugin for Infrataster
131
+ test_files:
132
+ - spec/.gitignore
133
+ - spec/Vagrantfile
134
+ - spec/cookbooks/apt-mirror/recipes/default.rb
135
+ - spec/cookbooks/db/files/default/my.cnf
136
+ - spec/cookbooks/db/recipes/default.rb
137
+ - spec/mysql_query_spec.rb
138
+ - spec/spec_helper.rb