buildpack-packager 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE +176 -0
  6. data/README.md +180 -0
  7. data/Rakefile +6 -0
  8. data/bin/buildpack-packager +79 -0
  9. data/buildpack-packager.gemspec +33 -0
  10. data/doc/disconnected_environments.md +50 -0
  11. data/lib/buildpack/manifest_dependency.rb +14 -0
  12. data/lib/buildpack/manifest_validator.rb +88 -0
  13. data/lib/buildpack/packager.rb +55 -0
  14. data/lib/buildpack/packager/default_versions_presenter.rb +38 -0
  15. data/lib/buildpack/packager/dependencies_presenter.rb +41 -0
  16. data/lib/buildpack/packager/manifest_schema.yml +67 -0
  17. data/lib/buildpack/packager/package.rb +139 -0
  18. data/lib/buildpack/packager/table_presentation.rb +21 -0
  19. data/lib/buildpack/packager/version.rb +5 -0
  20. data/lib/buildpack/packager/zip_file_excluder.rb +31 -0
  21. data/lib/kwalify/parser/yaml-patcher.rb +70 -0
  22. data/spec/buildpack/packager_spec.rb +7 -0
  23. data/spec/fixtures/buildpack-with-uri-credentials/VERSION +1 -0
  24. data/spec/fixtures/buildpack-with-uri-credentials/manifest.yml +36 -0
  25. data/spec/fixtures/buildpack-without-uri-credentials/VERSION +1 -0
  26. data/spec/fixtures/buildpack-without-uri-credentials/manifest.yml +36 -0
  27. data/spec/fixtures/manifests/manifest_invalid-md6.yml +18 -0
  28. data/spec/fixtures/manifests/manifest_invalid-md6_and_defaults.yml +21 -0
  29. data/spec/fixtures/manifests/manifest_valid.yml +19 -0
  30. data/spec/helpers/cache_directory_helpers.rb +15 -0
  31. data/spec/helpers/fake_binary_hosting_helpers.rb +21 -0
  32. data/spec/helpers/file_system_helpers.rb +35 -0
  33. data/spec/integration/bin/buildpack_packager/download_caching_spec.rb +85 -0
  34. data/spec/integration/bin/buildpack_packager_spec.rb +378 -0
  35. data/spec/integration/buildpack/directory_name_spec.rb +89 -0
  36. data/spec/integration/buildpack/packager_spec.rb +454 -0
  37. data/spec/integration/default_versions_spec.rb +170 -0
  38. data/spec/integration/output_spec.rb +70 -0
  39. data/spec/spec_helper.rb +12 -0
  40. data/spec/unit/buildpack/packager/zip_file_excluder_spec.rb +68 -0
  41. data/spec/unit/manifest_dependency_spec.rb +41 -0
  42. data/spec/unit/manifest_validator_spec.rb +35 -0
  43. data/spec/unit/packager/package_spec.rb +196 -0
  44. metadata +235 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e85c65266998fe1e952c48e1734d1ca8b6e9709
4
+ data.tar.gz: ffba21b8055ec13b591f32ef3495e4fb0e10c5d6
5
+ SHA512:
6
+ metadata.gz: 1078fca1adb589b73a37f7e349c8f4bbb56b5d4e913a28ef3b5e8c4c626c6783f8d207ea178195630caddc51c00f3d32c3bffb6b356b0299301f7684c2ae8b40
7
+ data.tar.gz: a2aa5e825f4d1c1cdddb8ad973ba19f5e20d153499678672ac498b86833b0f6921970a0519a7fbe5f835768b5b94d5a17694abeff75a8fce3d40c41be6b8358c
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/**/*.zip
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in buildpack-packager.gemspec
4
+ gemspec
5
+ gem 'pry'
data/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
data/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # Buildpack Packager
2
+
3
+ A [RubyGem](https://rubygems.org/) that provides tooling to package a buildpack for upload to Cloud Foundry.
4
+
5
+ For officially supported Cloud Foundry buildpacks, it is used in conjunction with [compile-extensions](https://github.com/cloudfoundry-incubator/compile-extensions).
6
+
7
+
8
+ # Usage
9
+
10
+ ## Packaging a Buildpack
11
+
12
+ Within your buildpack directory:
13
+
14
+ 1. Create a `Gemfile` and the line `gem 'buildpack-packager', git: 'https://github.com/cloudfoundry-incubator/buildpack-packager'`.
15
+ 1. Run `bundle install`.
16
+ 1. Create a `manifest.yml`
17
+ 1. Run the packager for uncached or cached mode:
18
+
19
+ ```
20
+ buildpack-packager [cached|uncached]
21
+ ```
22
+
23
+ In either mode, the packager will add (almost) everything in your
24
+ buildpack directory into a zip file. It will exclude anything marked
25
+ for exclusion in your manifest.
26
+
27
+ In `cached` mode, the packager will download and add dependencies as
28
+ described in the manifest.
29
+
30
+
31
+ ## Examining a manifest
32
+
33
+ If you'd like to get a pretty-printed summary of what's in a manifest,
34
+ run in `list` mode:
35
+
36
+ ```
37
+ buildpack-packager list
38
+ ```
39
+
40
+ Example output:
41
+
42
+ ```
43
+ +----------------------------+------------------------------+------------+
44
+ | name | version | cf_stacks |
45
+ +----------------------------+------------------------------+------------+
46
+ | ruby | 2.0.0 | cflinuxfs2 |
47
+ | ruby | 2.1.5 | cflinuxfs2 |
48
+ | ruby | 2.1.6 | cflinuxfs2 |
49
+ | ruby | 2.2.1 | cflinuxfs2 |
50
+ | ruby | 2.2.2 | cflinuxfs2 |
51
+ | jruby | ruby-1.9.3-jruby-1.7.19 | cflinuxfs2 |
52
+ | jruby | ruby-2.0.0-jruby-1.7.19 | cflinuxfs2 |
53
+ | jruby | ruby-2.2.2-jruby-9.0.0.0.rc1 | cflinuxfs2 |
54
+ | node | 0.12.2 | cflinuxfs2 |
55
+ | bundler | 1.9.7 | cflinuxfs2 |
56
+ | libyaml | 0.1.6 | cflinuxfs2 |
57
+ | openjdk1.8-latest | - | cflinuxfs2 |
58
+ | rails3_serve_static_assets | - | cflinuxfs2 |
59
+ | rails_log_stdout | - | cflinuxfs2 |
60
+ +----------------------------+------------------------------+------------+
61
+ ```
62
+
63
+ ### Option Flags
64
+
65
+ #### --force-download
66
+
67
+ By default, `buildpack-packager` stores the dependencies that it
68
+ downloads while building a cached buildpack in a local cache at
69
+ `~/.buildpack-packager`. This is in order to avoid redownloading them
70
+ when repackaging similar buildpacks. Running `buildpack-packager
71
+ cached` with the the `--force-download` option will force the packager
72
+ to download dependencies from the s3 host and ignore the local cache.
73
+
74
+ #### --use-custom-manifest
75
+
76
+ If you would like to include a different manifest file in your
77
+ packaged buildpack, you may call `buildpack-packager` with the the
78
+ `--use-custom-manifest [path/to/manifest.yml]`
79
+ option. `buildpack-packager` will generate a buildpack with the
80
+ specified manifest. If you are building a cached buildpack,
81
+ `buildpack-packager` will vendor dependencies from the specified
82
+ manifest as well.
83
+
84
+
85
+ # Manifest
86
+
87
+ The packager looks for a `manifest.yml` file in the current working
88
+ directory, which should be the root of your buildpack.
89
+
90
+ A sample manifest (all keys are required):
91
+
92
+ ```yaml
93
+ ---
94
+ language: ruby
95
+
96
+ url_to_dependency_map:
97
+ - match: bundler-(\d+\.\d+\.\d+)
98
+ name: bundler
99
+ version: $1
100
+ - match: ruby-(\d+\.\d+\.\d+)
101
+ name: ruby
102
+ version: $1
103
+
104
+ dependencies:
105
+ - name: bundler
106
+ version: 1.7.12
107
+ uri: https://pivotal-buildpacks.s3.amazonaws.com/ruby/binaries/lucid64/bundler-1.7.12.tgz
108
+ md5: ab7ebd9c9e945e3ea91c8dd0c6aa3562
109
+ cf_stacks:
110
+ - lucid64
111
+ - cflinuxfs2
112
+ - name: ruby
113
+ version: 2.1.4
114
+ uri: https://pivotal-buildpacks.s3.amazonaws.com/ruby/binaries/lucid64/ruby-2.1.4.tgz
115
+ md5: 72b4d193a11766e2a4c45c1fed65754c
116
+ cf_stacks:
117
+ - lucid64
118
+
119
+ exclude_files:
120
+ - .gitignore
121
+ - private.key
122
+ ```
123
+
124
+ ## language (required)
125
+
126
+ The language key is used to give your zip file a meaningful name.
127
+
128
+
129
+ ## url_to_dependency_map (required)
130
+
131
+ A list of regular expressions that extract and map the values of `name` and `version` to a corresponding dependency.
132
+
133
+
134
+ ## dependencies (required)
135
+
136
+
137
+ The dependencies key specifies the name, version, uri, md5, and the
138
+ cf_stacks (the root file system(s) for which it is compiled for) of a
139
+ resource which the buildpack attempts to download during staging. By
140
+ specifying them here, the packager can download them and install them
141
+ into the `dependencies/` folder in the zip file.
142
+
143
+ All keys are required:
144
+
145
+ - `name`, `version`, and `uri`:
146
+ Required for `url_to_dependency_map` to work. Make sure to create a new entry in the `url_to_dependency_map` if a matching regex does not exist for the dependency to be curled.
147
+
148
+ - `md5`:
149
+ Required to ensure that dependencies being packaged for 'cached' mode have not been compromised
150
+
151
+ - `cf_stacks`:
152
+ Required to ensure the right binary is selected for the root file system in which an app will be running on. Currently supported root file systems are lucid64(default) and cflinuxfs2. *Note that if the same dependency is used for both root file systems, both can be listed under the `cf_stacks` key.*
153
+
154
+ To have your buildpack use these 'cached' dependencies, use
155
+ `compile_extensions/bin/translate_dependency_url` to translate the url
156
+ into a locally cached url (useful for cached mode).
157
+
158
+ Read more on the [compile-extensions repo](https://github.com/cloudfoundry-incubator/compile-extensions).
159
+
160
+
161
+ ## exclude_files (required)
162
+
163
+ The exclude key lists files you do not want in your buildpack. This is
164
+ useful to remove sensitive information or extraneous files before uploading.
165
+
166
+ # Development
167
+
168
+ ## Propagating Packager Changes to CF Buildpacks
169
+
170
+ Latest changes to master will not be automatically reflected in the various Cloud Foundry buildpacks.
171
+ To propagate buildpack-packager changes:
172
+
173
+ 1. Update the version in `lib/buildpack/packager/version.rb`.
174
+ 2. Commit this change and push to master.
175
+ 3. Tag the new version with a release tag (e.g., `git tag v2.2.6`).
176
+ 4. Push the tag to origin with `git push --tags`.
177
+ 5. Update the `cf.Gemfile`s in the various buildpacks with the new release tag like so:
178
+ ```
179
+ gem 'buildpack-packager', git: 'https://github.com/cloudfoundry/buildpack-packager', tag: 'v2.2.6'
180
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ require 'buildpack/packager'
3
+ require 'optparse'
4
+ require 'buildpack/manifest_validator'
5
+
6
+ SUPPORTED_MODES = %w(cached uncached list defaults).freeze
7
+ USAGE_MSG = "USAGE: #{File.basename(__FILE__)} < #{SUPPORTED_MODES.map { |mode| '--' + mode }.join(' | ')} >".freeze
8
+
9
+ options = {
10
+ root_dir: Dir.pwd,
11
+ manifest_path: 'manifest.yml',
12
+ force_download: false
13
+ }
14
+
15
+ optparser = OptionParser.new do |opts|
16
+ opts.banner = USAGE_MSG
17
+
18
+ opts.on('--cached', 'Package dependencies with the built buildpack.') do
19
+ options[:mode] = :cached
20
+ end
21
+
22
+ opts.on('--uncached', 'Will NOT package dependencies with the built buildpack.') do
23
+ options[:mode] = :uncached
24
+ end
25
+
26
+ opts.on('--list', 'List dependencies supported by the buildpack.') do
27
+ options[:mode] = :list
28
+ end
29
+
30
+ opts.on('--defaults', 'List default dependency versions specified by the buildpack.') do
31
+ options[:mode] = :defaults
32
+ end
33
+
34
+ opts.on('--force-download', 'Force dependencies to be downloaded from the internet. (default is false)') do
35
+ options[:force_download] = true
36
+ end
37
+
38
+ opts.on('--use-custom-manifest=PATH_TO_MANIFEST', 'Use a custom manifest, passing the path as an argument.') do |manifest_path|
39
+ options[:manifest_path] = manifest_path
40
+ end
41
+
42
+ opts.on_tail('-h', '--help', 'Show this message') do
43
+ puts opts
44
+ exit
45
+ end
46
+ end
47
+
48
+ optparser.parse!
49
+
50
+ unless options[:mode]
51
+ puts optparser
52
+ exit 1
53
+ end
54
+
55
+ manifest_path = options[:manifest_path]
56
+ unless File.exist?(manifest_path)
57
+ STDERR.puts "Could not find #{manifest_path}"
58
+ exit 1
59
+ end
60
+
61
+ validator = Buildpack::ManifestValidator.new(manifest_path)
62
+ unless validator.valid?
63
+ errors = validator.errors
64
+ if errors[:manifest_parser_errors]
65
+ STDERR.print "The manifest does not conform to the schema:\n\t- "
66
+ STDERR.puts errors[:manifest_parser_errors].join("\n\t- ")
67
+ end
68
+
69
+ STDERR.puts errors[:default_version].join("\n\t")
70
+ exit 1
71
+ end
72
+
73
+ if options[:mode] == :list
74
+ puts Buildpack::Packager.list(options)
75
+ elsif options[:mode] == :defaults
76
+ puts Buildpack::Packager.defaults(options)
77
+ else
78
+ Buildpack::Packager.package(options)
79
+ end