cachivache 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e68c84fc309762c64ddf571c3f53d6e274b9140
4
- data.tar.gz: a88c0c0a348c71891bbd17d3628d44a728394c8f
3
+ metadata.gz: 3456d3dbf0a1cf2a9874b946d3d6e562d3409e07
4
+ data.tar.gz: b0f24200f939d7ea555d585253bb0191c991e8c6
5
5
  SHA512:
6
- metadata.gz: dab8a7e369843262583de50fda7e30a469cc3c4cdfa7bc4d7e75e41916ddcbdb27395a6c6410a52428a745c13632d979cc4e53364c3a01ebcb44bd628c321e8e
7
- data.tar.gz: a772bce3e35172d195786f28e60b7420ceeee4b04637905601fbd4b1823152567e8297f46b0b385185d2286d3bf70a5b8e8daa9abff6929e56ed5d13eb8b2baf
6
+ metadata.gz: 7955d555c94b1fec28a43fdc07b2debcb332a7bcae846ca111a6722c2392263f0758d46b915bab209e7f3f720adaa88143dc53ba2fa8756e20d9939d8a455b81
7
+ data.tar.gz: 007eb2d44a849c97d2209174c017a00695cb78e6c82abda2363a4524d5d23e15460831802fd60fe72bc1f1510e257abc1c5ef41c8fe6f349217502966073d33c
data/README.md CHANGED
@@ -91,7 +91,7 @@ stuff :'php-json-spec' => dependencies do
91
91
  }
92
92
  end
93
93
 
94
- configure PhpJsonSpec do
94
+ configure :PhpJsonSpec do
95
95
  let(:project_folder) { Cachivache.src_folder }
96
96
  end
97
97
  ```
@@ -260,7 +260,7 @@ stuff :'do-stuff' do
260
260
  }
261
261
  end
262
262
 
263
- configure DoStuff do
263
+ configure :DoStuff do
264
264
  let(:some_folder) { '/home/vagrant/some-folder' }
265
265
  end
266
266
  ```
@@ -314,6 +314,10 @@ To debug the provision do
314
314
 
315
315
  Not a single test was written this day :(
316
316
 
317
+ ## Roadmap
318
+
319
+ - v1.0.0: Make a custom Vagrant provisioner plugin
320
+
317
321
  ## Contributing
318
322
 
319
323
  Bug reports and pull requests are welcome on GitHub at https://github.com/cabeza-de-termo/cachivache.
@@ -32,21 +32,9 @@ end
32
32
  ######################################
33
33
 
34
34
  def stuff(task_definition, *args, &block)
35
- task_name = fully_qualified_name_of(task_definition)
36
-
37
- Rake::Task[task_name].clear if Rake::Task.task_defined?(task_name)
38
-
39
35
  task(task_definition, *args, &block)
40
36
  end
41
37
 
42
- def fully_qualified_name_of(task_definition)
43
- task_name = (task_definition.is_a? Hash) ? task_definition.keys.first : task_definition
44
- namespace = Rake.application.current_scope.path
45
-
46
- return task_name if namespace.empty?
47
- (namespace.to_s + ':' + task_name.to_s).to_sym
48
- end
49
-
50
38
  def execute_shell_command(command)
51
39
  sh command
52
40
  end
@@ -61,7 +49,5 @@ ShellContext.set_current( ShellExec.new(self) )
61
49
  ######################################
62
50
 
63
51
  all_rb_files_in Cachivache.cachivache_folder do |file|
64
- Stuff::Configuration.creating_undefined_subclasses do
65
- require file
66
- end
52
+ require file
67
53
  end
@@ -97,6 +97,17 @@ module Stuff
97
97
  shell_context.raise_validation_error(message)
98
98
  end
99
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
+
100
111
  protected
101
112
 
102
113
  def during_shell_buffer(&block)
@@ -1,13 +1,3 @@
1
- # Example:
2
- #
3
- # configure Something do
4
- # let(:bla) { '123' }
5
- # let(:ble) { 'abc' }
6
- # end
7
- def configure(klass, &block)
8
- klass.instance_eval(&block)
9
- end
10
-
11
1
  module Stuff
12
2
  class Configuration
13
3
  # Class methods
@@ -33,17 +23,6 @@ module Stuff
33
23
  variables[name].call
34
24
  end
35
25
 
36
- def creating_undefined_subclasses(&block)
37
- begin
38
- block.call
39
- rescue NameError => e
40
- raise e unless is_class_name e.name
41
-
42
- define_subclass(e.name)
43
- retry
44
- end
45
- end
46
-
47
26
  protected
48
27
 
49
28
  def method_missing(name, *more_args, &block)
@@ -52,8 +31,20 @@ module Stuff
52
31
  super(name, *more_args, &block)
53
32
  end
54
33
 
55
- def is_class_name(const)
56
- const[0] == const[0].upcase
34
+ public
35
+
36
+ def class_named(class_name)
37
+ Object.const_get(class_name)
38
+ end
39
+
40
+ def ensure_subclass_exists(class_name)
41
+ define_subclass(class_name) unless is_class_defined?(class_name)
42
+ end
43
+
44
+ protected
45
+
46
+ def is_class_defined?(name)
47
+ Object.const_defined?(name)
57
48
  end
58
49
 
59
50
  def define_subclass(name)
@@ -61,4 +52,4 @@ module Stuff
61
52
  end
62
53
  end
63
54
  end
64
- end
55
+ end
@@ -37,6 +37,6 @@ stuff :'php-json-spec' => dependencies do
37
37
  remind_to "You can check the reports in the #{StuffSample.project_folder}/ouput folder"
38
38
  end
39
39
 
40
- configure StuffSample do
40
+ configure :StuffSample do
41
41
  let(:project_folder) { Cachivache.src_folder }
42
42
  end
@@ -23,6 +23,7 @@ module Cachivache
23
23
 
24
24
  FileUtils.mkdir destination
25
25
  FileUtils.copy_entry template_folder, destination
26
+ FileUtils.cp readme_file, destination
26
27
  end
27
28
 
28
29
  def clone_stuff_library_submodule()
@@ -33,6 +34,10 @@ module Cachivache
33
34
  'https://github.com/cabeza-de-termo/stuff-library'
34
35
  end
35
36
 
37
+ def readme_file()
38
+ gem_folder + '../README.md'
39
+ end
40
+
36
41
  def raise_folder_exist_error()
37
42
  raise_error "A folder 'cachivache' already exists."
38
43
  end
@@ -1,3 +1,3 @@
1
1
  module Cachivache
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachivache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Rubi
@@ -83,7 +83,6 @@ files:
83
83
  - bin/setup
84
84
  - bin/template/.gitignore
85
85
  - bin/template/Gemfile
86
- - bin/template/README.md
87
86
  - bin/template/Rakefile
88
87
  - bin/template/Vagrantfile
89
88
  - bin/template/cachivache.rb
@@ -1,324 +0,0 @@
1
- # CabezaDeTermo::Cachivache
2
-
3
- ## Installation
4
-
5
- - `gem install cachivache`
6
-
7
- ## Description
8
-
9
- Cachivache is a provisioner for Vagrant machines with Ubuntu images.
10
-
11
- You can provision a Vagrant VM using shell scripts, or more sophisticated tools like [Puppet](https://puppetlabs.com/), [Chef](https://www.chef.io/chef/), [salt](https://docs.saltstack.com/en/latest/), [Ansible](http://www.ansible.com/) and by the time you are reading this probably a few more.
12
-
13
- If you are a developer, most of the time you just want to quickly provision you Vagrant with some bash script that installs some services and libraries, replace some parameter files in your application and probably run a few custom bash commands and that's pretty much it.
14
- The good thing about provisioning with bash scripts is that it is fast and very easy to implement (just google how to install something and toss the bash script into the provision script and that's it).
15
- On the other hand, the problems with shell provisions are that
16
-
17
- - bash is unreadable. That's not a problem most of the times, but when the a task becomes a little more complex than c&p the apt-get instructions to install something, it becomes one (even some super simple tasks like replacing parameters in a file)
18
-
19
- - it's very difficult to factorize and reuse
20
-
21
- - even if you factorize it into little bash scripts, you can't easyly declare dependencies between these scripts
22
-
23
- The provisioning tools like Puppet and Chef resolve these problems, and a lot more. Actually, they resolve so much more problems that is overkill to only use them to provision a Vagrant machine for developing.
24
- All of these tools define their own DSL and high level concepts and metaphors, they require you configure them, you must search for the correct recipes to install what you want, etc.
25
- These tools are a must to manage the provisioning of different environments, but for a single developer machine they are way too much.
26
-
27
- Cachivache is a middle ground between bash scripts and these tools.
28
- Instead of reinventing the wheel with a brand new DSL and new metaphors, Cachivache uses a wheel that we have had for ages: [Rake](https://github.com/ruby/rake).
29
-
30
- ## Usage
31
-
32
- Once you installed the `cachivache` gem, setup cachivache for your project:
33
-
34
- - Go to the root of your project
35
- - `cachivache init`
36
- - `cd cachivache`
37
-
38
- write some stuffs in your `stuff` folder and set what stuff to install and your git email and user:
39
-
40
- - `cachivache config`
41
-
42
- and that's it, you can now start Vagrant with:
43
-
44
- - `vagrant up`
45
- - `vagrant ssh`
46
- - `cd src`
47
-
48
- and you have your project running in a Vagrant machine.
49
-
50
- If you want to commit from Vagrant, add the `:'projects-setup'` as a dependency of your project in the stuff you created, it will set your git credentials.
51
-
52
- The idea behind Cachivache is to put little bash scripts in Rake tasks, and then run those tasks from within the Vagrant VM. As the Ubuntu images already come with a Ruby installation, there's not much to do at all.
53
-
54
- So, Cachivache has very few concepts:
55
-
56
- - Bash scripts, which you put in Rake tasks
57
-
58
- - Rake tasks (also called stuffs in this framework), that can depend on other Rake tasks
59
-
60
- - Ruby string interpolation, which allows you to easily parametrize stuff in the bash scripts
61
-
62
- - And the secret ingredient: stuff
63
-
64
- What is stuff? Stuff is a folder with .rb files. That's it. Cachivache believes in giving power to the people, so instead of defining how, where and when you must organize your scripts, it will let you organize things in any way you want in a couple of folders: `stuff-library` and `stuff`. No recipes, playbooks, roles, bags, configurations, minions, masters, slaves, facts, etc. Just put stuff in a folder.
65
- [`stuff-library`](https://github.com/cabeza-de-termo/stuff-library) folder holds some existing stuff you can use to install things, and in `stuff` you can toss your own stuff for your project.
66
-
67
- ## So, what does a stuff look like?
68
-
69
- Well, here's an example stuff that setups all the necessary things to work on a php library:
70
-
71
- ```ruby
72
- dependencies = [
73
- :'projects-setup',
74
- :graphviz,
75
- :xdebug,
76
- :'php-cli',
77
- :composer,
78
- ]
79
-
80
- stuff :'php-json-spec' => dependencies do
81
- shell %{
82
- cd #{PhpJsonSpec.project_folder}
83
-
84
- composer install
85
-
86
- # Run the test coverage report
87
- php vendor/bin/phpunit -c phpunit-with-coverage.xml
88
-
89
- # Generate the documentation
90
- php vendor/bin/phpdoc
91
- }
92
- end
93
-
94
- configure PhpJsonSpec do
95
- let(:project_folder) { Cachivache.src_folder }
96
- end
97
- ```
98
- ## How do I tell Cachivache what to install?
99
-
100
- Edit the file `cachivache.rb` and define the stuffs to install in the section
101
-
102
- ```ruby
103
- ####################################
104
- # Define what stuff to install
105
- ####################################
106
-
107
- let(:stuff_to_install) {
108
- [
109
- 'ruby-json-spec',
110
- 'some-other-stuff',
111
- 'a-namespace:and-another-one:more-stuff',
112
- 'mysql-server', # You can install any stuff as long as it is defined
113
- ]
114
- }
115
- ```
116
-
117
- Note that if you set the dependencies of each stuff correctly, you will only have to tell Cachivache to install the top most stuff, and Rake will do the rest for you. Thanks Rake!
118
-
119
- ## What other awesome features has Cachivache?
120
-
121
- As I said before, all the work is done by Rake, so pretty much none.
122
-
123
- There is some sintactic sugar you can use to perform some common task though. But please note that using any of these shorcuts is not mandatory at all, you can just stick to plain old shell scripts.
124
-
125
- If you haven't see any ruby code before, here are some tips to use in Cachivache stuffs:
126
-
127
- ### You can define strings in several ways:
128
-
129
- ```ruby
130
- stuff :'do-stuff' do
131
- shell %Q{
132
- echo "stuff"
133
- }
134
- end
135
-
136
- # or
137
-
138
- stuff :'do-stuff' do
139
- shell %Q[
140
- echo "stuff"
141
- ]
142
- end
143
-
144
- # or
145
-
146
- stuff :'do-stuff' do
147
- shell %(
148
- echo "stuff"
149
- )
150
- end
151
-
152
- # or in a single line
153
-
154
- stuff :'do-stuff' do
155
- shell %Q{echo "stuff"}
156
- end
157
-
158
- # or with ""
159
-
160
- stuff :'do-stuff' do
161
- shell "echo \"stuff\""
162
- end
163
- ```
164
-
165
- You see in the last example that if we define strings using "" we need to scape internals \", so the simpliest is to use `%Q{}`.
166
-
167
- ### You can call as many `sh` blocks within a task as you like. You can also :invoke and :execute other tasks:
168
-
169
- ```ruby
170
- stuff :'do-stuff' do
171
- shell %Q{
172
- echo "stuff"
173
- }
174
-
175
- invoke 'install-apache'
176
-
177
- shell %Q{
178
- echo "even more stuff"
179
- }
180
-
181
- execute 'restart-apache'
182
-
183
- shell! %Q{
184
- echo "You would normally not need to use :shell! (note the exclamation mark) but you can"
185
- }
186
- end
187
- ```
188
-
189
- The difference between :invoke and :execute is that :execute will perform the task every time it's called, whilst :invoke will only run the task once during the provision. So, to install and configure stuff use :invoke, but to turn things on and off use :execute.
190
- Or if your tasks are idempotent, always use :execute to make things simplier. It's up to you.
191
-
192
- ### Instead of using bash `if ! ...; then; .... fi`, you can use these Cachivache helpers:
193
-
194
- ```ruby
195
- stuff :'do-stuff' do
196
- shell_unless file_exists: '/bla.conf' do
197
- shell %Q{
198
- ls -la
199
- rm -rf bla
200
- }
201
- end
202
- end
203
- ```
204
-
205
- ```ruby
206
- stuff :'do-stuff' do
207
- shell_unless folder_exists: '/bla' do
208
- shell %Q{
209
- ls -la
210
- rm -rf bla
211
- }
212
- end
213
- end
214
- ```
215
-
216
- ```ruby
217
- stuff :'do-stuff' do
218
- shell_unless file: '/bla', contains: 'some regex' do
219
- shell %Q{
220
- ls -la
221
- rm -rf bla
222
- }
223
- end
224
- end
225
- ```
226
-
227
- ```ruby
228
- stuff :'do-stuff' do
229
- shell_unless command: 'java -version', contains: 'java 1.8' do
230
- shell %Q{
231
- ls -la
232
- rm -rf bla
233
- }
234
- end
235
- end
236
- ```
237
-
238
- - To append and replace text in a file, you can use this Cachivache helper:
239
-
240
- ```ruby
241
- stuff :'do-stuff' do
242
- in_file "/etc/bla.conf" do
243
- shell replace pattern: "%user%", with: "admin"
244
-
245
- shell append "[cachivache]"
246
- shell append "path='/bla'"
247
- shell append :new_line
248
- end
249
- end
250
- ```
251
-
252
- ### You can use variables instead of hardcoding values in the scripts:
253
-
254
- ```ruby
255
- stuff :'do-stuff' do
256
- shell %Q{
257
- mkdir #{DoStuff.some_folder}
258
-
259
- mkdir #{SomethingDefinedElsewhereWorksToo.some_folder}
260
- }
261
- end
262
-
263
- configure DoStuff do
264
- let(:some_folder) { '/home/vagrant/some-folder' }
265
- end
266
- ```
267
-
268
- ### If you want to remind the user of something after the provision is done, in any task use :remind_to
269
-
270
- ```ruby
271
- stuff :'do-stuff' do
272
- shell %Q{
273
- ls -la
274
- }
275
-
276
- remind_to "Please don't forget to add '#{Cachivache.vagrant_ip_address} cachivache.com' to your /etc/hosts file"
277
- end
278
- ```
279
- ## What if I want to use my own [`stuff-library`](https://github.com/cabeza-de-termo/stuff-library)?
280
-
281
- No prob! Go to your `cachivache` folder and:
282
-
283
- - `cachivache add-stuff-library git@github.com:someuser/my-very-own-stuff-library.git`
284
-
285
- Cachivache will load any .rb file in the cachivache folder, so your library stuff will be loaded too.
286
-
287
- To update some stuff library from git do:
288
-
289
- - `cachivache update-stuff-libraries my-very-own-stuff-library`
290
-
291
- To update all the stuff libraries do:
292
-
293
- - `cachivache update-stuff-libraries`
294
-
295
- To remove a stuff library do:
296
-
297
- - `cachivache remove-stuff-libraries stuff-library`
298
-
299
- ## Debugging
300
-
301
- During the building of the stuff, it's useful to be able to see what the provision
302
- what would do instead of running it.
303
-
304
- To debug the provision do
305
-
306
- - Go to the root of your project
307
- - `cd cachivache`
308
- - `vagrant ssh`
309
- - `cd src/cachivache` (now you are in Vagrant)
310
- - `bundle install`
311
- - `rake explain` will output the complete shell script without running it
312
- - `rake some-stuff` will execute only some-stuff and its dependencies
313
-
314
- ## Running the tests
315
-
316
- Not a single test was written this day :(
317
-
318
- ## Contributing
319
-
320
- Bug reports and pull requests are welcome on GitHub at https://github.com/cabeza-de-termo/cachivache.
321
-
322
- ## License
323
-
324
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).