salted-rails 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +48 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/README.md +79 -0
  6. data/Rakefile +1 -0
  7. data/lib/salted_rails.rb +5 -0
  8. data/lib/salted_rails/base.rb +5 -0
  9. data/lib/salted_rails/capistrano.rb +6 -0
  10. data/lib/salted_rails/vagrant_helper.rb +155 -0
  11. data/lib/salted_rails/version.rb +3 -0
  12. data/pillar/capistrano.sls +3 -0
  13. data/pillar/capistrano/top.sls +5 -0
  14. data/pillar/common.sls +15 -0
  15. data/pillar/vagrant.sls +3 -0
  16. data/pillar/vagrant/top.sls +5 -0
  17. data/salt/apt/partner-sources.sls +13 -0
  18. data/salt/apt/unwanted.sls +5 -0
  19. data/salt/capistrano.sls +0 -0
  20. data/salt/capistrano/minion +14 -0
  21. data/salt/capistrano/minion.sls +6 -0
  22. data/salt/capistrano/top.sls +8 -0
  23. data/salt/common.sls +19 -0
  24. data/salt/crons/init.sls +23 -0
  25. data/salt/databases/mysql/client-encoding-and-collation.cnf +2 -0
  26. data/salt/databases/mysql/client.sls +17 -0
  27. data/salt/databases/mysql/common.sls +22 -0
  28. data/salt/databases/mysql/config.sls +6 -0
  29. data/salt/databases/mysql/custom_config.sls +14 -0
  30. data/salt/databases/mysql/default-table-engine.cnf +2 -0
  31. data/salt/databases/mysql/group.sls +4 -0
  32. data/salt/databases/mysql/init.sls +8 -0
  33. data/salt/databases/mysql/server-encoding-and-collation.cnf +4 -0
  34. data/salt/databases/mysql/server.sls +59 -0
  35. data/salt/databases/phpmyadmin/etc/nginx/sites-available/.gitignore +3 -0
  36. data/salt/databases/phpmyadmin/etc/nginx/sites-available/phpmyadmin.conf +24 -0
  37. data/salt/databases/phpmyadmin/init.sls +27 -0
  38. data/salt/develop/init.sls +3 -0
  39. data/salt/echo_pillar.sls +9 -0
  40. data/salt/editors/vim/init.sls +12 -0
  41. data/salt/editors/vim/vimrc +23 -0
  42. data/salt/lang/php/composer.sls +9 -0
  43. data/salt/lang/php/etc/php5/fpm/php.fpm.ini +1818 -0
  44. data/salt/lang/php/etc/php5/fpm/pool.d/www.conf +393 -0
  45. data/salt/lang/php/init.sls +38 -0
  46. data/salt/lang/php/nginx.sls +9 -0
  47. data/salt/lang/python/python-libs.sls +28 -0
  48. data/salt/lang/ruby.sls +60 -0
  49. data/salt/lang/ruby.sls.bak +106 -0
  50. data/salt/lang/system_ruby.sls +43 -0
  51. data/salt/munin/files/nginx/plugin-conf.d/nginx +2 -0
  52. data/salt/munin/files/nginx/plugins/nginx_combined_localhost +160 -0
  53. data/salt/munin/files/nginx/plugins/nginx_request +114 -0
  54. data/salt/munin/files/nginx/plugins/nginx_status +126 -0
  55. data/salt/munin/files/node/checkPermissions.sh +10 -0
  56. data/salt/munin/files/node/munin-node.conf +54 -0
  57. data/salt/munin/files/php5-fpm/plugins/phpfpm_average +39 -0
  58. data/salt/munin/files/php5-fpm/plugins/phpfpm_connections +71 -0
  59. data/salt/munin/files/php5-fpm/plugins/phpfpm_memory +24 -0
  60. data/salt/munin/files/php5-fpm/plugins/phpfpm_processes +38 -0
  61. data/salt/munin/files/php5-fpm/plugins/phpfpm_status +83 -0
  62. data/salt/munin/files/server/munin.conf +107 -0
  63. data/salt/munin/nginx.sls +13 -0
  64. data/salt/munin/node.sls +34 -0
  65. data/salt/munin/php5-fpm.sls +13 -0
  66. data/salt/munin/server.sls +7 -0
  67. data/salt/railsapp/database.sls +25 -0
  68. data/salt/railsapp/files/Gemfile +57 -0
  69. data/salt/railsapp/files/Gemfile.lock +133 -0
  70. data/salt/railsapp/gems.sls +18 -0
  71. data/salt/railsapp/init.sls +3 -0
  72. data/salt/run-standalone +3 -0
  73. data/salt/salt/minion/config.template +259 -0
  74. data/salt/salt/minion/debconf.sls +3 -0
  75. data/salt/salt/minion/init.sls +49 -0
  76. data/salt/salt/minion/lsb.sls +8 -0
  77. data/salt/salt/minion/mysql.conf +1 -0
  78. data/salt/salt/minion/mysql.sls +20 -0
  79. data/salt/server/monit.sls +31 -0
  80. data/salt/server/sudo/init.sls +16 -0
  81. data/salt/server/sudo/sudoers +90 -0
  82. data/salt/sysutils/file.sls +8 -0
  83. data/salt/sysutils/init.sls +5 -0
  84. data/salt/sysutils/net.sls +9 -0
  85. data/salt/sysutils/status.sls +11 -0
  86. data/salt/sysutils/tmux.sls +3 -0
  87. data/salt/vagrant.sls +0 -0
  88. data/salt/vagrant/minion +14 -0
  89. data/salt/vagrant/minion.sls +6 -0
  90. data/salt/vagrant/top.sls +8 -0
  91. data/salt/www/chromium.sls +6 -0
  92. data/salt/www/nginx/etc/nginx/nginx.conf +53 -0
  93. data/salt/www/nginx/init.sls +20 -0
  94. data/salt/www/users.sls +12 -0
  95. data/salted-rails.gemspec +23 -0
  96. metadata +163 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA512:
3
+ data.tar.gz: 8d8f12a3fea5cd1fe34fecb9fb9f7c41aa69e522428586d47576e5a4505e3358dd95d4c779f4275542a239b604f07c69be55773935803302dd9701069819b0c8
4
+ metadata.gz: f7b1112de4257b00978672dbc92b1bea11c73f1d12fefba4c15ba3b24e749e9140b72bd07c2a1f66813657ef80b26cc71e40c76e8f1923d1f80c3d33183f50d9
5
+ SHA1:
6
+ data.tar.gz: 18eeb1ba5e95d7d9ccd59a14036b403474fab4e8
7
+ metadata.gz: a70fe04ed27f0f858d3ef5b33041e89f8741bd6f
data/.gitignore ADDED
@@ -0,0 +1,48 @@
1
+ # OS-specific
2
+ .DS_Store
3
+
4
+ # Vagrant stuff
5
+ acceptance_config.yml
6
+ boxes/*
7
+ /Vagrantfile
8
+ /.vagrant
9
+
10
+ # Bundler/Rubygems
11
+ *.gem
12
+ .bundle
13
+ pkg/*
14
+ tags
15
+ /Gemfile.lock
16
+ test/tmp/
17
+
18
+ # Documentation
19
+ _site/*
20
+ .yardoc/
21
+ doc/
22
+
23
+ # Python
24
+ *.pyc
25
+
26
+ # Rubinius
27
+ *.rbc
28
+
29
+ # IDE junk
30
+ .idea/*
31
+ *.iml
32
+
33
+ # Ruby Managers
34
+ .rbenv
35
+ .ruby-gemset
36
+ .ruby-version
37
+ .rvmrc
38
+
39
+ # Website: docs
40
+ website/docs/.sass-cache
41
+ website/docs/build
42
+ website/docs/Rakefile
43
+
44
+ # Website: www
45
+ website/www/.sass-cache
46
+ website/www/build
47
+ website/www/Rakefile
48
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in salted-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Ian Heggie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Salted-Rails
2
+
3
+ Salted-Rails: Provision rails using salt to vagrant or capistrano controlled systems
4
+
5
+ EXPERIMENTAL
6
+
7
+ This configures vagrant in the way that I personally like:
8
+ * ubunutu 12.04 (LTS) 32bit from cloud-images.ubuntu.com (up to date packages and more memory free for systems < 4GB memory)
9
+ * forward ssh agent
10
+ * digital ocean default to 'San Francisco 1'
11
+ * salt provisioning based on rails Gemfile[.lock], database.yml and .ruby-version configuration
12
+ * forward post 3000, 80, 443
13
+
14
+ I am intending to add a capistrano helper as well
15
+
16
+ ## Installation
17
+
18
+ ### Vagrant
19
+
20
+ Add as a vagrant plugin
21
+
22
+ vagrant plugin add salted-rails
23
+
24
+ And then adjust your Vagrantfile as follows:
25
+
26
+ require 'salted_rails/vagrant_helper'
27
+ vagrant_helper = SaltedRails::VagrantHelper.new(File.dirname(__FILE__))
28
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
29
+ vagrant_helper.configure_vagrant(config)
30
+ vagrant_helper.configure_digital_ocean(config)
31
+ vagrant_helper.configure_salt(config)
32
+ vagrant_helper.configure_ports(config)
33
+ # example - override default key
34
+ # config.ssh.private_key_path = '~/.ssh/id_rsa_Another'
35
+ end
36
+
37
+ You can add configuration that applies to all your projects to `~/.vagrant.d/Vagrantfile`, eg:
38
+
39
+ Vagrant.configure('2') do |config|
40
+ config.vm.provider :digital_ocean do |provider|
41
+ provider.client_id = 'your id'
42
+ provider.api_key = 'your key'
43
+ end
44
+ end
45
+
46
+ ### Capistrano
47
+
48
+ Add this line to your application's Gemfile:
49
+
50
+ gem 'salted-rails'
51
+
52
+ And then execute:
53
+
54
+ $ bundle
55
+
56
+ Or install it yourself as:
57
+
58
+ $ gem install salted-rails
59
+
60
+ TODO: write the helper and then configure capistrano to use it ...
61
+
62
+ ## Usage
63
+
64
+ TODO: Write usage instructions here
65
+
66
+ Salt rules are copied into RAILS_ROOT/tmp/salt and pillar info into RAILS_ROOT/tmp/pillar by the `configure_salt` method.
67
+ It also (re)creates `pillar/application.sls` based on `.ruby-version`, `config/database.yml` and `Gemfile` ehenever they change.
68
+ The configuration files are also copied to `salt/railsapp/files/`.
69
+
70
+ If you move `RAILS_ROOT/tmp/salt` and `RAILS_ROOT/tmp/pillar` into a RAILS_ROOT/salt directory then you can adjust the other files as desired.
71
+ In that case only the `pillar/application.sls` and `salt/railsapp/files/*` files will be refreshed when they become stale (rather than all files).
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ require "salted_rails/version"
2
+
3
+ module SaltedRails
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,5 @@
1
+ module SaltedRails
2
+ class Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module SaltedRails
2
+ class Capistrano
3
+
4
+ end
5
+ end
6
+
@@ -0,0 +1,155 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+ #
4
+
5
+ require 'erb'
6
+ require 'yaml'
7
+ require 'fileutils'
8
+
9
+ module SaltedRails
10
+ class VagrantHelper
11
+
12
+ def initialize(rails_root, debug = false)
13
+ @logger = if debug
14
+ self
15
+ end
16
+
17
+ @rails_root = rails_root
18
+ @rails_root += '/' unless @rails_root =~ /\/$/
19
+
20
+ @gem_root = File.dirname(__FILE__) + '/../../'
21
+
22
+ @logger.info "RAILS_ROOT = #{@rails_root}" if @logger
23
+
24
+ end
25
+
26
+ def configure_vagrant(config)
27
+ config.vm.box = 'UbuntuCloud_12.04_32bit'
28
+ config.vm.box_url = 'http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-vagrant-i386-disk1.box'
29
+ config.ssh.private_key_path = '~/.ssh/id_rsa'
30
+ config.ssh.forward_agent = true
31
+ end
32
+
33
+ def configure_digital_ocean(config)
34
+ @logger.info 'Configuring digital ocean provider' if @logger
35
+ config.vm.provider :digital_ocean do |provider, override|
36
+ override.ssh.username = 'vagrant'
37
+ override.vm.box = 'digital_ocean'
38
+ override.vm.box_url = 'https://github.com/smdahlen/vagrant-digitalocean/raw/master/box/digital_ocean.box'
39
+ provider.image = 'Ubuntu 12.04 x32'
40
+ provider.region = 'San Francisco 1'
41
+ #override.vm.synced_folder '.', '/vagrant', :disabled => true
42
+ provider.ca_path = '/etc/ssl/certs/ca-certificates.crt' if File.exist?('/etc/ssl/certs/ca-certificates.crt')
43
+ end
44
+ end
45
+
46
+ def configure_salt(config)
47
+ pillarize_application_configuration
48
+ config.vm.synced_folder @rails_root + 'tmp/salt/', '/srv/salt/'
49
+ config.vm.synced_folder @rails_root + 'tmp/pillar/', '/srv/pillar/'
50
+ # Bootstrap salt
51
+ ## config.vm.provision :shell, :inline => 'salt-call --version || wget -O - http://bootstrap.saltstack.org | sudo sh'
52
+ # Provisioning #2: masterless highstate call
53
+ config.vm.provision :salt do |salt|
54
+ @logger.info 'Configuring salt provisioner' if @logger
55
+ salt.minion_config = @gem_root + 'salt/vagrant/minion'
56
+ salt.run_highstate = true
57
+ salt.verbose = true
58
+ end
59
+ end
60
+
61
+ def configure_ports(vm_config)
62
+ vm_config.vm.network :forwarded_port, :guest => 3000, :host => 3000, auto_correct: true
63
+ [ 80, 443 ].each do |port|
64
+ vm_config.vm.network :forwarded_port, :guest => port, :host => 3000+port, auto_correct: true
65
+ end
66
+ end
67
+
68
+ def configure_gui(vm_config)
69
+ vm_config.vm.boot_mode == :gui
70
+ vm_config.vm.provision :salt do |salt|
71
+ salt.minion_config = @gem_root + 'salt/vagrant/gui_minion'
72
+ end
73
+ end
74
+
75
+ def info(msg)
76
+ puts msg
77
+ end
78
+
79
+ private
80
+
81
+ # Add ruby version and gemfiles
82
+
83
+ def pillarize_application_configuration
84
+ salt_dir = @rails_root + 'salt/salt/'
85
+ pillar_dir = @rails_root + 'salt/pillar/'
86
+ copy_in_tmp = ! File.directory?(salt_dir)
87
+ if copy_in_tmp
88
+ salt_dir = @rails_root + 'tmp/salt/'
89
+ pillar_dir = @rails_root + 'tmp/pillar/'
90
+ end
91
+ copy_all = ! File.directory?(salt_dir)
92
+
93
+ pillar_app_file = pillar_dir + 'application.sls'
94
+ version_file = @rails_root + '.ruby-version'
95
+ database_file = @rails_root + 'config/database.yml'
96
+ gemfile = @rails_root + 'Gemfile'
97
+
98
+ rails_config_changed = ! (File.exist?(pillar_app_file) and File.directory?(salt_dir))
99
+ rails_config_changed ||= (File.mtime(__FILE__) > File.mtime(pillar_app_file))
100
+ files = [ version_file, database_file, gemfile ]
101
+ files <<= "#{gemfile}.lock" if File.exist? "#{gemfile}.lock"
102
+ files.each do |f|
103
+ rails_config_changed ||= (File.mtime(f) > File.mtime(pillar_app_file))
104
+ end
105
+ copy_all ||= rails_config_changed if copy_in_tmp
106
+
107
+ if copy_all
108
+ @logger.info "Copying default rules to tmp/salt and tmp/pillar" if @logger
109
+ FileUtils.rm_rf(pillar_dir)
110
+ FileUtils.rm_rf(salt_dir)
111
+ FileUtils.mkdir_p(pillar_dir)
112
+ FileUtils.mkdir_p(salt_dir)
113
+
114
+ FileUtils.cp_r(@gem_root + 'pillar/.', pillar_dir)
115
+ FileUtils.cp_r(@gem_root + 'salt/.', salt_dir)
116
+ else
117
+ @logger.info 'skipped creation of salt and pillar (up to date)' if @logger
118
+ end
119
+
120
+ if rails_config_changed
121
+ dest = salt_dir + "railsapp/files"
122
+ FileUtils.mkdir_p dest
123
+ files.each do |file|
124
+ @logger.info "Copying #{file} to #{dest}" if @logger
125
+ FileUtils.cp(file, dest)
126
+ end
127
+
128
+ File.open(pillar_app_file, 'w') do |f_out|
129
+ ENV['VAGRANT_MACHINE'] = 'true'
130
+ database_conf = YAML.load(ERB.new(IO.read(database_file)).result)
131
+ ruby_version = File.open(version_file, 'r') do |f_in|
132
+ f_in.gets.gsub(/\s/,'')
133
+ end
134
+ app_config = {
135
+ 'database' => database_conf,
136
+ 'ruby-version' => ruby_version,
137
+ 'packages' => { }
138
+ }
139
+ database_conf.each do |key, details|
140
+ app_config['packages'][details['adapter']] = true
141
+ end
142
+ #File.foreach(gemfile) do |line|
143
+ # app_config['packages']['mysql'] ||= (line =~ /^\s*gem\s*['"]mysql2?['"]/)
144
+ #end
145
+ f_out.puts app_config.to_yaml
146
+ end
147
+ else
148
+ @logger.info 'skipped configuration of salt and pillar (up to date)' if @logger
149
+ end
150
+
151
+ end
152
+
153
+ end
154
+
155
+ end
@@ -0,0 +1,3 @@
1
+ module SaltedRails
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,3 @@
1
+ username: deploy
2
+ homedir: /home/deploy
3
+ fullname: Deployer
@@ -0,0 +1,5 @@
1
+ base:
2
+ '*':
3
+ - common
4
+ - application
5
+ - capistrano
data/pillar/common.sls ADDED
@@ -0,0 +1,15 @@
1
+ {%- if grains['os'] == 'MacOS' %}
2
+ etc_dir: /opt/local/etc/
3
+ var_dir: /opt/local/var/
4
+ logs_dir: /opt/local/var/log/
5
+ {%- else %}
6
+ etc_dir: /etc/
7
+ var_dir: /var/
8
+ logs_dir: /var/log/
9
+ {%- endif %}
10
+
11
+ www_dir: /srv/www/
12
+
13
+ mysql-version: 5.5
14
+
15
+ # vim: filetype=sls
@@ -0,0 +1,3 @@
1
+ username: vagrant
2
+ homedir: /home/vagrant
3
+ fullname: Vagrant User
@@ -0,0 +1,5 @@
1
+ base:
2
+ '*':
3
+ - common
4
+ - application
5
+ - vagrant
@@ -0,0 +1,13 @@
1
+ canonical-partner-repo:
2
+ file.sed:
3
+ - name: /etc/apt/sources.list
4
+ - limit: '^# deb .*partner'
5
+ - before: '^# '
6
+ - after: ''
7
+
8
+ canonical-partner-repo-src:
9
+ file.sed:
10
+ - name: /etc/apt/sources.list
11
+ - limit: '^# deb-src .*partner'
12
+ - before: '^# '
13
+ - after: ''
@@ -0,0 +1,5 @@
1
+ whoopsie:
2
+ service.disabled:
3
+ - name: whoopsie
4
+ pkg.purged:
5
+ - name: whoopsie
File without changes
@@ -0,0 +1,14 @@
1
+ # Standard masterless salt minion set-up
2
+ master: localhost
3
+ file_client: local
4
+ state_auto_order: True
5
+
6
+ file_roots:
7
+ base:
8
+ - /srv/salt/capistrano
9
+ - /srv/salt
10
+
11
+ pillar_roots:
12
+ base:
13
+ - /srv/pillar/capistrano
14
+ - /srv/pillar
@@ -0,0 +1,6 @@
1
+ minion:
2
+ file:
3
+ - source: salt://capistrano/minion
4
+ - name: /etc/salt/minion
5
+ - mode: 644
6
+
@@ -0,0 +1,8 @@
1
+ base:
2
+ '*':
3
+ - common
4
+ - capistrano
5
+
6
+ # if GUI:
7
+ # www.chromium
8
+