minimart 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +21 -0
- data/.rspec +3 -0
- data/.travis.yml +13 -0
- data/Gemfile +3 -0
- data/README.md +198 -0
- data/Rakefile +45 -0
- data/bin/minimart +4 -0
- data/lib/minimart.rb +15 -0
- data/lib/minimart/cli.rb +93 -0
- data/lib/minimart/commands/mirror.rb +30 -0
- data/lib/minimart/commands/web.rb +91 -0
- data/lib/minimart/configuration.rb +46 -0
- data/lib/minimart/cookbook.rb +173 -0
- data/lib/minimart/download/cookbook.rb +70 -0
- data/lib/minimart/download/git_cache.rb +60 -0
- data/lib/minimart/download/git_repository.rb +41 -0
- data/lib/minimart/error.rb +32 -0
- data/lib/minimart/inventory_requirement/base_requirement.rb +81 -0
- data/lib/minimart/inventory_requirement/git_requirement.rb +87 -0
- data/lib/minimart/inventory_requirement/git_requirements_builder.rb +101 -0
- data/lib/minimart/inventory_requirement/local_path_requirement.rb +45 -0
- data/lib/minimart/inventory_requirement/local_requirements_builder.rb +31 -0
- data/lib/minimart/inventory_requirement/supermarket_requirements_builder.rb +35 -0
- data/lib/minimart/mirror.rb +12 -0
- data/lib/minimart/mirror/dependency_graph.rb +73 -0
- data/lib/minimart/mirror/download_metadata.rb +57 -0
- data/lib/minimart/mirror/inventory_builder.rb +143 -0
- data/lib/minimart/mirror/inventory_configuration.rb +74 -0
- data/lib/minimart/mirror/inventory_requirements.rb +104 -0
- data/lib/minimart/mirror/local_store.rb +107 -0
- data/lib/minimart/mirror/source.rb +57 -0
- data/lib/minimart/mirror/source_cookbook.rb +77 -0
- data/lib/minimart/mirror/sources.rb +37 -0
- data/lib/minimart/output.rb +34 -0
- data/lib/minimart/utils/archive.rb +39 -0
- data/lib/minimart/utils/file_helper.rb +34 -0
- data/lib/minimart/utils/http.rb +60 -0
- data/lib/minimart/version.rb +3 -0
- data/lib/minimart/web.rb +10 -0
- data/lib/minimart/web/cookbook_show_page_generator.rb +78 -0
- data/lib/minimart/web/cookbooks.rb +83 -0
- data/lib/minimart/web/dashboard_generator.rb +46 -0
- data/lib/minimart/web/html_generator.rb +52 -0
- data/lib/minimart/web/markdown_parser.rb +47 -0
- data/lib/minimart/web/template_helper.rb +132 -0
- data/lib/minimart/web/universe_generator.rb +109 -0
- data/minimart.gemspec +36 -0
- data/spec/fixtures/sample_cookbook.tar.gz +0 -0
- data/spec/fixtures/sample_cookbook/Berksfile +3 -0
- data/spec/fixtures/sample_cookbook/CHANGELOG.md +3 -0
- data/spec/fixtures/sample_cookbook/Gemfile +16 -0
- data/spec/fixtures/sample_cookbook/LICENSE +3 -0
- data/spec/fixtures/sample_cookbook/README.md +42 -0
- data/spec/fixtures/sample_cookbook/Thorfile +5 -0
- data/spec/fixtures/sample_cookbook/Vagrantfile +90 -0
- data/spec/fixtures/sample_cookbook/chefignore +94 -0
- data/spec/fixtures/sample_cookbook/metadata.rb +9 -0
- data/spec/fixtures/sample_cookbook/recipes/default.rb +8 -0
- data/spec/fixtures/sample_inventory.yml +16 -0
- data/spec/fixtures/simple_git_inventory.yml +8 -0
- data/spec/fixtures/simple_inventory.yml +6 -0
- data/spec/fixtures/simple_local_path_inventory.yml +5 -0
- data/spec/fixtures/universe.json +42 -0
- data/spec/fixtures/vcr_cassettes/local_path_cookbooks.yml +3316 -0
- data/spec/fixtures/vcr_cassettes/location_specific_cookbooks.yml +3316 -0
- data/spec/fixtures/vcr_cassettes/supermarket_cookbooks_graph.yml +905 -0
- data/spec/fixtures/vcr_cassettes/supermarket_cookbooks_installing_cookbooks.yml +4218 -0
- data/spec/lib/minimart/cli_spec.rb +104 -0
- data/spec/lib/minimart/commands/mirror_spec.rb +37 -0
- data/spec/lib/minimart/commands/web_spec.rb +75 -0
- data/spec/lib/minimart/configuration_spec.rb +54 -0
- data/spec/lib/minimart/cookbook_spec.rb +137 -0
- data/spec/lib/minimart/download/cookbook_spec.rb +135 -0
- data/spec/lib/minimart/download/git_cache_spec.rb +69 -0
- data/spec/lib/minimart/download/git_repository_spec.rb +39 -0
- data/spec/lib/minimart/error_spec.rb +18 -0
- data/spec/lib/minimart/inventory_requirement/base_requirement_spec.rb +38 -0
- data/spec/lib/minimart/inventory_requirement/git_requirement_spec.rb +92 -0
- data/spec/lib/minimart/inventory_requirement/git_requirements_builder_spec.rb +130 -0
- data/spec/lib/minimart/inventory_requirement/local_path_requirement_spec.rb +35 -0
- data/spec/lib/minimart/inventory_requirement/local_requirements_builder_spec.rb +33 -0
- data/spec/lib/minimart/inventory_requirement/supermarket_requirements_builder_spec.rb +69 -0
- data/spec/lib/minimart/mirror/dependency_graph_spec.rb +123 -0
- data/spec/lib/minimart/mirror/download_metadata_spec.rb +73 -0
- data/spec/lib/minimart/mirror/inventory_builder_spec.rb +195 -0
- data/spec/lib/minimart/mirror/inventory_configuration_spec.rb +86 -0
- data/spec/lib/minimart/mirror/inventory_requirements_spec.rb +78 -0
- data/spec/lib/minimart/mirror/local_store_spec.rb +64 -0
- data/spec/lib/minimart/mirror/source_spec.rb +54 -0
- data/spec/lib/minimart/mirror/sources_spec.rb +50 -0
- data/spec/lib/minimart/output_spec.rb +29 -0
- data/spec/lib/minimart/utils/archive_spec.rb +38 -0
- data/spec/lib/minimart/utils/file_helper_spec.rb +43 -0
- data/spec/lib/minimart/utils/http_spec.rb +37 -0
- data/spec/lib/minimart/web/cookbook_show_page_generator_spec.rb +101 -0
- data/spec/lib/minimart/web/cookbooks_spec.rb +70 -0
- data/spec/lib/minimart/web/dashboard_generator_spec.rb +33 -0
- data/spec/lib/minimart/web/html_generator_spec.rb +34 -0
- data/spec/lib/minimart/web/markdown_parser_spec.rb +54 -0
- data/spec/lib/minimart/web/template_helper_spec.rb +86 -0
- data/spec/lib/minimart/web/universe_generator_spec.rb +125 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/support/file_system.rb +22 -0
- data/web/_assets/javascripts/app.js +164 -0
- data/web/_assets/javascripts/backbone.min.js +6 -0
- data/web/_assets/javascripts/jquery.min.js +4 -0
- data/web/_assets/javascripts/jquery.tabslet.min.js +9 -0
- data/web/_assets/javascripts/manifest.js +5 -0
- data/web/_assets/javascripts/underscore.min.js +5 -0
- data/web/_assets/stylesheets/font-awesome.min.css +4 -0
- data/web/_assets/stylesheets/font-mfizz.css +318 -0
- data/web/_assets/stylesheets/main.css +720 -0
- data/web/_assets/stylesheets/manifest.css +4 -0
- data/web/_assets/stylesheets/normalize.css +427 -0
- data/web/assets/fonts/FontAwesome.otf +0 -0
- data/web/assets/fonts/font-mfizz.eot +0 -0
- data/web/assets/fonts/font-mfizz.svg +1344 -0
- data/web/assets/fonts/font-mfizz.ttf +0 -0
- data/web/assets/fonts/font-mfizz.woff +0 -0
- data/web/assets/fonts/fontawesome-webfont.eot +0 -0
- data/web/assets/fonts/fontawesome-webfont.svg +520 -0
- data/web/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/web/assets/fonts/fontawesome-webfont.woff +0 -0
- data/web/assets/images/header-slim.jpg +0 -0
- data/web/assets/images/icon-search.png +0 -0
- data/web/assets/images/mad-glory-logo.png +0 -0
- data/web/assets/images/main-gradient.png +0 -0
- data/web/assets/images/top-bar-logo.png +0 -0
- data/web/assets/javascripts/application.min.js +5 -0
- data/web/assets/stylesheets/application.min.css +4 -0
- data/web/templates/cookbook_show.erb +96 -0
- data/web/templates/dashboard.erb +81 -0
- data/web/templates/layout.erb +38 -0
- metadata +433 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Yjk5YWIyMGEzYTNiODU2ODJkMTE0MGJmODJkMWUyNDcxMjNiYWYzNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGU0NmJiNjNjMTJlNWVlYjA3YjlmMTlmZmFhNjQwYTBlNDgwOWYxYQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDg2MmY5MWQ1NzUxNmZjNzEyYWY1N2RiNzhlMmM4MWQ2OGEyODQ5YmNmYjYz
|
10
|
+
MjcwYWZkYWQzZGI4MTdmOWY1ODg0MTNmYzQyMmE1NzkxNGNiYjg3ZGY2N2Uw
|
11
|
+
MjA2NjZlN2U5OWIyZDE4N2E0YzQyOTZiYjYxNzgyZTI5NjdlMDM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjBiNzgzYWYzYWVhMDZiZWJmNzM0MjUzYmYyNDgxYzA0ZGUxYTE1MjcxZmYy
|
14
|
+
NDI2MzRiMWU4N2UzMWVkMWE5MDQ2YzQ2ZmY0ZDhhNTM2ZDU2OWNlNmViZGIx
|
15
|
+
M2FkYjBlYzExYjdjYWVhZTI4ZDY5OTRjMzk0ZjA1MWZlZTQyODM=
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
/.sass-cache/
|
11
|
+
/_site/
|
12
|
+
*.bundle
|
13
|
+
*.so
|
14
|
+
*.o
|
15
|
+
*.a
|
16
|
+
*.gem
|
17
|
+
mkmf.log
|
18
|
+
.ruby-version
|
19
|
+
.ruby-gemset
|
20
|
+
.rvmrc
|
21
|
+
vendor/
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- ruby-head
|
4
|
+
- 2.1.1
|
5
|
+
- 1.9.3
|
6
|
+
deploy:
|
7
|
+
provider: rubygems
|
8
|
+
api_key:
|
9
|
+
secure: WQnBmi+DIi18NXL+iCZZ9gV8YEEmLQ8LOQY/nZ7fnnX1ziHpUDZjneXAP7t762d6dNYib8f6Bs5n+HltAhrKiyY+t/jErmjS3DR1UV2uv+/lZgu0KwxA9WSph5LBLKDYw1R+fWf6E7nlnm4+fhhT19Qr5VaL7Wsf9ojiv+RCl9U=
|
10
|
+
gem: minimart
|
11
|
+
on:
|
12
|
+
tags: true
|
13
|
+
repo: electric-it/minimart
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
# MiniMart
|
2
|
+
|
3
|
+
MiniMart is a RubyGem that makes it simple to build a repository of Chef cookbooks using only static files.
|
4
|
+
|
5
|
+
Minimart is made up of two main components:
|
6
|
+
|
7
|
+
* A mirroring tool that will download any cookbooks described in an inventory file.
|
8
|
+
|
9
|
+
* A web tool that will generate a Berkshelf compatible index of the cookbooks in your inventory, and a user friendly web interface for browsing cookbooks.
|
10
|
+
|
11
|
+
## Installing Minimart
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'minimart'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install minimart
|
26
|
+
|
27
|
+
## Basic Usage
|
28
|
+
|
29
|
+
### Getting Started
|
30
|
+
|
31
|
+
After installing the `minimart` gem, you can start a new MiniMart by running the following command:
|
32
|
+
|
33
|
+
$ minimart init
|
34
|
+
|
35
|
+
### Mirroring Cookbooks
|
36
|
+
|
37
|
+
The `init` command will generate a sample `inventory.yml` file for you to use as a reference when building your own inventory. A real inventory may look like the following:
|
38
|
+
|
39
|
+
sources:
|
40
|
+
- "https://supermarket.chef.io"
|
41
|
+
cookbooks:
|
42
|
+
apache2:
|
43
|
+
versions:
|
44
|
+
- '= 3.0.0'
|
45
|
+
- '= 2.0.0'
|
46
|
+
nginx:
|
47
|
+
version: "~> 2.7.0"
|
48
|
+
git:
|
49
|
+
location: "https://github.com/miketheman/nginx.git"
|
50
|
+
tags:
|
51
|
+
- 'v2.6.0'
|
52
|
+
- 'v2.5.0'
|
53
|
+
|
54
|
+
This file allows you to specify multiple sources to fetch cookbooks from (in order of precedence). You can also specify multiple versions of the same cookbook, either from one of the sources, using Git, or a local path. All of the `version` style commands allow for plural, and singular YAML keys (version, versions, branch, branches, etc...).
|
55
|
+
|
56
|
+
Once you are done modifying the `inventory.yml` file, you can run the `mirror` command to download any cookbooks to your local inventory.
|
57
|
+
|
58
|
+
$ minimart mirror
|
59
|
+
|
60
|
+
The above inventory file would download multiple versions of the `apache2`, and `nginx` cookbooks. The inventory directory would have the following structure:
|
61
|
+
|
62
|
+
inventory
|
63
|
+
├── apache2-2.0.0
|
64
|
+
│ ├── README.md
|
65
|
+
│ ├── metadata.rb
|
66
|
+
│ ├── ... (all of the other cookbook files)
|
67
|
+
├── ... (directories and files for other cookbooks)
|
68
|
+
|
69
|
+
### Generating a MiniMart Endpoint
|
70
|
+
|
71
|
+
Once you are satisfied with the cookbooks in your inventory, you can use the `web` command to generate the MiniMart index file, archived cookbook directories, and static HTML for browsing any mirrored cookbooks. This directory structure will be built in your local directory (wherever you are running `minimart`), and can be synced to your web server, s3, etc...
|
72
|
+
|
73
|
+
The `web` command requires the user to specify a `host` to build a proper index file. The `host` should be the domain name, or IP you plan to use to host Minimart. To generate a MiniMart that would be hosted on `example.com` you would run:
|
74
|
+
|
75
|
+
$ minimart web --host=http://example.com
|
76
|
+
|
77
|
+
`web` will run through any of the cookbooks in the inventory, and generate the following:
|
78
|
+
|
79
|
+
web
|
80
|
+
├── assets
|
81
|
+
│ ├── ... (CSS, JS, etc...)
|
82
|
+
├── cookbook_files
|
83
|
+
│ ├── apache2
|
84
|
+
│ │ └── 2_0_0
|
85
|
+
│ │ └── apache2-2.0.0.tar.gz
|
86
|
+
│ ├── nginx
|
87
|
+
│ │ └── ... (additional .tar.gz cookbooks)
|
88
|
+
├── cookbooks
|
89
|
+
│ ├── apache2
|
90
|
+
│ │ └── 2.0.0.html
|
91
|
+
│
|
92
|
+
├── index.html
|
93
|
+
├── universe
|
94
|
+
|
95
|
+
It is important to note the creation of the `universe` file. This is the JSON index file that is necessary for MiniMart to work with Berkshelf. It contains a listing of all cookbook versions, and where they can be found (hence the need for the `host`).
|
96
|
+
|
97
|
+
### Deploying MiniMart
|
98
|
+
|
99
|
+
Deploying MiniMart *should* be as easy as syncing the contents of your `web` directory to a web server that will serve static files.
|
100
|
+
|
101
|
+
The caveat is that you **must configure your server to serve the `universe` file with a content-type of `application/json`**.
|
102
|
+
|
103
|
+
##### Amazon S3
|
104
|
+
You must set the 'Content-Type' Metadata of `universe` to `application/json` with the tool you are using to sync files to S3.
|
105
|
+
|
106
|
+
##### nginx
|
107
|
+
In your nginx.conf:
|
108
|
+
|
109
|
+
location /universe {
|
110
|
+
default_type application/json;
|
111
|
+
}
|
112
|
+
|
113
|
+
##### Apache
|
114
|
+
In your apache2.conf:
|
115
|
+
|
116
|
+
<Location "/universe">
|
117
|
+
ForceType application/json
|
118
|
+
</Location>
|
119
|
+
|
120
|
+
### Additional Configuration
|
121
|
+
If you are using berkshelf-api, you can add chef, and github configuration options to your `inventory.yml` file to properly download cookbooks from those sources.
|
122
|
+
|
123
|
+
sources:
|
124
|
+
- "api.berkshelf.com"
|
125
|
+
configuration:
|
126
|
+
verify_ssl: true # This defaults to true!
|
127
|
+
chef:
|
128
|
+
client_name: 'berkshelf'
|
129
|
+
client_key: '/path/to.pem'
|
130
|
+
github:
|
131
|
+
organization: "org-name"
|
132
|
+
api_endpoint: "https://api.github.com/"
|
133
|
+
web_endpoint: "https://api.github.com/"
|
134
|
+
|
135
|
+
|
136
|
+
### Example Jenkins Script
|
137
|
+
This is an example of a script that can be used by Jenkins to sync the
|
138
|
+
cookbooks to the S3 bucket. This script can be placed in the same
|
139
|
+
directory as the `inventory.yml` file created by `minimart init`. This
|
140
|
+
can be pulled down from a repository and then ran by Jenkins.
|
141
|
+
|
142
|
+
#!/bin/bash
|
143
|
+
|
144
|
+
# Exit 1 if any command fails
|
145
|
+
set -e
|
146
|
+
|
147
|
+
# Name of the repository bucket
|
148
|
+
BUCKET_NAME=your.s3.bucket.name
|
149
|
+
|
150
|
+
echo Changing to special RVM and gemset...
|
151
|
+
rvm 2.1.2
|
152
|
+
|
153
|
+
echo Updating required gems...
|
154
|
+
bundle install
|
155
|
+
|
156
|
+
echo Mirroring cookbooks...
|
157
|
+
minimart mirror
|
158
|
+
|
159
|
+
echo Generating market...
|
160
|
+
minimart web --host=$BUCKET_NAME
|
161
|
+
|
162
|
+
echo Syncing web site up to s3://$BUCKET_NAME
|
163
|
+
aws s3 sync web s3://$BUCKET_NAME --acl public-read --exclude
|
164
|
+
"web/universe"
|
165
|
+
aws s3 cp web/universe s3://$BUCKET_NAME --acl public-read
|
166
|
+
|
167
|
+
echo cleaning up Jenkins...
|
168
|
+
rm -rf ./inventory
|
169
|
+
|
170
|
+
|
171
|
+
## Contributing
|
172
|
+
|
173
|
+
1. Fork it ( https://github.com/electric-it/minimart/fork )
|
174
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
175
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
176
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
177
|
+
5. Create a new Pull Request
|
178
|
+
|
179
|
+
|
180
|
+
## License
|
181
|
+
|
182
|
+
```
|
183
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
184
|
+
you may not use this file except in compliance with the License.
|
185
|
+
You may obtain a copy of the License at
|
186
|
+
|
187
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
188
|
+
|
189
|
+
Unless required by applicable law or agreed to in writing,
|
190
|
+
software
|
191
|
+
distributed under the License is distributed on an "AS IS"
|
192
|
+
BASIS,
|
193
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
194
|
+
implied.
|
195
|
+
See the License for the specific language governing permissions
|
196
|
+
and
|
197
|
+
limitations under the License.
|
198
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
begin
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
task :default => :spec
|
6
|
+
rescue LoadError
|
7
|
+
# no rspec available
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :web do
|
11
|
+
ROOT = Pathname.new(File.dirname(__FILE__))
|
12
|
+
RAW_WEB_DIR = ROOT.join('web', '_assets')
|
13
|
+
WEB_DIR = ROOT.join('web', 'assets')
|
14
|
+
|
15
|
+
desc 'Compile assets'
|
16
|
+
task :compile => [:compile_js, :compile_css]
|
17
|
+
|
18
|
+
task :compile_js do
|
19
|
+
require 'sprockets'
|
20
|
+
require 'uglifier'
|
21
|
+
|
22
|
+
puts 'Compiling JS...'
|
23
|
+
js_dir = WEB_DIR.join('javascripts')
|
24
|
+
FileUtils.mkdir_p(js_dir)
|
25
|
+
sprockets = Sprockets::Environment.new(ROOT)
|
26
|
+
sprockets.js_compressor = :uglify
|
27
|
+
sprockets.append_path(RAW_WEB_DIR.join('javascripts'))
|
28
|
+
sprockets['manifest.js'].write_to(js_dir.join('application.min.js'))
|
29
|
+
puts 'Done Compiling JS...'
|
30
|
+
end
|
31
|
+
|
32
|
+
task :compile_css do
|
33
|
+
require 'sprockets'
|
34
|
+
require 'sass'
|
35
|
+
|
36
|
+
puts 'Compiling CSS...'
|
37
|
+
css_dir = WEB_DIR.join('stylesheets')
|
38
|
+
FileUtils.mkdir_p(css_dir)
|
39
|
+
sprockets = Sprockets::Environment.new(ROOT)
|
40
|
+
sprockets.css_compressor = :sass
|
41
|
+
sprockets.append_path(RAW_WEB_DIR.join('stylesheets'))
|
42
|
+
sprockets['manifest.css'].write_to(css_dir.join('application.min.css'))
|
43
|
+
puts 'Done Compiling CSS...'
|
44
|
+
end
|
45
|
+
end
|
data/bin/minimart
ADDED
data/lib/minimart.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Minimart
|
5
|
+
require 'minimart/version'
|
6
|
+
require 'minimart/configuration'
|
7
|
+
require 'minimart/error'
|
8
|
+
|
9
|
+
require 'minimart/mirror'
|
10
|
+
require 'minimart/web'
|
11
|
+
|
12
|
+
def self.root_path
|
13
|
+
File.dirname(__FILE__)
|
14
|
+
end
|
15
|
+
end
|
data/lib/minimart/cli.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require 'minimart'
|
4
|
+
require 'minimart/commands/mirror'
|
5
|
+
require 'minimart/commands/web'
|
6
|
+
|
7
|
+
module Minimart
|
8
|
+
# The command line interface for Minimart.
|
9
|
+
class Cli < Thor
|
10
|
+
include Thor::Actions
|
11
|
+
|
12
|
+
DEFAULT_INVENTORY_CONFIG = './inventory.yml'
|
13
|
+
DEFAULT_INVENTORY_DIRECTORY = './inventory'
|
14
|
+
DEFAULT_WEB_DIRECTORY = './web'
|
15
|
+
|
16
|
+
##
|
17
|
+
# Init
|
18
|
+
##
|
19
|
+
desc 'init', 'Begin a new Minimart.'
|
20
|
+
option :inventory_config, default: DEFAULT_INVENTORY_CONFIG
|
21
|
+
# Begin a new Minimart
|
22
|
+
def init
|
23
|
+
create_file options[:inventory_config] do
|
24
|
+
<<-YML
|
25
|
+
# sources:
|
26
|
+
# - "https://supermarket.getchef.com"
|
27
|
+
# cookbooks:
|
28
|
+
# cookbook-name:
|
29
|
+
# versions:
|
30
|
+
# - "~> 4.0.2"
|
31
|
+
# - "> 5.0.0"
|
32
|
+
# git:
|
33
|
+
# location: url | path
|
34
|
+
# branches:
|
35
|
+
# - a_branch_name
|
36
|
+
# refs:
|
37
|
+
# - SHA
|
38
|
+
|
39
|
+
YML
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Mirror
|
45
|
+
##
|
46
|
+
desc 'mirror', 'Mirror cookbooks specified in an inventory file.'
|
47
|
+
option :inventory_config,
|
48
|
+
default: DEFAULT_INVENTORY_CONFIG,
|
49
|
+
desc: 'The path to the Minimart config file. Minimart will create the file if it does not exist.'
|
50
|
+
|
51
|
+
option :inventory_directory,
|
52
|
+
default: DEFAULT_INVENTORY_DIRECTORY,
|
53
|
+
desc: 'The path to store any cookbooks downloaded by the mirroring tool.'
|
54
|
+
# Mirror cookbooks specified in an inventory file.
|
55
|
+
def mirror
|
56
|
+
Minimart::Commands::Mirror.new(options).execute!
|
57
|
+
|
58
|
+
rescue Minimart::Error::BaseError => e
|
59
|
+
Minimart::Error.handle_exception(e)
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Web
|
64
|
+
##
|
65
|
+
desc 'web', 'Generate a web interface to download any mirrored cookbooks.'
|
66
|
+
option :inventory_directory,
|
67
|
+
default: DEFAULT_INVENTORY_DIRECTORY,
|
68
|
+
desc: 'Path to the cookbooks downloaded by the mirroring tool.'
|
69
|
+
|
70
|
+
option :web_directory,
|
71
|
+
default: DEFAULT_WEB_DIRECTORY,
|
72
|
+
desc: 'Path to output the web endpoint of Minimart.'
|
73
|
+
|
74
|
+
option :host,
|
75
|
+
aliases: :h,
|
76
|
+
required: true,
|
77
|
+
desc: 'The web endpoint where Minimart will be hosted. This is required to properly generate the index file to be used by Berkshelf.'
|
78
|
+
|
79
|
+
option :html,
|
80
|
+
type: :boolean,
|
81
|
+
default: true,
|
82
|
+
desc: 'Flag to determine whether or not to generate HTML output along with the universe endpoint.'
|
83
|
+
|
84
|
+
# Generate a web interface to download any mirrored cookbooks.
|
85
|
+
def web
|
86
|
+
Minimart::Commands::Web.new(options).execute!
|
87
|
+
|
88
|
+
rescue Minimart::Error::BaseError => e
|
89
|
+
Minimart::Error.handle_exception(e)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Minimart
|
2
|
+
module Commands
|
3
|
+
# Mirror is the main entrance point for the mirroring portion of Minimart.
|
4
|
+
# Given a directory, and a path to a config file, this class
|
5
|
+
# will generate an inventory.
|
6
|
+
class Mirror
|
7
|
+
|
8
|
+
# @return [String] The path to the inventory configuration file.
|
9
|
+
attr_reader :inventory_config
|
10
|
+
|
11
|
+
# @return [String] The directory to store the inventory.
|
12
|
+
attr_reader :inventory_directory
|
13
|
+
|
14
|
+
|
15
|
+
# @param [Hash] opts
|
16
|
+
# @option opts [String] :inventory_directory The directory to store the inventory.
|
17
|
+
# @option opts [String] :inventory_config The path to the inventory configuration file.
|
18
|
+
def initialize(opts)
|
19
|
+
@inventory_directory = opts[:inventory_directory]
|
20
|
+
@inventory_config = Minimart::Mirror::InventoryConfiguration.new(opts[:inventory_config])
|
21
|
+
end
|
22
|
+
|
23
|
+
# Generate the inventory.
|
24
|
+
def execute!
|
25
|
+
builder = Minimart::Mirror::InventoryBuilder.new(inventory_directory, inventory_config)
|
26
|
+
builder.build!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|