buildpack-support 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/LICENSE +202 -0
  2. data/NOTICE +2 -0
  3. data/docs/cache.md +77 -0
  4. data/docs/component.md +1 -0
  5. data/docs/configuration.md +27 -0
  6. data/docs/logging.md +54 -0
  7. data/docs/other.md +1 -0
  8. data/docs/rake.md +1 -0
  9. data/docs/repository.md +116 -0
  10. data/docs/test.md +1 -0
  11. data/lib/buildpack_support.rb +18 -0
  12. data/lib/buildpack_support/base_buildpack.rb +166 -0
  13. data/lib/buildpack_support/buildpack_version.rb +124 -0
  14. data/lib/buildpack_support/cache.rb +24 -0
  15. data/lib/buildpack_support/cache/application_cache.rb +41 -0
  16. data/lib/buildpack_support/cache/cached_file.rb +103 -0
  17. data/lib/buildpack_support/cache/download_cache.rb +280 -0
  18. data/lib/buildpack_support/cache/inferred_network_failure.rb +26 -0
  19. data/lib/buildpack_support/cache/internet_availability.rb +64 -0
  20. data/lib/buildpack_support/component.rb +24 -0
  21. data/lib/buildpack_support/component/application.rb +76 -0
  22. data/lib/buildpack_support/component/base_component.rb +78 -0
  23. data/lib/buildpack_support/component/base_droplet.rb +96 -0
  24. data/lib/buildpack_support/component/downloads.rb +88 -0
  25. data/lib/buildpack_support/component/services.rb +84 -0
  26. data/lib/buildpack_support/component/versioned_dependency_component.rb +71 -0
  27. data/lib/buildpack_support/component/versioned_downloads.rb +57 -0
  28. data/lib/buildpack_support/component/with_timing.rb +40 -0
  29. data/lib/buildpack_support/configuration_utils.rb +58 -0
  30. data/lib/buildpack_support/constantize.rb +46 -0
  31. data/lib/buildpack_support/dash_case.rb +29 -0
  32. data/lib/buildpack_support/directory_finder.rb +45 -0
  33. data/lib/buildpack_support/filtering_pathname.rb +227 -0
  34. data/lib/buildpack_support/format_duration.rb +57 -0
  35. data/lib/buildpack_support/logging.rb +22 -0
  36. data/lib/buildpack_support/logging/delegating_logger.rb +48 -0
  37. data/lib/buildpack_support/logging/logger_factory.rb +148 -0
  38. data/lib/buildpack_support/qualify_path.rb +36 -0
  39. data/lib/buildpack_support/rake.rb +22 -0
  40. data/lib/buildpack_support/rake/buildpack_stage_task.rb +86 -0
  41. data/lib/buildpack_support/rake/cached_artifact_finder.rb +99 -0
  42. data/lib/buildpack_support/rake/check_api_doc_task.rb +70 -0
  43. data/lib/buildpack_support/rake/dependency_cache_task.rb +87 -0
  44. data/lib/buildpack_support/rake/disable_remote_downloads_task.rb +80 -0
  45. data/lib/buildpack_support/rake/package_task.rb +133 -0
  46. data/lib/buildpack_support/rake/package_zip_task.rb +80 -0
  47. data/lib/buildpack_support/rake/repository_configuration_finder.rb +66 -0
  48. data/lib/buildpack_support/rake/write_version_file_task.rb +82 -0
  49. data/lib/buildpack_support/repository.rb +24 -0
  50. data/lib/buildpack_support/repository/configured_item.rb +81 -0
  51. data/lib/buildpack_support/repository/repository_index.rb +98 -0
  52. data/lib/buildpack_support/repository/wildcard_version_resolver.rb +75 -0
  53. data/lib/buildpack_support/shell.rb +41 -0
  54. data/lib/buildpack_support/snake_case.rb +30 -0
  55. data/lib/buildpack_support/space_case.rb +29 -0
  56. data/lib/buildpack_support/test/application_helper.rb +41 -0
  57. data/lib/buildpack_support/test/base_component_helper.rb +59 -0
  58. data/lib/buildpack_support/test/base_droplet_helper.rb +36 -0
  59. data/lib/buildpack_support/test/console_helper.rb +57 -0
  60. data/lib/buildpack_support/test/environment_helper.rb +32 -0
  61. data/lib/buildpack_support/test/internet_availability_helper.rb +29 -0
  62. data/lib/buildpack_support/test/logging_helper.rb +50 -0
  63. data/lib/buildpack_support/test/scratch_helper.rb +32 -0
  64. data/lib/buildpack_support/test/versioned_dependency_component_helper.rb +32 -0
  65. data/lib/buildpack_support/test/with_load_path_helper.rb +27 -0
  66. data/lib/buildpack_support/to_b.rb +38 -0
  67. data/lib/buildpack_support/tokenized_version.rb +157 -0
  68. data/lib/buildpack_support/version.rb +23 -0
  69. data/spec/buildpack_support/base_buildpack_spec.rb +112 -0
  70. data/spec/buildpack_support/buildpack_version_spec.rb +122 -0
  71. data/spec/buildpack_support/cache/application_cache_spec.rb +56 -0
  72. data/spec/buildpack_support/cache/cached_file_spec.rb +94 -0
  73. data/spec/buildpack_support/cache/download_cache_spec.rb +293 -0
  74. data/spec/buildpack_support/cache/internet_availability_spec.rb +57 -0
  75. data/spec/buildpack_support/cache/yield_file_with_content.rb +30 -0
  76. data/spec/buildpack_support/component/application_spec.rb +81 -0
  77. data/spec/buildpack_support/component/base_component_spec.rb +81 -0
  78. data/spec/buildpack_support/component/base_droplet_spec.rb +72 -0
  79. data/spec/buildpack_support/component/downloads_spec.rb +63 -0
  80. data/spec/buildpack_support/component/services_spec.rb +80 -0
  81. data/spec/buildpack_support/component/versioned_dependency_component_spec.rb +58 -0
  82. data/spec/buildpack_support/component/versioned_downloads_spec.rb +58 -0
  83. data/spec/buildpack_support/component/with_timing_spec.rb +30 -0
  84. data/spec/buildpack_support/configuration_utils_spec.rb +39 -0
  85. data/spec/buildpack_support/constantize_spec.rb +34 -0
  86. data/spec/buildpack_support/dash_case_spec.rb +41 -0
  87. data/spec/buildpack_support/directory_finder_spec.rb +41 -0
  88. data/spec/buildpack_support/filtering_pathname_spec.rb +443 -0
  89. data/spec/buildpack_support/format_duration_spec.rb +60 -0
  90. data/spec/buildpack_support/logging/delegating_logger_spec.rb +62 -0
  91. data/spec/buildpack_support/logging/logger_factory_spec.rb +262 -0
  92. data/spec/buildpack_support/qualify_path_spec.rb +42 -0
  93. data/spec/buildpack_support/rake/buildpack_stage_task_spec.rb +88 -0
  94. data/spec/buildpack_support/rake/cached_artifact_finder_spec.rb +73 -0
  95. data/spec/buildpack_support/rake/check_api_doc_task_spec.rb +69 -0
  96. data/spec/buildpack_support/rake/dependency_cache_task_spec.rb +133 -0
  97. data/spec/buildpack_support/rake/disable_remote_downloads_task_spec.rb +91 -0
  98. data/spec/buildpack_support/rake/package_task_spec.rb +335 -0
  99. data/spec/buildpack_support/rake/package_zip_task_spec.rb +91 -0
  100. data/spec/buildpack_support/rake/repository_configuration_finder_spec.rb +61 -0
  101. data/spec/buildpack_support/rake/write_version_file_task_spec.rb +96 -0
  102. data/spec/buildpack_support/repository/configured_item_spec.rb +78 -0
  103. data/spec/buildpack_support/repository/repository_index_spec.rb +118 -0
  104. data/spec/buildpack_support/repository/wildcard_version_resolver_spec.rb +73 -0
  105. data/spec/buildpack_support/shell_spec.rb +32 -0
  106. data/spec/buildpack_support/snake_case_spec.rb +45 -0
  107. data/spec/buildpack_support/space_case_spec.rb +41 -0
  108. data/spec/buildpack_support/to_b_spec.rb +41 -0
  109. data/spec/buildpack_support/tokenized_version_spec.rb +132 -0
  110. data/spec/fixtures/application/test-file +0 -0
  111. data/spec/fixtures/config/found-config.yml +2 -0
  112. data/spec/fixtures/droplet-resources/droplet-resource +0 -0
  113. data/spec/fixtures/stub-download-with-top-level.zip +0 -0
  114. data/spec/fixtures/stub-download.tar.gz +0 -0
  115. data/spec/fixtures/stub-download.zip +0 -0
  116. data/spec/fixtures/test-cache.yml +18 -0
  117. data/spec/fixtures/test-index.yml +2 -0
  118. data/spec/fixtures/test_component.rb +0 -0
  119. data/spec/fixtures/zip-contents/test-directory/test-deep-file +0 -0
  120. data/spec/fixtures/zip-contents/test-file +0 -0
  121. data/spec/spec_helper.rb +30 -0
  122. metadata +416 -0
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Cloud Foundry Buildpack Support
2
+ Copyright 2014 the original author or authors.
data/docs/cache.md ADDED
@@ -0,0 +1,77 @@
1
+ # Caches
2
+ Many buildpack components will want to cache large files that are downloaded for applications. `buildpack-support` provides a cache abstraction to encapsulate this behavior. The cache abstraction is comprised of two cache types, each with the same signature.
3
+
4
+ ```ruby
5
+ # Retrieves an item from the cache. Retrieval of the item uses the following algorithm:
6
+ #
7
+ # 1. Obtain an exclusive lock based on the URI of the item. This allows concurrency for different items, but not for
8
+ # the same item.
9
+ # 2. If the the cached item does not exist, download from +uri+ and cache it, its +Etag+, and its +Last-Modified+
10
+ # values if they exist.
11
+ # 3. If the cached file does exist, and the original download had an +Etag+ or a +Last-Modified+ value, attempt to
12
+ # download from +uri+ again. If the result is +304+ (+Not-Modified+), then proceed without changing the cached
13
+ # item. If it is anything else, overwrite the cached file and its +Etag+ and +Last-Modified+ values if they exist.
14
+ # 4. Downgrade the lock to a shared lock as no further mutation of the cache is possible. This allows concurrency for
15
+ # read access of the item.
16
+ # 5. Yield the cached file (opened read-only) to the passed in block. Once the block is complete, the file is closed
17
+ # and the lock is released.
18
+ #
19
+ # @param [String] uri the uri to download if the item is not already in the cache. Also used in the case where the
20
+ # item is already in the cache, to validate that the item is up to date
21
+ # @yieldparam [File] file the file representing the cached item. In order to ensure that the file is not changed or
22
+ # deleted while it is being used, the cached item can only be accessed as part of a block.
23
+ # @return [Void]
24
+ def get(uri)
25
+
26
+ # Remove an item from the cache
27
+ #
28
+ # @param [String] uri the URI of the item to remove
29
+ # @return [Void]
30
+ def evict(uri)
31
+ ```
32
+
33
+ Use of a cache might look like the following:
34
+
35
+ ```ruby
36
+ require 'buildpack_support/cache/download_cache'
37
+
38
+ BuildpackSupport::Cache::DownloadCache.new.get(uri) do |file|
39
+ YAML.load_file(file)
40
+ end
41
+ ```
42
+
43
+ ## Configuration
44
+ For general information on configuration using `buildpack-support`, refer to the [configuration documentation][c].
45
+
46
+ Caching can be configured by modifying the `config/cache.yml` file in a buildpack.
47
+
48
+ | Name | Description
49
+ | ---- | -----------
50
+ | `remote_downloads` | This property can take the value `enabled` or `disabled`. <p>The default value of `enabled` means that the buildpack will check the internet connection and remember the result for the remainder of the buildpack invocation. If the internet is available, it will then be used to download files. If the internet is not available, cache will be consulted instead. <p>Alternatively, the property may be set to `disabled` which avoids the check for an internet connection, does not attempt downloads, and consults the cache instead.
51
+
52
+ ## `BuildpackSupport::Cache::ApplicationCache`
53
+ The `ApplicationCache` is a cache that persists files into the application cache passed to the `compile` script. It examines `ARGV[1]` for the cache location and configures itself accordingly. The constructor signature looks the following:
54
+
55
+ ```ruby
56
+ # Creates an instance that is configured to use the application cache. The application cache location is defined
57
+ # by the second argument (<tt>ARGV[1]</tt>) to the +compile+ script.
58
+ #
59
+ # @raise if the second argument (<tt>ARGV[1]</tt>) to the +compile+ script is +nil+
60
+ def initialize
61
+ ```
62
+
63
+ ## `BuildpackSupport::Cache::DownloadCache`
64
+ The `DownloadCache` is the more generic of the two caches. It allows you to create a cache that persists files anywhere that write access is available. The constructor signature looks the following:
65
+
66
+ ```ruby
67
+ # Creates an instance of the cache that is backed by a number of filesystem locations. The first argument
68
+ # (+mutable_cache_root+) is the only location that downloaded files will be stored in.
69
+ #
70
+ # @param [Pathname] mutable_cache_root the filesystem location in which find cached files in. This will also be
71
+ # the location that all downloaded files are written to.
72
+ # @param [Pathname] immutable_cache_roots other filesystem locations to find cached files in. No files will be
73
+ # written to these locations.
74
+ def initialize(mutable_cache_root = Pathname.new(Dir.tmpdir), *immutable_cache_roots)
75
+ ```
76
+
77
+ [c]: configuration.md
data/docs/component.md ADDED
@@ -0,0 +1 @@
1
+ TODO: Document component support
@@ -0,0 +1,27 @@
1
+ # Configuration
2
+ Many buildpack components will need to read user configuration in order to operate. `buildpack-support` provides a utility class to encapsulate the reading of this configuration in a uniform way from a centralized location. Configuration is located in the `config` directory of a buildpack, and is read from files matching the `<COMPONENT-ID>.yml` pattern.
3
+
4
+ ```ruby
5
+ # Loads a configuration file from the buildpack configuration directory. If the configuration file does not exist,
6
+ # returns an empty hash.
7
+ #
8
+ # @param [String] identifier the identifier of the configuration
9
+ # @return [Hash] the configuration or an empty hash if the configuration file does not exist
10
+ def load(identifier)
11
+ ```
12
+
13
+ Use of the configuration utility might look like the following:
14
+
15
+ ```ruby
16
+ require 'buildpack_support/configuration_utils'
17
+
18
+ BuildpackSupport::ConfigurationUtils.new.load('cache')['remote_downloads']
19
+ ```
20
+
21
+ ## Configuring an existing buildpack
22
+ Buildpack configuration is supported through the use of Git repository forking. The easiest way to accomplish this is to use [GitHub's forking functionality][f] to create a copy of this repository. Make the required configuration changes in this copy of the repository and then specify the URL of the new repository when pushing applications to Cloud Foundry. If the modifications are generally applicable to the Cloud Foundry community, please submit a [pull request][p] with the changes.
23
+
24
+ To lean how to configuration various properties of the buildpack, check the "Configuration" documentation for each component.
25
+
26
+ [f]: https://help.github.com/articles/fork-a-repo
27
+ [p]: https://help.github.com/articles/using-pull-requests
data/docs/logging.md ADDED
@@ -0,0 +1,54 @@
1
+ # Logging
2
+ Many buildpack components will want to log output for the users to see. `buildpack-support` provides support for this functionality by reusing the [Ruby `Logger` API][l] and adding with a new API for initialzing the logger.
3
+
4
+ ```ruby
5
+ # Sets up the logger factory
6
+ #
7
+ # @param [Pathname] app_dir the application directory
8
+ # @return [Void]
9
+ def setup(app_dir)
10
+
11
+ # Returns a configured logger for a given +Class+. The +Class+ that is passed in is used as the +progname+, for all
12
+ # messages logged by the logger. If this is called before the +setup()+ method, a failure will be generated.
13
+ #
14
+ # @param [Class] klass the class that the logger is created for
15
+ # @return [Logger] the logger that was requested
16
+ def get_logger(klass)
17
+
18
+ # Returns the location of the log file. If this is called before the +setup()+ method, a failure will be generated.
19
+ #
20
+ # @return [Pathname] the location of the log file
21
+ def log_file
22
+
23
+ # Resets the configuration of the factory
24
+ #
25
+ # @return [Void]
26
+ def reset
27
+ ```
28
+ Use of a cache might look like the following:
29
+
30
+ ```ruby
31
+ require 'buildpack_support/logging/logger_factory'
32
+
33
+ @logger = BuildpackSupport::Logging::LoggerFactory.instance.get_logger BuildpackVersion
34
+
35
+ @logger.info 'simple message'
36
+ @logger.debug { generate_costly_message }
37
+ ```
38
+
39
+ `buildpack-support` logs all messages, regardless of severity to `<APP-DIR>/.buildpack.log`. It also logs messages to `$stderr`, filtered by a configured severity.
40
+
41
+ The `BuildpackSupport::Logging::LoggerFactory` class manages instances that meet the contract of the standard Ruby `Logger`. In normal usage, the `BuildpackSupport::BaseBuildpack` class configures the `LoggerFactory`. `Logger` instances are then retrieved for classes that require them.
42
+
43
+ ## Configuration
44
+ For general information on configuration using `buildpack-support`, refer to the [configuration documentation][c].
45
+
46
+ The console logging severity filter is set to `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL` using the following strategies in descending priority:
47
+
48
+ 1. `$BP_LOG_LEVEL` environment variable. This can be set using the `cf set-env <app name> BP_LOG_LEVEL DEBUG` command.
49
+ 2. Ruby `--verbose` and `--debug` flags. Setting either of these is the equivalent of setting the log severity level to `DEBUG`.
50
+ 3. `default_log_level` value in `config/logging.yml` in a buildpack
51
+ 4. Fallback to `INFO` if none of the above are set
52
+
53
+ [c]: configuration.md
54
+ [l]: http://www.rubydoc.info/stdlib/logger/Logger
data/docs/other.md ADDED
@@ -0,0 +1 @@
1
+ TODO: Document other utilities
data/docs/rake.md ADDED
@@ -0,0 +1 @@
1
+ TODO: Document Rake tasks
@@ -0,0 +1,116 @@
1
+ # Repositories
2
+ Many buildpack components will want to provide multiple versions of binaries. `buildpack-support` provides a repository abstraction to encapsulate version resolution and download URI creation.
3
+
4
+ ```ruby
5
+ # Finds an instance of the file based on the configuration and wraps any exceptions
6
+ # to identify the component.
7
+ #
8
+ # @param [String] component_name the name of the component
9
+ # @param [Hash] configuration the configuration
10
+ # @option configuration [String] :repository_root the root directory of the repository
11
+ # @option configuration [String] :version the version of the file to resolve
12
+ # @yield the version to a block for validation. An error should be raised if the version is not valid
13
+ # @yieldparam version [BuildpackSupport::TokenizedVersion] the version to validate
14
+ # @return [String] the URI of the chosen version of the file
15
+ # @return [TokenizedVersion] the chosen version of the file
16
+ def find_item(component_name, configuration)
17
+ ```
18
+
19
+ Use of a repository might look like the following:
20
+
21
+ ```ruby
22
+ require 'buildpack_support/repository/configured_item'
23
+
24
+ configured_item = BuildpackSupport::Repository::ConfiguredItem.new
25
+ version, uri = configured_item.find_item component_name, configuration
26
+ ```
27
+
28
+ or with version validation:
29
+
30
+ ```ruby
31
+ require 'buildpack_support/repository/configured_item'
32
+
33
+ configured_item = BuildpackSupport::Repository::ConfiguredItem.new
34
+ version, uri = configured_item.find_item component_name, configuration { |version| validate_version version }
35
+ ```
36
+
37
+ ## Repository Structure
38
+ The repository is an HTTP-accessible collection of files. The repository root must contain an `index.yml` file ([example][i]) that is a mapping of concrete versions to absolute URIs consisting of a series of lines of the form:
39
+
40
+ ```yaml
41
+ <version>: <URI>
42
+ ```
43
+
44
+ The collection of files may be stored alongside the index file or elsewhere.
45
+
46
+ An example filesystem might look like:
47
+
48
+ ```
49
+ /index.yml
50
+ /openjdk-1.6.0_27.tar.gz
51
+ /openjdk-1.7.0_21.tar.gz
52
+ /openjdk-1.8.0_M7.tar.gz
53
+ ```
54
+
55
+ ## Wildcards
56
+ `repository_root` declarations in component configuration files can have variables in them. These variables are replaced by the repository infrastructure and the resulting URI is used when retrieving the repository index.
57
+
58
+ | Variable | Description |
59
+ | -------- | ----------- |
60
+ | `{default.repository.root}` | The common root for all repositories. Currently defaults to `http://download.run.pivotal.io`.
61
+ | `{platform}` | The platform that the application is running on. Currently detects `centos6`, `lucid`, `mountainlion`, `precise`, and `trusty`.
62
+ | `{architecture}` | The architecture of the system as returned by Ruby. The value is typically one of `x86_64` or `x86`.
63
+
64
+ ## Version Syntax and Ordering
65
+ Versions are composed of major, minor, micro, and optional qualifier parts (`<major>.<minor>.<micro>[_<qualifier>]`). The major, minor, and micro parts must be numeric. The qualifier part is composed of letters, digits, and hyphens. The lexical ordering of the qualifier is:
66
+
67
+ 1. hyphen
68
+ 2. lowercase letters
69
+ 3. uppercase letters
70
+ 4. digits
71
+
72
+ ## Configuration
73
+ For general information on configuration using `buildpack-support`, refer to the [configuration documentation][c].
74
+
75
+ Repositories can be configured by modifying the `config/repository.yml` file in a buildpack.
76
+
77
+ | Name | Description
78
+ | ---- | -----------
79
+ | `default_repository_root` | This property can take a URI that is used as a common root for all of the repositories used by the buildpack. The value is substituted for the `{default.repository.root}` variable in `repository_root` declarations.
80
+
81
+ ## `BuildpackSupport::Repository::ConfiguredItem`
82
+ The `ConfiguredItem` class is responsible for downloading (and caching) a repository index and using provided configuration to resolve the version and download URI of a dependency. The constructor signature looks the following:
83
+
84
+ ```ruby
85
+ # Creates a new instance
86
+ #
87
+ # @param [VersionResolver] version_resolver the version resolver to use when finding items
88
+ def initialize(version_resolver = WildcardVersionResolver.new)
89
+ ```
90
+
91
+ ## Version Resolvers
92
+ `VersionResolvers` are an abstraction that allows different version resolution strategies to be plugged into the `ConfiguredItem`. The API for a `VersionResolver` looks like the following
93
+
94
+ ```ruby
95
+ # Resolves a version from a collection of versions. The +candidate_version+ must be structured as up to three numeric
96
+ # components, followed by an optional string component. The resolution returns the maximum of the versions that match
97
+ # the candidate version
98
+ #
99
+ # @param [TokenizedVersion] candidate_version the version to resolve
100
+ # @param [Array<String>] versions the collection of versions to resolve against
101
+ # @return [TokenizedVersion] the resolved version
102
+ # @raise if no version can be resolved
103
+ def resolve(candidate_version, versions)
104
+ ```
105
+
106
+ ## `BuildpackSupport::Repository::WildcardVersionResolver`
107
+ The default `VersionResolver` that allows you to specify a bounded range of versions to use, in addition to a specific version. Appending the `+` symbol to a version prefix chooses the latest version that begins with the prefix.
108
+
109
+ | Example | Description
110
+ | ------- | -----------
111
+ | `1.+` | Selects the greatest available version less than `2.0.0`.
112
+ | `1.7.+` | Selects the greatest available version less than `1.8.0`.
113
+ | `1.7.0_+` | Selects the greatest available version less than `1.7.1`. Use this syntax to stay up to date with the latest security releases in a particular version.
114
+
115
+ [c]: configuration.md
116
+ [i]: http://download.pivotal.io.s3.amazonaws.com/openjdk/lucid/x86_64/index.yml