json-spec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.gitmodules +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +960 -0
- data/Rakefile +10 -0
- data/api_documentation.md +611 -0
- data/cachivache/.gitignore +1 -0
- data/cachivache/Gemfile +4 -0
- data/cachivache/README.md +247 -0
- data/cachivache/Rakefile +19 -0
- data/cachivache/Vagrantfile +70 -0
- data/cachivache/cachivache.rb +59 -0
- data/cachivache/lib/let-behaviour.rb +27 -0
- data/cachivache/lib/rake-helper.rb +131 -0
- data/cachivache/lib/sh-file-context.rb +39 -0
- data/cachivache/lib/sh-if-context.rb +31 -0
- data/cachivache/stuff/.gitkeep +0 -0
- data/cachivache/stuff/ruby-json-spec.rb +22 -0
- data/examples/example-1-simple.rb +66 -0
- data/examples/example-2-default-expectations.rb +63 -0
- data/examples/example-3-each-field.rb +104 -0
- data/examples/example-4-to-be-as-defined-in.rb +117 -0
- data/examples/example-5-custom-expectations.rb +153 -0
- data/examples/example-6-custom-messages.rb +36 -0
- data/examples/example-7-full-example.rb +231 -0
- data/examples/fixtures.rb +77 -0
- data/examples/validation-printer.rb +47 -0
- data/json-spec.gemspec +29 -0
- data/lib/cabeza-de-termo/json-spec/errors/error.rb +6 -0
- data/lib/cabeza-de-termo/json-spec/errors/expectation-not-found-error.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/errors/modifier-not-found-error.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/errors/unkown-json-type-error.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/errors/validation-error.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/default-expectations/default-expectation-builder.rb +29 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/default-expectations/default-expectations-mapping.rb +54 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/block-expectation-definition.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/class-expectation-definition.rb +15 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectation-definition.rb +19 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expectations-definition-builder.rb +136 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expecting-all-of-expectation-definition.rb +23 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expecting-any-of-expectation-definition.rb +23 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/expecting-expectation-definition.rb +17 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-builders/negating-expectation-definition.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/expectation-library-definition-builder.rb +35 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/class-modifier-definition.rb +15 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/composing-modifiers-definition.rb +28 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/modifier-definition.rb +13 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/definition-builders/modifier-builders/modifiers-definition-builder.rb +73 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/expectations-library.rb +150 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/initializers/default-library-initializer.rb +265 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/initializers/library-initializer.rb +9 -0
- data/lib/cabeza-de-termo/json-spec/expectations-library/messages/expectation-messages-mapping.rb +27 -0
- data/lib/cabeza-de-termo/json-spec/expectations/abstract-expectation.rb +39 -0
- data/lib/cabeza-de-termo/json-spec/expectations/all-expectations-composite.rb +33 -0
- data/lib/cabeza-de-termo/json-spec/expectations/any-expectation-composite.rb +33 -0
- data/lib/cabeza-de-termo/json-spec/expectations/block-expectation.rb +28 -0
- data/lib/cabeza-de-termo/json-spec/expectations/expectation.rb +51 -0
- data/lib/cabeza-de-termo/json-spec/expectations/is-email-expectation.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expectations/is-scalar-expectation.rb +17 -0
- data/lib/cabeza-de-termo/json-spec/expectations/is-url-expectation.rb +21 -0
- data/lib/cabeza-de-termo/json-spec/expectations/negated-expectation.rb +31 -0
- data/lib/cabeza-de-termo/json-spec/expectations/runner/abstract-expectations-runner.rb +27 -0
- data/lib/cabeza-de-termo/json-spec/expectations/runner/can-be-absent-expectations-runner.rb +50 -0
- data/lib/cabeza-de-termo/json-spec/expectations/runner/can-be-null-expectations-runner.rb +48 -0
- data/lib/cabeza-de-termo/json-spec/expectations/runner/expectations-runner.rb +43 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-any-of.rb +62 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-anything.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-each-field.rb +58 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-each.rb +58 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-expression.rb +314 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-field-name.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-field.rb +76 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-list.rb +40 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-object.rb +82 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-scalar.rb +20 -0
- data/lib/cabeza-de-termo/json-spec/expressions/json-spec.rb +174 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/abstract-instantiator.rb +9 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/all-expectations-composite-instantiator.rb +12 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/any-expectation-composite-instantiator.rb +12 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/block-expectation-instantiator.rb +16 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/composite-instantiator.rb +45 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/modifier-composite-instantiator.rb +12 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/negated-expectation-instantiator.rb +20 -0
- data/lib/cabeza-de-termo/json-spec/instantiators/patial-application-instantiator.rb +26 -0
- data/lib/cabeza-de-termo/json-spec/json-spec.rb +2 -0
- data/lib/cabeza-de-termo/json-spec/message-formatters/block-message-formatter.rb +15 -0
- data/lib/cabeza-de-termo/json-spec/message-formatters/erb-message-formatter.rb +60 -0
- data/lib/cabeza-de-termo/json-spec/message-formatters/message-formatter.rb +9 -0
- data/lib/cabeza-de-termo/json-spec/metaprogramming/message-send.rb +37 -0
- data/lib/cabeza-de-termo/json-spec/metaprogramming/message.rb +37 -0
- data/lib/cabeza-de-termo/json-spec/metaprogramming/object-method.rb +14 -0
- data/lib/cabeza-de-termo/json-spec/modifiers/can-be-absent-modifier.rb +13 -0
- data/lib/cabeza-de-termo/json-spec/modifiers/can-be-null-modifier.rb +13 -0
- data/lib/cabeza-de-termo/json-spec/modifiers/expression-modifier.rb +9 -0
- data/lib/cabeza-de-termo/json-spec/modifiers/modifier-composite.rb +27 -0
- data/lib/cabeza-de-termo/json-spec/signals/signal.rb +6 -0
- data/lib/cabeza-de-termo/json-spec/signals/skip-branch-signal.rb +8 -0
- data/lib/cabeza-de-termo/json-spec/utilities/bind.rb +20 -0
- data/lib/cabeza-de-termo/json-spec/utilities/range.rb +70 -0
- data/lib/cabeza-de-termo/json-spec/value-holders/accessors-chain.rb +27 -0
- data/lib/cabeza-de-termo/json-spec/value-holders/missing-value.rb +21 -0
- data/lib/cabeza-de-termo/json-spec/value-holders/value-holder.rb +135 -0
- data/lib/cabeza-de-termo/json-spec/version.rb +5 -0
- data/lib/cabeza-de-termo/json-spec/walkers/expression-walker.rb +66 -0
- data/lib/cabeza-de-termo/json-spec/walkers/json-expectations-runner.rb +214 -0
- data/lib/cabeza-de-termo/json-spec/walkers/json-expression-explainer.rb +183 -0
- data/lib/cabeza-de-termo/json-spec/walkers/reporter/expectation-report.rb +63 -0
- data/lib/cabeza-de-termo/json-spec/walkers/reporter/json-expectations-reporter.rb +111 -0
- data/lib/cabeza-de-termo/json-spec/walkers/validator/json-validator-error.rb +29 -0
- data/lib/cabeza-de-termo/json-spec/walkers/validator/json-validator.rb +133 -0
- data/lib/cabeza-de-termo/json-spec/walkers/value-holders-stack-behaviour.rb +57 -0
- metadata +242 -0
@@ -0,0 +1 @@
|
|
1
|
+
.vagrant
|
data/cachivache/Gemfile
ADDED
@@ -0,0 +1,247 @@
|
|
1
|
+
# CabezaDeTermo::Cachivache
|
2
|
+
|
3
|
+
Cachivache is a provisioner for Vagrant machines that use Ubuntu images.
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
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.
|
8
|
+
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).
|
9
|
+
On the other hand, the problems with shell provisions are that
|
10
|
+
|
11
|
+
- 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)
|
12
|
+
|
13
|
+
- it's very difficult to factorize and reuse
|
14
|
+
|
15
|
+
- even if you factorize it into little bash scripts, you can't easyly declare dependencies between these scripts
|
16
|
+
|
17
|
+
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.
|
18
|
+
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.
|
19
|
+
These tools are a must to manage the provisioning of different environments, but for a developer machine they are way too much.
|
20
|
+
|
21
|
+
Cachivache is a middle ground between bash scripts and these tools.
|
22
|
+
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).
|
23
|
+
|
24
|
+
The idea behind Cachivache is to put little bash scripts in Rake tasks, and the 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.
|
25
|
+
|
26
|
+
So, Cachivache has very few concepts:
|
27
|
+
|
28
|
+
- Bash scripts, which you put in Rake tasks
|
29
|
+
|
30
|
+
- Rake tasks, that can depend on other Rake tasks
|
31
|
+
|
32
|
+
- Ruby string interpolation, which allows you to easily parametrize stuff in the bash scripts
|
33
|
+
|
34
|
+
- And the secret ingredient: stuff
|
35
|
+
|
36
|
+
What is stuff? Stuff is a folder. 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.
|
37
|
+
[`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.
|
38
|
+
|
39
|
+
## So, what does a stuff look like?
|
40
|
+
|
41
|
+
Well, here's an example stuff that setups all the necessary things to work on a php library:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
dependencies = [
|
45
|
+
:'projects-setup',
|
46
|
+
:graphviz,
|
47
|
+
:xdebug,
|
48
|
+
:composer
|
49
|
+
]
|
50
|
+
|
51
|
+
namespace :stuff do
|
52
|
+
task :'php-json-spec' => dependencies do
|
53
|
+
sh %{
|
54
|
+
cd #{PHPJsonSpec.project_folder}
|
55
|
+
|
56
|
+
composer install
|
57
|
+
|
58
|
+
# Run the test coverage report
|
59
|
+
php vendor/bin/phpunit -c phpunit-with-coverage.xml
|
60
|
+
|
61
|
+
# Generate the documentation
|
62
|
+
php vendor/bin/phpdoc
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class PHPJsonSpec
|
68
|
+
include LetBehaviour
|
69
|
+
|
70
|
+
let(:project_folder) { Cachivache.src_folder }
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
That's all there is. Bash + Rake + string interpolation + a little sintatic sugar.
|
75
|
+
|
76
|
+
## What other awesome features has Cachivache?
|
77
|
+
|
78
|
+
As I said before, all the work is done by Rake, so pretty much none.
|
79
|
+
|
80
|
+
There is some sintactic sugar you can use to perform some common task though.
|
81
|
+
|
82
|
+
If you haven't see any ruby code before, here are some tips to use in Cachivache stuffs:
|
83
|
+
|
84
|
+
### You can define strings in several ways:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
task :'do-stuff' do
|
88
|
+
sh %Q{
|
89
|
+
echo "stuff"
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
# or
|
94
|
+
|
95
|
+
task :'do-stuff' do
|
96
|
+
sh %Q[
|
97
|
+
echo "stuff"
|
98
|
+
]
|
99
|
+
end
|
100
|
+
|
101
|
+
# or
|
102
|
+
|
103
|
+
task :'do-stuff' do
|
104
|
+
sh %(
|
105
|
+
echo "stuff"
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
# or in a single line
|
110
|
+
|
111
|
+
task :'do-stuff' do
|
112
|
+
sh %Q{echo "stuff"}
|
113
|
+
end
|
114
|
+
|
115
|
+
# or with ""
|
116
|
+
|
117
|
+
task :'do-stuff' do
|
118
|
+
sh "echo \"stuff\""
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
You see in the last example that if we define strings using "" we need to scape internals \", so the simpliest is to use `%Q{}`.
|
123
|
+
|
124
|
+
### You can call as many `sh` blocks in a task as you like:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
task :'do-stuff' do
|
128
|
+
sh %Q{
|
129
|
+
echo "stuff"
|
130
|
+
}
|
131
|
+
|
132
|
+
sh %Q{
|
133
|
+
echo "even more stuff"
|
134
|
+
}
|
135
|
+
end
|
136
|
+
```
|
137
|
+
|
138
|
+
### You can invoke and execute other tasks from within a task:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
task :'do-stuff' do
|
142
|
+
invoke 'install-apache'
|
143
|
+
execute 'restart-apache'
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
147
|
+
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.
|
148
|
+
Or always use :execute to make things simplier. It's up to you.
|
149
|
+
|
150
|
+
### Instead of using bash `if ! ...; then; .... fi`, you can use these Cachivache helpers:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
task :'do-stuff' do
|
154
|
+
sh_unless file_exists: '/bla.conf' do
|
155
|
+
sh %Q{
|
156
|
+
ls -la
|
157
|
+
rm -rf bla
|
158
|
+
}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
```
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
task :'do-stuff' do
|
165
|
+
sh_unless folder_exists: '/bla' do
|
166
|
+
sh %Q{
|
167
|
+
ls -la
|
168
|
+
rm -rf bla
|
169
|
+
}
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
task :'do-stuff' do
|
176
|
+
sh_unless file: '/bla', contains: 'some regex' do
|
177
|
+
sh %Q{
|
178
|
+
ls -la
|
179
|
+
rm -rf bla
|
180
|
+
}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
```
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
task :'do-stuff' do
|
187
|
+
sh_unless command: 'java -version', contains: 'java 1.8' do
|
188
|
+
sh %Q{
|
189
|
+
ls -la
|
190
|
+
rm -rf bla
|
191
|
+
}
|
192
|
+
end
|
193
|
+
end
|
194
|
+
```
|
195
|
+
|
196
|
+
- To append and replace text in a file, you can use this Cachivache helper:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
task :'do-stuff' do
|
200
|
+
sh_in_file "/etc/bla.conf" do
|
201
|
+
replace pattern: "%user%", with: "admin"
|
202
|
+
|
203
|
+
append "[cachivache]"
|
204
|
+
append "path='/bla'"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
```
|
208
|
+
|
209
|
+
### If you want to remind the user of something after the provision is done, in any task use :remind_to
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
task :'do-stuff' do
|
213
|
+
sh %Q{
|
214
|
+
ls -la
|
215
|
+
}
|
216
|
+
|
217
|
+
remind_to "Please don't forget to add '#{Cachivache.vagrant_ip_address} cachivache.com' to your /etc/hosts file"
|
218
|
+
end
|
219
|
+
```
|
220
|
+
|
221
|
+
## Installation
|
222
|
+
|
223
|
+
- Go to the root of your project
|
224
|
+
- `git clone git@github.com:cabeza-de-termo/cachivache.git`
|
225
|
+
- `cd cachivache/`
|
226
|
+
- `rm -rf .git/`
|
227
|
+
- `git submodule add git@github.com:cabeza-de-termo/stuff-library.git`
|
228
|
+
|
229
|
+
Now edit `cachivache.rb` and set what stuff to install and your git email and user:
|
230
|
+
|
231
|
+
- `pico cachivache.rb`
|
232
|
+
|
233
|
+
## What if I want to use my own stuff-library?
|
234
|
+
|
235
|
+
No prob! just replace or add to the previous step your custom library:
|
236
|
+
|
237
|
+
- `git submodule add git@github.com:someuser/my-very-own-stuff-library.git`
|
238
|
+
|
239
|
+
Cachivache will load any .rb file in the cachivache folder, so your library stuff will be loaded too.
|
240
|
+
|
241
|
+
## Contributing
|
242
|
+
|
243
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cabeza-de-termo/cachivache.
|
244
|
+
|
245
|
+
## License
|
246
|
+
|
247
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/cachivache/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'lib/rake-helper'
|
2
|
+
|
3
|
+
raise_validation_error "Please, define some Cachivache:stuff_to_install in './cachivache.rb' task and run 'vagrant provision' again" if Cachivache.stuff_to_install.empty?
|
4
|
+
|
5
|
+
task :provision do
|
6
|
+
Cachivache.stuff_to_install.each do |stuff_name|
|
7
|
+
show_info "Provisioning #{stuff_name}"
|
8
|
+
|
9
|
+
invoke stuff_name
|
10
|
+
end
|
11
|
+
|
12
|
+
show_info "All done!!!"
|
13
|
+
end
|
14
|
+
|
15
|
+
task default: :provision
|
16
|
+
|
17
|
+
at_exit do
|
18
|
+
show_reminders
|
19
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
require_relative 'cachivache'
|
5
|
+
|
6
|
+
Vagrant.configure(2) do |config|
|
7
|
+
# Every Vagrant development environment requires a box. You can search for
|
8
|
+
# boxes at https://atlas.hashicorp.com/search.
|
9
|
+
config.vm.box = "ubuntu/trusty32"
|
10
|
+
|
11
|
+
# Create a private network, which allows host-only access to the machine
|
12
|
+
# using a specific IP.
|
13
|
+
config.vm.network "private_network", ip: Cachivache.vagrant_ip_address
|
14
|
+
|
15
|
+
# Map the source folder
|
16
|
+
config.vm.synced_folder "../", Cachivache.src_folder
|
17
|
+
|
18
|
+
# Map the host ~/.ssh folder
|
19
|
+
config.vm.synced_folder "~/.ssh", Cachivache.ssh_keys_folder
|
20
|
+
|
21
|
+
# Provider-specific configuration so you can fine-tune various
|
22
|
+
# backing providers for Vagrant. These expose provider-specific options.
|
23
|
+
|
24
|
+
config.vm.provider "virtualbox" do |vb|
|
25
|
+
# Display the VirtualBox GUI when booting the machine
|
26
|
+
vb.gui = Cachivache.wants_gui?
|
27
|
+
|
28
|
+
# Customize the amount of memory on the VM:
|
29
|
+
vb.memory = Cachivache.wants_gui? ? "4096" : "1024"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Enable provisioning with a shell script. Additional provisioners such as
|
33
|
+
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
|
34
|
+
# documentation for more information about their specific syntax and use.
|
35
|
+
|
36
|
+
# Provisioning the VM with the custom provision-scripts
|
37
|
+
|
38
|
+
config.vm.provision "rbenv",
|
39
|
+
type: "shell",
|
40
|
+
privileged: false,
|
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
|
44
|
+
|
45
|
+
sudo apt-get install git-core -y
|
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
|
50
|
+
|
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
|
54
|
+
|
55
|
+
git clone git://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler
|
56
|
+
|
57
|
+
sudo gem install bundler
|
58
|
+
fi
|
59
|
+
}
|
60
|
+
|
61
|
+
config.vm.provision "rake-provision",
|
62
|
+
type: "shell",
|
63
|
+
privileged: false,
|
64
|
+
inline: %Q{
|
65
|
+
cd #{Cachivache.cachivache_folder}
|
66
|
+
|
67
|
+
bundle install
|
68
|
+
rake provision
|
69
|
+
}
|
70
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative 'lib/let-behaviour'
|
2
|
+
|
3
|
+
class Cachivache
|
4
|
+
include LetBehaviour
|
5
|
+
|
6
|
+
# Vagrant params
|
7
|
+
|
8
|
+
let(:vagrant_ip_address) { '192.168.0.101' }
|
9
|
+
|
10
|
+
let(:home_folder) { '/home/vagrant' }
|
11
|
+
|
12
|
+
let(:src_folder) { home_folder + '/src' }
|
13
|
+
let(:ssh_keys_folder) { home_folder + '/ssh-keys' }
|
14
|
+
let(:bin_folder) { home_folder + '/bin-cachivache' }
|
15
|
+
|
16
|
+
# Cachivache folders
|
17
|
+
|
18
|
+
let(:cachivache_folder) { src_folder + '/cachivache' }
|
19
|
+
let(:stuff_library_folder) { cachivache_folder + '/stuff-library' }
|
20
|
+
let(:stuff_folder) { cachivache_folder + '/stuff' }
|
21
|
+
|
22
|
+
let(:wants_gui?) { false }
|
23
|
+
|
24
|
+
# Developer params
|
25
|
+
|
26
|
+
####################################
|
27
|
+
# Define what stuff to install
|
28
|
+
####################################
|
29
|
+
|
30
|
+
let(:stuff_to_install) {
|
31
|
+
[
|
32
|
+
'stuff:ruby-json-spec'
|
33
|
+
]
|
34
|
+
}
|
35
|
+
|
36
|
+
####################################
|
37
|
+
# Define your git user
|
38
|
+
####################################
|
39
|
+
|
40
|
+
let(:git_user_email) { 'martinrubi@gmail.com' }
|
41
|
+
let(:git_user_name) { 'Martin Rubi' }
|
42
|
+
|
43
|
+
####################################
|
44
|
+
# Define your git credentials
|
45
|
+
####################################
|
46
|
+
|
47
|
+
let(:git_credentials) { %Q{
|
48
|
+
host github.com
|
49
|
+
HostName github.com
|
50
|
+
IdentityFile #{Cachivache.ssh_keys_folder}/id_rsa
|
51
|
+
User git
|
52
|
+
|
53
|
+
host bitbucket.org
|
54
|
+
HostName bitbucket.org
|
55
|
+
IdentityFile #{Cachivache.ssh_keys_folder}/id_rsa
|
56
|
+
User git
|
57
|
+
}
|
58
|
+
}
|
59
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module LetBehaviour
|
2
|
+
def self.included(base)
|
3
|
+
base.extend(self)
|
4
|
+
end
|
5
|
+
|
6
|
+
def variables()
|
7
|
+
@variables ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_variable?(name)
|
11
|
+
variables.key?(name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def is_defined?(name)
|
15
|
+
has_variable?(name) && !variables[name].nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def let(name, &block)
|
19
|
+
variables[name] = block.call
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(method_name, *args, &block)
|
23
|
+
return variables[method_name] if has_variable?(method_name)
|
24
|
+
|
25
|
+
super(method_name, *args, &block)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'colorize'
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
require_relative 'let-behaviour'
|
6
|
+
require_relative 'sh-file-context'
|
7
|
+
require_relative 'sh-if-context'
|
8
|
+
require_relative '../cachivache'
|
9
|
+
|
10
|
+
public
|
11
|
+
|
12
|
+
# Require all .rb files in a folder
|
13
|
+
def require_all_rb_files_in(folder)
|
14
|
+
Dir[Pathname.new(folder) + '**/*.rb'].each do |file|
|
15
|
+
require file
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def invoke(task_name, *args)
|
20
|
+
Rake::Task[task_name].invoke(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute(task_name, *args)
|
24
|
+
Rake::Task[task_name].execute(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Examples:
|
28
|
+
#
|
29
|
+
# sh_unless file_exists: '/bla.conf' do
|
30
|
+
# sh %Q{
|
31
|
+
# ls -la
|
32
|
+
# rm -rf bla
|
33
|
+
# }
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# sh_unless folder_exists: '/bla' do
|
37
|
+
# sh %Q{
|
38
|
+
# ls -la
|
39
|
+
# rm -rf bla
|
40
|
+
# }
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# sh_unless file: '/bla', contains: 'some regex' do
|
44
|
+
# sh %Q{
|
45
|
+
# ls -la
|
46
|
+
# rm -rf bla
|
47
|
+
# }
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# sh_unless command: 'java -version', contains: 'java 1.8' do
|
51
|
+
# sh %Q{
|
52
|
+
# ls -la
|
53
|
+
# rm -rf bla
|
54
|
+
# }
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
def sh_unless(params, &block)
|
58
|
+
if params.key?(:file_exists)
|
59
|
+
sh unless_file_exists(params[:file_exists], &block)
|
60
|
+
return
|
61
|
+
end
|
62
|
+
if params.key?(:folder_exists)
|
63
|
+
sh unless_folder_exists(params[:folder_exists], &block)
|
64
|
+
return
|
65
|
+
end
|
66
|
+
if params.key?(:file) && params.key?(:contains)
|
67
|
+
sh unless_regex_in_file(params[:contains], params[:file], &block)
|
68
|
+
return
|
69
|
+
end
|
70
|
+
if params.key?(:command) && params.key?(:contains)
|
71
|
+
sh unless_regex_in_command(params[:contains], params[:command], &block)
|
72
|
+
return
|
73
|
+
end
|
74
|
+
raise 'Invalid unless option'
|
75
|
+
end
|
76
|
+
|
77
|
+
def unless_file_exists(filename, &block)
|
78
|
+
ShIfContext.with(guard: "[ ! -e #{filename} ]", &block)
|
79
|
+
end
|
80
|
+
|
81
|
+
def unless_folder_exists(folder, &block)
|
82
|
+
ShIfContext.with(guard: "[ ! -d #{folder} ]", &block)
|
83
|
+
end
|
84
|
+
|
85
|
+
def unless_regex_in_file(regex, filename, &block)
|
86
|
+
ShIfContext.with(guard: "! grep -q \"#{regex}\" \"#{filename}\"", &block)
|
87
|
+
end
|
88
|
+
|
89
|
+
def unless_regex_in_command(regex, command, &block)
|
90
|
+
ShIfContext.with(guard: "! #{command} | grep -q \"#{regex}\"", &block)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Examples:
|
94
|
+
#
|
95
|
+
# sh_in_file "/bla.conf" do
|
96
|
+
# replace pattern: "%user%", with: "admin"
|
97
|
+
#
|
98
|
+
# append "[cachivache]"
|
99
|
+
# append "path='/bla'"
|
100
|
+
# end
|
101
|
+
def sh_in_file(filename, &block)
|
102
|
+
sh ShFileContext.with(file: filename, &block)
|
103
|
+
end
|
104
|
+
|
105
|
+
def reminders()
|
106
|
+
@reminders ||= []
|
107
|
+
end
|
108
|
+
|
109
|
+
# Examples:
|
110
|
+
#
|
111
|
+
# remind_to 'This is shown when the provision ends'
|
112
|
+
def remind_to(text)
|
113
|
+
reminders << text
|
114
|
+
end
|
115
|
+
|
116
|
+
def show_info(text)
|
117
|
+
puts '-----------------------------------------------'.red
|
118
|
+
puts text.green
|
119
|
+
puts '-----------------------------------------------'.red
|
120
|
+
end
|
121
|
+
|
122
|
+
def show_reminders()
|
123
|
+
reminders.each { |alert| show_info(alert) }
|
124
|
+
end
|
125
|
+
|
126
|
+
def raise_validation_error(message)
|
127
|
+
show_info(message)
|
128
|
+
exit
|
129
|
+
end
|
130
|
+
|
131
|
+
require_all_rb_files_in Cachivache.cachivache_folder
|