cachivache 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d395340edc5efa34f8cafead802c3ff0726da99
4
- data.tar.gz: 2c1cb76ae62c0fa558cad5072e64d68fc762cfce
3
+ metadata.gz: 3057e44a88c0f053f9d6a60541f0acf8a45f9278
4
+ data.tar.gz: 26bfabc484bffff7e437b221cb4e82981959e6a9
5
5
  SHA512:
6
- metadata.gz: 7d48d5f20a32d6e2a6759fb005670199096d7b30fdbbb6ce6e475a2bd8800a8b1209857daa816e20075f8942a7be7a43f14fb386de5b2c73b5d38e825d889763
7
- data.tar.gz: 92eb614e6831df563bf4a5099dbd0814e570438b34d4d5580eeb9ad276ac392348b1e146ea00137685eafaf313738b43609ffc3b0df4ca1011b95ef633d53f8d
6
+ metadata.gz: 8a2e63fbfbc9c455df606679bdfceca6b9622ed0a78ebbcceac470a34b8606928e64ee16b8eadef4cbe784d48428d7dd5c8064a6dc366f9d554e0bf541bee88d
7
+ data.tar.gz: b04204bfd561b2a22b24814d67fdd2b967ec8d0c8b0a324afde9c3f2e0043be730c7706154b33656ad63125bb60d1dec3ae6e9e63fc51f54aaa2b658598bd6d0
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rake'
4
- gem 'colorize'
4
+ gem 'colorize'
5
+ gem 'cachivache-helpers'
@@ -1,13 +1,47 @@
1
- require_relative 'lib/rake-helper'
1
+ require 'rake'
2
+
3
+ require_relative 'cachivache'
4
+ require 'cabeza-de-termo/cachivache-helpers/helpers'
5
+
6
+ ######################################
7
+ # Include all stuffs behaviours
8
+ ######################################
9
+
10
+ include Stuff::ApiBehaviour
11
+ include Stuff::RemindersBehaviour
12
+ include RakeAdaptor
13
+ ShellContext.set_current( ShellExec.new(self) )
14
+
15
+ ######################################
16
+ # Validate the provision configuration
17
+ ######################################
2
18
 
3
19
  raise_validation_error "Please define the parameter Cachivache.git_user_email in './cachivache.rb' run 'vagrant provision' again" unless Cachivache.is_defined?(:git_user_email)
4
20
  raise_validation_error "Please define the parameter Cachivache.git_user_name in './cachivache.rb' run 'vagrant provision' again" unless Cachivache.is_defined?(:git_user_name)
5
21
  raise_validation_error "Please define some Cachivache.stuff_to_install in './cachivache.rb' run 'vagrant provision' again" if Cachivache.stuff_to_install.empty?
6
22
 
23
+ ######################################
24
+ # Load all the .rb files in this folder
25
+ ######################################
26
+
27
+ all_rb_files_in Cachivache.cachivache_folder do |file|
28
+ require file
29
+ end
30
+
31
+ ######################################
32
+ # Define the tasks that run the provision
33
+ ######################################
34
+
35
+ def stuff_to_install(&block)
36
+ Cachivache.stuff_to_install.each do |stuff_name|
37
+ block.call stuff_name
38
+ end
39
+ end
40
+
7
41
  def provision_stuff_to_install()
8
42
  stuff_to_install do |stuff_name|
9
43
  show_info "Provisioning #{stuff_name}"
10
- invoke stuff_name
44
+ invoke_stuff stuff_name
11
45
  end
12
46
  show_info "All done!!!"
13
47
  end
@@ -17,7 +51,7 @@ stuff :provision do
17
51
  end
18
52
 
19
53
  stuff :explain do
20
- ShellContext.set_current ShellDebugger.new
54
+ ShellContext.set_current ShellDebugger.new(self)
21
55
  provision_stuff_to_install
22
56
  end
23
57
 
@@ -39,23 +39,25 @@ Vagrant.configure(2) do |config|
39
39
  type: "shell",
40
40
  privileged: false,
41
41
  inline: %Q{
42
- # From https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04
43
- if [ ! -d $HOME/.rbenv/ ]; then
42
+ # From https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04
43
+ if [ ! -d $HOME/.rbenv/ ]; then
44
44
 
45
- sudo apt-get install git-core -y
45
+ sudo apt-get update
46
46
 
47
- git clone git://github.com/sstephenson/rbenv.git .rbenv
48
- echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
49
- echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
47
+ sudo apt-get install git-core -y
50
48
 
51
- git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
52
- echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
53
- source ~/.bash_profile
49
+ git clone git://github.com/sstephenson/rbenv.git .rbenv
50
+ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
51
+ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
54
52
 
55
- git clone git://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler
53
+ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
54
+ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
55
+ source ~/.bash_profile
56
56
 
57
- sudo gem install bundler
58
- fi
57
+ git clone git://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler
58
+
59
+ sudo gem install bundler
60
+ fi
59
61
  }
60
62
 
61
63
  config.vm.provision "rake-provision",
@@ -1,4 +1,4 @@
1
- require_relative 'lib/stuff-configuration'
1
+ require_relative 'utilities/stuff-configuration'
2
2
 
3
3
  class Cachivache < Stuff::Configuration
4
4
  # Vagrant params
@@ -21,13 +21,13 @@ namespace :'cachivache-com' do
21
21
  task :'enable-site' do
22
22
  shell %Q{
23
23
  # Copy .conf to /etc/apache2/sites-available
24
- sudo cp -f #{Cachivache.provision_folder}/stuff/php-site-sample/cachivache-com.conf /etc/apache2/sites-available
24
+ sudo cp -f #{Cachivache.stuff_folder}/php-site-sample/cachivache-com.conf /etc/apache2/sites-available
25
25
 
26
26
  # Enable cachivache-com.conf
27
27
  sudo a2ensite cachivache-com.conf
28
28
 
29
29
  # Link the /data/www to the actual src location
30
- sudo ln -s #{CachivacheDotCom.app_folder}/web /var/www/cachivache-com
30
+ sudo ln -s #{CachivacheDotCom.app_folder}/web /var/www/cachivache.com
31
31
  }
32
32
  end
33
33
 
@@ -54,7 +54,7 @@ namespace :'cachivache-com' do
54
54
 
55
55
  task :'populate-mysql' do
56
56
  shell %Q{
57
- mysql -uroot -p#{MysqlServer.root_password} < #{Cachivache.provision_folder}/stuff/php-site-sample/populate-mysql.sql
57
+ mysql -uroot -p#{MysqlServer.root_password} < #{Cachivache.stuff_folder}/php-site-sample/populate-mysql.sql
58
58
  }
59
59
  end
60
- end
60
+ end
@@ -1,4 +1,4 @@
1
- configure :CachivacheDotCom
2
- let(:app_folder) { CachivacheDotCom.src_folder + "/yii2" }
1
+ configure :CachivacheDotCom do
2
+ let(:app_folder) { Cachivache.src_folder + "/yii2" }
3
3
  let(:domain) { 'cachivache.com' }
4
4
  end
@@ -1,3 +1,5 @@
1
+ # Duplicating this class here and in cachivache-helpers sucks, but I haven't
2
+ # come up with a decent workaround yet, so ...
1
3
  module Stuff
2
4
  class Configuration
3
5
  # Class methods
@@ -1,3 +1,3 @@
1
1
  module Cachivache
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachivache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Rubi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2015-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -86,22 +86,13 @@ files:
86
86
  - bin/template/Rakefile
87
87
  - bin/template/Vagrantfile
88
88
  - bin/template/cachivache.rb
89
- - bin/template/lib/rake-helper.rb
90
- - bin/template/lib/shell-contexts/shell-context.rb
91
- - bin/template/lib/shell-contexts/shell-exec.rb
92
- - bin/template/lib/shell-contexts/shell_buffer.rb
93
- - bin/template/lib/shell-contexts/shell_debugger.rb
94
- - bin/template/lib/shell-file-context.rb
95
- - bin/template/lib/shell-if-context.rb
96
- - bin/template/lib/stuff-api-behaviour.rb
97
- - bin/template/lib/stuff-configuration.rb
98
- - bin/template/lib/stuff-reminders-behaviour.rb
99
89
  - bin/template/stuff/.gitkeep
100
90
  - bin/template/stuff/php-site-sample/cachivache-com.conf
101
91
  - bin/template/stuff/php-site-sample/cachivache-com.rb
102
92
  - bin/template/stuff/php-site-sample/config.rb
103
93
  - bin/template/stuff/php-site-sample/populate-mysql.sql
104
94
  - bin/template/stuff/stuff-sample.rb
95
+ - bin/template/utilities/stuff-configuration.rb
105
96
  - cachivache.gemspec
106
97
  - lib/cachivache.rb
107
98
  - lib/cachivache/add-stuff-libraries-command.rb
@@ -1,53 +0,0 @@
1
- require 'rake'
2
- require 'colorize'
3
- require 'pathname'
4
-
5
- require_relative '../cachivache'
6
-
7
- # Helper - Iterate all .rb files in a folder
8
- def all_rb_files_in(folder, &block)
9
- Dir[Pathname.new(folder) + '**/*.rb'].each do |file|
10
- block.call(file)
11
- end
12
- end
13
-
14
- def stuff_to_install(&block)
15
- Cachivache.stuff_to_install.each do |stuff_name|
16
- block.call stuff_name
17
- end
18
- end
19
-
20
- public
21
-
22
- ######################################
23
- # require all the files in /lib first
24
- ######################################
25
-
26
- all_rb_files_in Cachivache.cachivache_folder + '/lib' do |file|
27
- require file
28
- end
29
-
30
- ######################################
31
- # Stuff Api behaviour
32
- ######################################
33
-
34
- def stuff(task_definition, *args, &block)
35
- task(task_definition, *args, &block)
36
- end
37
-
38
- def execute_shell_command(command)
39
- sh command
40
- end
41
-
42
- include Stuff::ApiBehaviour
43
- include Stuff::RemindersBehaviour
44
-
45
- ShellContext.set_current( ShellExec.new(self) )
46
-
47
- ######################################
48
- # Load the rest of the files
49
- ######################################
50
-
51
- all_rb_files_in Cachivache.cachivache_folder do |file|
52
- require file
53
- end
@@ -1,63 +0,0 @@
1
- class ShellContext
2
- @current = nil
3
- @reminders = []
4
-
5
- def self.current()
6
- @current
7
- end
8
-
9
- def self.set_current(shell_context)
10
- @current = shell_context
11
- end
12
-
13
- def self.during_shell_context(new_shell_context, &block)
14
- current_shell_context = @current
15
-
16
- @current = new_shell_context
17
-
18
- block.call
19
-
20
- @current = current_shell_context
21
- end
22
-
23
- def self.reminders()
24
- @reminders
25
- end
26
-
27
- def self.show_info(text)
28
- puts '-----------------------------------------------'.red
29
- puts text.green
30
- puts '-----------------------------------------------'.red
31
- end
32
-
33
- # Instance methods
34
-
35
- def shell(command)
36
- raise 'Subclass responsibility'
37
- end
38
-
39
- def shell!(command)
40
- raise 'Subclass responsibility'
41
- end
42
-
43
- def invoke(task_name, *args)
44
- Rake::Task[task_name].invoke(*args)
45
- end
46
-
47
- def execute(task_name, *args)
48
- Rake::Task[task_name].execute(*args)
49
- end
50
-
51
- def remind_to(text)
52
- ShellContext.reminders << text
53
- end
54
-
55
- def raise_validation_error(message)
56
- show_info(message)
57
- exit
58
- end
59
-
60
- def show_info(text)
61
- ShellContext.show_info(text)
62
- end
63
- end
@@ -1,19 +0,0 @@
1
- require_relative 'shell-context'
2
-
3
- class ShellExec < ShellContext
4
- def initialize(scope)
5
- @scope = scope
6
- end
7
-
8
- def scope()
9
- @scope
10
- end
11
-
12
- def shell(command)
13
- shell! command
14
- end
15
-
16
- def shell!(command)
17
- scope.execute_shell_command(command)
18
- end
19
- end
@@ -1,25 +0,0 @@
1
- require_relative 'shell-context'
2
-
3
- class ShellBuffer < ShellContext
4
- def initialize(underlaying_shell_context)
5
- @underlaying_shell_context = underlaying_shell_context
6
- @contents = ''
7
- end
8
-
9
- def underlaying_shell_context()
10
- @underlaying_shell_context
11
- end
12
-
13
- def contents
14
- @contents
15
- end
16
-
17
- def shell(command)
18
- contents << "\n" unless contents.empty?
19
- contents << command
20
- end
21
-
22
- def shell!(command)
23
- underlaying_shell_context.shell! command
24
- end
25
- end
@@ -1,11 +0,0 @@
1
- require_relative 'shell-context'
2
-
3
- class ShellDebugger < ShellContext
4
- def shell(command)
5
- puts command.cyan
6
- end
7
-
8
- def shell!(command)
9
- puts command.red
10
- end
11
- end
@@ -1,36 +0,0 @@
1
- require_relative 'stuff-api-behaviour'
2
-
3
- class ShellFileContext
4
- include Stuff::ApiBehaviour
5
-
6
- def self.with(args, &block)
7
- new(args).evaluate_with block
8
- end
9
-
10
- def initialize(args)
11
- @filename = args[:file]
12
- end
13
-
14
- def evaluate_with(block)
15
- instance_eval(&block)
16
- end
17
-
18
- # replace pattern: "user: ''", with: "user: 'admin'"
19
- def replace(params)
20
- pattern = params[:pattern]
21
- replacement = params[:with]
22
- %Q{
23
- sudo sed -i 's|#{pattern}|#{replacement}|g' #{@filename}
24
- }
25
- end
26
-
27
- # append '[mongo]'
28
- # append :new_line
29
- def append(text)
30
- text = "\n" if text == :new_line
31
-
32
- %Q{
33
- echo "#{text}" | sudo tee -a #{@filename}
34
- }
35
- end
36
- end
@@ -1,21 +0,0 @@
1
- require_relative 'stuff-api-behaviour'
2
-
3
- class ShellIfContext
4
- include Stuff::ApiBehaviour
5
-
6
- def self.with(args, &block)
7
- new(args).evaluate_with block
8
- end
9
-
10
- def initialize(args)
11
- @guard = args[:guard]
12
- end
13
-
14
- def evaluate_with(block)
15
- shell "if #{@guard}; then"
16
-
17
- instance_eval(&block)
18
-
19
- shell "fi"
20
- end
21
- end
@@ -1,145 +0,0 @@
1
- module Stuff
2
- module ApiBehaviour
3
- def shell_context()
4
- ShellContext.current
5
- end
6
-
7
- def invoke(task_name, *args)
8
- shell_context.invoke(task_name, *args)
9
- end
10
-
11
- def execute(task_name, *args)
12
- shell_context.execute(task_name, *args)
13
- end
14
-
15
- def shell(command)
16
- shell_context.shell(command)
17
- end
18
-
19
- def shell!(command)
20
- shell_context.shell!(command)
21
- end
22
-
23
- # Examples:
24
- #
25
- # shell_unless file_exists: '/bla.conf' do
26
- # shell %Q{
27
- # ls -la
28
- # rm -rf bla
29
- # }
30
- # end
31
- #
32
- # shell_unless folder_exists: '/bla' do
33
- # shell %Q{
34
- # ls -la
35
- # rm -rf bla
36
- # }
37
- # end
38
- #
39
- # shell_unless file: '/bla', contains: 'some regex' do
40
- # shell %Q{
41
- # ls -la
42
- # rm -rf bla
43
- # }
44
- # end
45
- #
46
- # shell_unless command: 'java -version', contains: 'java 1.8' do
47
- # shell %Q{
48
- # ls -la
49
- # rm -rf bla
50
- # }
51
- # end
52
- #
53
- def shell_unless(params, &block)
54
- if params.key?(:file_exists)
55
- shell unless_file_exists(params[:file_exists], &block)
56
- return
57
- end
58
- if params.key?(:folder_exists)
59
- shell unless_folder_exists(params[:folder_exists], &block)
60
- return
61
- end
62
- if params.key?(:file) && params.key?(:contains)
63
- shell unless_regex_in_file(params[:contains], params[:file], &block)
64
- return
65
- end
66
- if params.key?(:command) && params.key?(:contains)
67
- shell unless_regex_in_command(params[:contains], params[:command], &block)
68
- return
69
- end
70
- raise 'Invalid unless option'
71
- end
72
-
73
- # Examples:
74
- #
75
- # in_file "/bla.conf" do
76
- # shell replace pattern: "%user%", with: "admin"
77
- #
78
- # shell append "[cachivache]"
79
- # shell append "path='/bla'"
80
- # end
81
- def in_file(filename, &block)
82
- script = during_shell_buffer do
83
- ShellFileContext.with(file: filename, &block)
84
- end
85
-
86
- shell script
87
- end
88
-
89
- # Examples:
90
- #
91
- # remind_to 'This is shown when the provision ends'
92
- def remind_to(text)
93
- shell_context.remind_to(text)
94
- end
95
-
96
- def raise_validation_error(message)
97
- shell_context.raise_validation_error(message)
98
- end
99
-
100
- # Example:
101
- #
102
- # configure :Something do
103
- # let(:bla) { '123' }
104
- # let(:ble) { 'abc' }
105
- # end
106
- def configure(class_name, &block)
107
- Stuff::Configuration.ensure_subclass_exists(class_name)
108
- Stuff::Configuration.class_named(class_name).instance_eval(&block)
109
- end
110
-
111
- protected
112
-
113
- def during_shell_buffer(&block)
114
- temporary_shell_buffer = ShellBuffer.new(shell_context)
115
-
116
- ShellContext.during_shell_context(temporary_shell_buffer, &block)
117
-
118
- temporary_shell_buffer.contents
119
- end
120
-
121
- def unless_file_exists(filename, &block)
122
- during_shell_buffer do
123
- ShellIfContext.with(guard: "[ ! -e #{filename} ]", &block)
124
- end
125
- end
126
-
127
- def unless_folder_exists(folder, &block)
128
- during_shell_buffer do
129
- ShellIfContext.with(guard: "[ ! -d #{folder} ]", &block)
130
- end
131
- end
132
-
133
- def unless_regex_in_file(regex, filename, &block)
134
- during_shell_buffer do
135
- ShellIfContext.with(guard: "! grep -q \"#{regex}\" \"#{filename}\"", &block)
136
- end
137
- end
138
-
139
- def unless_regex_in_command(regex, command, &block)
140
- during_shell_buffer do
141
- ShellIfContext.with(guard: "! #{command} | grep -q \"#{regex}\"", &block)
142
- end
143
- end
144
- end
145
- end
@@ -1,11 +0,0 @@
1
- module Stuff
2
- module RemindersBehaviour
3
- def show_reminders()
4
- ShellContext.reminders.each { |alert| show_info(alert) }
5
- end
6
-
7
- def show_info(text)
8
- ShellContext.show_info(text)
9
- end
10
- end
11
- end