librarian 0.0.26 → 0.1.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -3
- data/.travis.yml +7 -0
- data/Gemfile +1 -1
- data/{MIT-LICENSE → LICENSE.txt} +2 -0
- data/README.md +13 -363
- data/lib/librarian/chef/version.rb +5 -0
- data/lib/librarian/cli.rb +1 -0
- data/lib/librarian/environment.rb +8 -2
- data/lib/librarian/mock/environment.rb +6 -1
- data/lib/librarian/mock/version.rb +5 -0
- data/lib/librarian/rspec/support/cli_macro.rb +120 -0
- data/lib/librarian/source/git.rb +1 -1
- data/lib/librarian/source/git/repository.rb +10 -2
- data/lib/librarian/version.rb +1 -1
- data/librarian.gemspec +15 -22
- data/spec/functional/cli_spec.rb +27 -0
- data/spec/functional/source/git/repository_spec.rb +2 -0
- metadata +69 -100
- data/lib/librarian/chef.rb +0 -1
- data/lib/librarian/chef/cli.rb +0 -47
- data/lib/librarian/chef/dsl.rb +0 -16
- data/lib/librarian/chef/environment.rb +0 -27
- data/lib/librarian/chef/extension.rb +0 -9
- data/lib/librarian/chef/integration/knife.rb +0 -46
- data/lib/librarian/chef/manifest_reader.rb +0 -59
- data/lib/librarian/chef/source.rb +0 -4
- data/lib/librarian/chef/source/git.rb +0 -25
- data/lib/librarian/chef/source/github.rb +0 -27
- data/lib/librarian/chef/source/local.rb +0 -69
- data/lib/librarian/chef/source/path.rb +0 -12
- data/lib/librarian/chef/source/site.rb +0 -442
- data/lib/librarian/chef/templates/Cheffile +0 -15
- data/spec/functional/chef/cli_spec.rb +0 -194
- data/spec/functional/chef/source/site_spec.rb +0 -266
- data/spec/integration/chef/source/git_spec.rb +0 -441
- data/spec/integration/chef/source/site_spec.rb +0 -217
- data/spec/support/cli_macro.rb +0 -114
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -4,9 +4,16 @@ rvm:
|
|
4
4
|
- 1.8.7
|
5
5
|
- 1.9.2
|
6
6
|
- 1.9.3
|
7
|
+
- 2.0.0
|
7
8
|
- rbx-18mode
|
8
9
|
- rbx-19mode
|
10
|
+
- jruby-18mode
|
11
|
+
- jruby-19mode
|
12
|
+
- ruby-head
|
9
13
|
matrix:
|
10
14
|
allow_failures:
|
11
15
|
- rvm: rbx-18mode
|
12
16
|
- rvm: rbx-19mode
|
17
|
+
- rvm: jruby-18mode
|
18
|
+
- rvm: jruby-19mode
|
19
|
+
- rvm: ruby-head
|
data/Gemfile
CHANGED
data/{MIT-LICENSE → LICENSE.txt}
RENAMED
@@ -1,5 +1,7 @@
|
|
1
1
|
Copyright (c) 2011 ApplicationsOnline, LLC.
|
2
2
|
|
3
|
+
MIT License
|
4
|
+
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
5
7
|
"Software"), to deal in the Software without restriction, including
|
data/README.md
CHANGED
@@ -4,10 +4,6 @@ Librarian [![Build Status](https://secure.travis-ci.org/applicationsonline/libra
|
|
4
4
|
Librarian is a framework for writing bundlers, which are tools that resolve,
|
5
5
|
fetch, install, and isolate a project's dependencies, in Ruby.
|
6
6
|
|
7
|
-
Librarian ships with Librarian-Chef, which is a bundler for your Chef-based
|
8
|
-
infrastructure repositories. In the future, Librarian-Chef will be a separate
|
9
|
-
project.
|
10
|
-
|
11
7
|
A bundler written with Librarian will expect you to provide a specfile listing
|
12
8
|
your project's declared dependencies, including any version constraints and
|
13
9
|
including the upstream sources for finding them. Librarian can resolve the spec,
|
@@ -17,385 +13,39 @@ install them, and isolate them in your project.
|
|
17
13
|
A bundler written with Librarian will be similar in kind to [Bundler](http://gembundler.com),
|
18
14
|
the bundler for Ruby gems that many modern Rails applications use.
|
19
15
|
|
20
|
-
Librarian-Chef
|
21
|
-
---------------
|
22
|
-
|
23
|
-
Librarian-Chef is a tool that helps you manage the cookbooks that your chef-repo
|
24
|
-
depends on. Here are some more details.
|
25
|
-
|
26
|
-
Librarian-Chef is a bundler for infrastructure repositories using Chef. You can
|
27
|
-
use Librarian-Chef to resolve your infrastructure's cookbook dependencies, fetch
|
28
|
-
them, and install them into your infrastructure repository.
|
29
|
-
|
30
|
-
Librarian-Chef can resolve and fetch third-party, publicly-released cookbooks,
|
31
|
-
and install them into your infrastructure repository. It can also source
|
32
|
-
cookbooks directly from their own source control repositories.
|
33
|
-
|
34
|
-
Librarian-Chef can also deal with cookbooks you may actively be working on
|
35
|
-
outside your infrastructure repository. For example, it can deal with cookbooks
|
36
|
-
directly from their own private source control repositories, whether they are
|
37
|
-
remote or local to your machine, and it can deal with cookbooks released to and
|
38
|
-
hosted on a private cookbooks server.
|
39
|
-
|
40
|
-
Librarian-Chef is not primarily intended for dealing with the cookbooks you are
|
41
|
-
actively working on *within* your infrastructure repository. In such a case, you
|
42
|
-
can still use Librarian-Chef, but it is likely unnecessary.
|
43
|
-
|
44
|
-
Librarian-Chef *takes over* your `cookbooks/` directory and manages it for you
|
45
|
-
based on your `Cheffile`. Your `Cheffile` becomes the authoritative source for
|
46
|
-
the cookbooks your infrastructure repository depends on. You should not modify
|
47
|
-
the contents of your `cookbooks/` directory when using Librarian-Chef. If you
|
48
|
-
have cookbooks which are, rather than being separate projects, inherently part
|
49
|
-
of your infrastructure repository, then they should go in a separate directory,
|
50
|
-
like your `site-cookbooks/` directory, and you do not need to use Librarian-Chef
|
51
|
-
to manage them.
|
52
|
-
|
53
|
-
### The Cheffile
|
54
|
-
|
55
|
-
Every infrastruture repository that uses Librarian-Chef will have a file named
|
56
|
-
`Cheffile` in the root directory of that repository. The full specification for
|
57
|
-
which third-party, publicly-released cookbooks your infrastructure repository
|
58
|
-
depends will go here.
|
59
|
-
|
60
|
-
Here's an example `Cheffile`:
|
61
|
-
|
62
|
-
site "http://community.opscode.com/api/v1"
|
63
|
-
|
64
|
-
cookbook "ntp"
|
65
|
-
cookbook "timezone", "0.0.1"
|
66
|
-
|
67
|
-
cookbook "rvm",
|
68
|
-
:git => "https://github.com/fnichol/chef-rvm",
|
69
|
-
:ref => "v0.7.1"
|
70
|
-
|
71
|
-
cookbook "cloudera",
|
72
|
-
:path => "vendor/cookbooks/cloudera-cookbook"
|
73
|
-
|
74
|
-
Here's how it works:
|
75
|
-
|
76
|
-
We start off by declaring the *default source* for this `Cheffile`.
|
77
|
-
|
78
|
-
site "http://community.opscode.com/api/v1"
|
79
|
-
|
80
|
-
This default source in this example is the Opscode Community Site API. This is
|
81
|
-
most likely what you will want for your default source. However, you can
|
82
|
-
certainly set up your own API-compatible HTTP endpoint if you want more control.
|
83
|
-
|
84
|
-
Any time we declare a cookbook dependency without also declaring a source for
|
85
|
-
that cookbook dependency, Librarian-Chef assumes we want it to look for that
|
86
|
-
cookbook in the default source.
|
87
|
-
|
88
|
-
Any time we declare a cookbook dependency that has subsidiary cookbook
|
89
|
-
dependencies of its own, Librarian-Chef assumes we want it to look for the
|
90
|
-
subsidiary cookbook dependencies in the default source.
|
91
|
-
|
92
|
-
cookbook "ntp"
|
93
|
-
|
94
|
-
Our infrastructure repository depends on the `ntp` cookbook from the default
|
95
|
-
source. Any version of the `ntp` cookbook will fulfill our requirements.
|
96
|
-
|
97
|
-
cookbook "timezone", "0.0.1"
|
98
|
-
|
99
|
-
Our infrastructure repository depends on the `timezone` cookbook from the
|
100
|
-
default source. But only version `0.0.1` of that cookbook will do.
|
101
|
-
|
102
|
-
cookbook "rvm",
|
103
|
-
:git => "https://github.com/fnichol/chef-rvm",
|
104
|
-
:ref => "v0.7.1"
|
105
|
-
|
106
|
-
Our infrastructure repository depends on the `rvm` cookbook, but not the one
|
107
|
-
from the default source. Instead, the cookbook is to be fetched from the
|
108
|
-
specified Git repository and from the specified Git tag only.
|
109
|
-
|
110
|
-
When using a Git source, we do not have to use a `:ref =>`. If we do not,
|
111
|
-
then Librarian-Chef will assume we meant the `master` branch. (In the future,
|
112
|
-
this will be changed to whatever branch is the default branch according to
|
113
|
-
the Git remote, which may not be `master`.)
|
114
|
-
|
115
|
-
If we use a `:ref =>`, we can use anything that Git will recognize as a ref.
|
116
|
-
This includes any branch name, tag name, SHA, or SHA unique prefix. If we use a
|
117
|
-
branch, we can later ask Librarian-Chef to update the cookbook by fetching the
|
118
|
-
most recent version of the cookbook from that same branch.
|
119
|
-
|
120
|
-
The Git source also supports a `:path =>` option. If we use the path option,
|
121
|
-
Librarian-Chef will navigate down into the Git repository and only use the
|
122
|
-
specified subdirectory. Many people have the habit of having a single repository
|
123
|
-
with many cookbooks in it. If we need a cookbook from such a repository, we can
|
124
|
-
use the `:path =>` option here to help Librarian-Chef drill down and find the
|
125
|
-
cookbook subdirectory.
|
126
|
-
|
127
|
-
cookbook "cloudera",
|
128
|
-
:path => "vendor/cookbooks/cloudera-cookbook"
|
129
|
-
|
130
|
-
Our infrastructure repository depends on the `cloudera` cookbook, which we have
|
131
|
-
downloaded and copied into our repository. In this example, `vendor/cookbooks/`
|
132
|
-
is only for use with Librarian-Chef. This directory should not appear in the
|
133
|
-
`.chef/knife.rb`. Librarian-Chef will, instead, copy this cookbook from where
|
134
|
-
we vendored it in our repository into the `cookbooks/` directory for us.
|
135
|
-
|
136
|
-
The `:path =>` source won't be confused with the `:git =>` source's `:path =>`
|
137
|
-
option.
|
138
|
-
|
139
|
-
Also, there is shortcut for cookbooks hosted on GitHub, so we may write:
|
140
|
-
|
141
|
-
cookbook "rvm",
|
142
|
-
:github => "fnichol/chef-rvm"
|
143
|
-
|
144
|
-
### How to Use
|
145
|
-
|
146
|
-
Install Librarian-Chef:
|
147
|
-
|
148
|
-
$ gem install librarian
|
149
|
-
|
150
|
-
Prepare your infrastructure repository:
|
151
|
-
|
152
|
-
$ cd ~/path/to/chef-repo
|
153
|
-
$ git rm -r cookbooks
|
154
|
-
$ echo /cookbooks >> .gitignore
|
155
|
-
$ echo /tmp >> .gitignore
|
156
|
-
|
157
|
-
Librarian-Chef takes over your `cookbooks/` directory, and will always reinstall
|
158
|
-
the cookbooks listed the `Cheffile.lock` into your `cookbooks/` directory. Hence
|
159
|
-
you do not need your `cookbooks/` directory to be tracked in Git. If you
|
160
|
-
nevertheless want your `cookbooks/` directory to be tracked in Git, simple don't
|
161
|
-
`.gitignore` the directory.
|
162
|
-
|
163
|
-
If you are manually tracking/vendoring outside cookbooks within the repository,
|
164
|
-
put them in another directory such as `vendor/cookbooks/` and use the `:path =>`
|
165
|
-
source when declaring these cookbooks in your `Cheffile`. Most people will
|
166
|
-
typically not be manually tracking/vendoring outside cookbooks.
|
167
|
-
|
168
|
-
Librarian-Chef uses your `tmp/` directory for tempfiles and caches. You do not
|
169
|
-
need to track this directory in Git.
|
170
|
-
|
171
|
-
Make a Cheffile:
|
172
|
-
|
173
|
-
$ librarian-chef init
|
174
|
-
|
175
|
-
This creates an empty `Cheffile` with the Opscode Community Site API as the
|
176
|
-
default source.
|
177
|
-
|
178
|
-
Add dependencies and their sources to the `Cheffile`:
|
179
|
-
|
180
|
-
$ cat Cheffile
|
181
|
-
site 'http://community.opscode.com/api/v1'
|
182
|
-
cookbook 'ntp'
|
183
|
-
cookbook 'timezone', '0.0.1'
|
184
|
-
cookbook 'rvm',
|
185
|
-
:git => 'https://github.com/fnichol/chef-rvm',
|
186
|
-
:ref => 'v0.7.1'
|
187
|
-
cookbook 'cloudera',
|
188
|
-
:path => 'vendor/cookbooks/cloudera-cookbook'
|
189
|
-
|
190
|
-
This is the same `Cheffile` we saw above.
|
191
|
-
|
192
|
-
$ librarian-chef install [--clean] [--verbose]
|
193
|
-
|
194
|
-
This command looks at each `cookbook` declaration and fetches the cookbook from
|
195
|
-
the source specified, or from the default source if none is provided.
|
196
|
-
|
197
|
-
Each cookbook is inspected, its dependencies are determined, and each dependency
|
198
|
-
is also fetched. For example, if you declare `cookbook 'nagios'`, which
|
199
|
-
depends on other cookbooks such as `'php'`, then those other cookbooks
|
200
|
-
including `'php'` will be fetched. This goes all the way down the chain of
|
201
|
-
dependencies.
|
202
|
-
|
203
|
-
This command writes the complete resolution into `Cheffile.lock`.
|
204
|
-
|
205
|
-
This command then copies all of the fetched cookbooks into your `cookbooks/`
|
206
|
-
directory, overwriting whatever was there before. You can then use `knife
|
207
|
-
cookbook upload -all` to upload the cookbooks to your chef-server, if you are
|
208
|
-
using the client-server model.
|
209
|
-
|
210
|
-
Check your `Cheffile` and `Cheffile.lock` into version control:
|
211
|
-
|
212
|
-
$ git add Cheffile
|
213
|
-
$ git add Cheffile.lock
|
214
|
-
$ git commit -m "I want these particular versions of these particular cookbooks from these particular."
|
215
|
-
|
216
|
-
Make sure you check your `Cheffile.lock` into version control. This will ensure
|
217
|
-
dependencies do not need to be resolved every run, greatly reducing dependency
|
218
|
-
resolution time.
|
219
|
-
|
220
|
-
Get an overview of your `Cheffile.lock` with:
|
221
|
-
|
222
|
-
$ librarian-chef show
|
223
|
-
|
224
|
-
Inspect the details of specific resolved dependencies with:
|
225
|
-
|
226
|
-
$ librarian-chef show NAME1 [NAME2, ...]
|
227
|
-
|
228
|
-
Update your `Cheffile` with new/changed/removed constraints/sources/dependencies:
|
229
|
-
|
230
|
-
$ cat Cheffile
|
231
|
-
site 'http://community.opscode.com/api/v1'
|
232
|
-
cookbook 'ntp'
|
233
|
-
cookbook 'timezone', '0.0.1'
|
234
|
-
cookbook 'rvm',
|
235
|
-
:git => 'https://github.com/fnichol/chef-rvm',
|
236
|
-
:ref => 'v0.7.1'
|
237
|
-
cookbook 'monit' # new!
|
238
|
-
$ git diff Cheffile
|
239
|
-
$ librarian-chef install [--verbose]
|
240
|
-
$ git diff Cheffile.lock
|
241
|
-
$ git add Cheffile
|
242
|
-
$ git add Cheffile.lock
|
243
|
-
$ git commit -m "I also want these additional cookbooks."
|
244
|
-
|
245
|
-
Find out which dependencies are outdated and may be updated:
|
246
|
-
|
247
|
-
$ librarian-chef outdated [--verbose]
|
248
|
-
|
249
|
-
Update the version of a dependency:
|
250
|
-
|
251
|
-
$ librarian-chef update ntp timezone monit [--verbose]
|
252
|
-
$ git diff Cheffile.lock
|
253
|
-
$ git add Cheffile.lock
|
254
|
-
$ git commit -m "I want updated versions of these cookbooks."
|
255
|
-
|
256
|
-
Push your changes to the git repository:
|
257
|
-
|
258
|
-
$ git push origin master
|
259
|
-
|
260
|
-
Upload the cookbooks to your chef-server:
|
261
|
-
|
262
|
-
$ knife cookbook upload --all
|
263
|
-
|
264
|
-
### Configuration
|
265
|
-
|
266
|
-
Configuration comes from three sources with the following highest-to-lowest
|
267
|
-
precedence:
|
268
|
-
|
269
|
-
* The local config (`./.librarian/chef/config`)
|
270
|
-
* The environment
|
271
|
-
* The global config (`~/.librarian/chef/config`)
|
272
|
-
|
273
|
-
You can inspect the final configuration with:
|
274
|
-
|
275
|
-
$ librarian-chef config
|
276
|
-
|
277
|
-
You can find out where a particular key is set with:
|
278
|
-
|
279
|
-
$ librarian-chef config KEY
|
280
|
-
|
281
|
-
You can set a key at the global level with:
|
282
|
-
|
283
|
-
$ librarian-chef config KEY VALUE --global
|
284
|
-
|
285
|
-
And remove it with:
|
286
|
-
|
287
|
-
$ librarian-chef config KEY --global --delete
|
288
|
-
|
289
|
-
You can set a key at the local level with:
|
290
|
-
|
291
|
-
$ librarian-chef config KEY VALUE --local
|
292
|
-
|
293
|
-
And remove it with:
|
294
|
-
|
295
|
-
$ librarian-chef config KEY --local --delete
|
296
|
-
|
297
|
-
You cannot set or delete environment-level config keys with the CLI.
|
298
|
-
|
299
|
-
Configuration set at either the global or local level will affect subsequent
|
300
|
-
invocations of `librarian-chef`. Configurations set at the environment level are
|
301
|
-
not saved and will not affect subsequent invocations of `librarian-chef`.
|
302
|
-
|
303
|
-
You can pass a config at the environment level by taking the original config key
|
304
|
-
and transforming it: replace hyphens (`-`) with underscores (`_`) and periods
|
305
|
-
(`.`) with doubled underscores (`__`), uppercase, and finally prefix with
|
306
|
-
`LIBRARIAN_CHEF_`. For example, to pass a config in the environment for the key
|
307
|
-
`part-one.part-two`, set the environment variable
|
308
|
-
`LIBRARIAN_CHEF_PART_ONE__PART_TWO`.
|
309
|
-
|
310
|
-
Configuration affects how various commands operate.
|
311
|
-
|
312
|
-
* The `path` config sets the cookbooks directory to install to. If a relative
|
313
|
-
path, it is relative to the directory containing the `Cheffile`. The
|
314
|
-
equivalent environment variable is `LIBRARIAN_CHEF_PATH`.
|
315
|
-
|
316
|
-
* The `install.strip-dot-git` config causes the `.git/` directory to be stripped
|
317
|
-
out when installing cookbooks from a git source. This must be set to exactly
|
318
|
-
"1" to cause this behavior. The equivalent environment variable is
|
319
|
-
`LIBRARIAN_CHEF_INSTALL__STRIP_DOT_GIT`.
|
320
|
-
|
321
|
-
Configuration can be set by passing specific options to other commands.
|
322
|
-
|
323
|
-
* The `path` config can be set at the local level by passing the `--path` option
|
324
|
-
to the `install` command. It can be unset at the local level by passing the
|
325
|
-
`--no-path` option to the `install` command. Note that if this is set at the
|
326
|
-
environment or global level then, even if `--no-path` is given as an option,
|
327
|
-
the environment or global config will be used.
|
328
|
-
|
329
|
-
* The `install.strip-dot-git` config can be set at the local level by passing
|
330
|
-
the `--strip-dot-git` option to the `install` command. It can be unset at the
|
331
|
-
local level by passing the `--no-strip-dot-git` option.
|
332
|
-
|
333
|
-
### Knife Integration
|
334
|
-
|
335
|
-
You can integrate your `knife.rb` with Librarian-Chef.
|
336
|
-
|
337
|
-
Stick the following in your `knife.rb`:
|
338
|
-
|
339
|
-
require 'librarian/chef/integration/knife'
|
340
|
-
cookbook_path Librarian::Chef.install_path,
|
341
|
-
"/path/to/chef-repo/site-cookbooks"
|
342
|
-
|
343
|
-
In the above, do *not* to include the path to your `cookbooks/` directory. If
|
344
|
-
you have additional cookbooks directories in your chef-repo that you use for
|
345
|
-
vendored cookbooks (where you use the `:path =>` source in your `Cheffile`),
|
346
|
-
make sure *not* to include the paths to those additional cookbooks directories
|
347
|
-
either.
|
348
|
-
|
349
|
-
You still need to include your `site-cookbooks/` directory in the above list.
|
350
|
-
|
351
|
-
What this integration does is whenever you use any `knife` command, it will:
|
352
|
-
|
353
|
-
* Enforce that your `Cheffile` and `Cheffile.lock` are in sync
|
354
|
-
* Install the resolved cookbooks to a temporary directory
|
355
|
-
* Configure Knife to look in the temporary directory for the installed cookbooks
|
356
|
-
and not in the normal `cookbooks/` directory.
|
357
|
-
|
358
|
-
When you use this integration, any changes you make to anything in the
|
359
|
-
`cookbooks/` directory will be ignored by Knife, because Knife won't look in
|
360
|
-
that directory for your cookbooks.
|
361
|
-
|
362
16
|
How to Contribute
|
363
17
|
-----------------
|
364
18
|
|
365
19
|
### Running the tests
|
366
20
|
|
367
|
-
|
21
|
+
Ensure the gem dependencies are installed:
|
22
|
+
|
23
|
+
$ bundle
|
368
24
|
|
369
|
-
|
370
|
-
so if you want to use bundler, you can prepare the directory with the usual
|
371
|
-
`bundle install` and run each command prefixed with the usual `bundle exec`, as:
|
25
|
+
Run the tests:
|
372
26
|
|
373
|
-
$ bundle
|
374
|
-
$ bundle exec rspec spec
|
27
|
+
$ [bundle exec] rspec spec
|
375
28
|
|
376
29
|
### Installing locally
|
377
30
|
|
378
|
-
|
31
|
+
Ensure the gem dependencies are installed:
|
32
|
+
|
33
|
+
$ bundle
|
379
34
|
|
380
|
-
|
381
|
-
patch a bug and test the result on a test case. Instead of installing locally,
|
382
|
-
you are probably better served by:
|
35
|
+
Install from the repository:
|
383
36
|
|
384
|
-
$
|
385
|
-
$ $PATH_TO_LIBRARIAN_CHECKOUT/bin/librarian-chef install [--verbose]
|
37
|
+
$ [bundle exec] rake install
|
386
38
|
|
387
39
|
### Reporting Issues
|
388
40
|
|
389
|
-
Please include
|
390
|
-
`librarian-chef` commands in verbose mode by using the `--verbose` flag, and
|
391
|
-
include the verbose output in the bug report as well.
|
41
|
+
Please include a reproducible test case.
|
392
42
|
|
393
43
|
License
|
394
44
|
-------
|
395
45
|
|
396
46
|
Written by Jay Feldblum.
|
397
47
|
|
398
|
-
Copyright (c) 2011-
|
48
|
+
Copyright (c) 2011-2013 ApplicationsOnline, LLC.
|
399
49
|
|
400
50
|
Released under the terms of the MIT License. For further information, please see
|
401
|
-
the file `
|
51
|
+
the file `LICENSE.txt`.
|