Skip to content

Commit e977bbf

Browse files
committed
Allow to extend the supported products of mixlib-install
Signed-off-by: Tensibai <tensibai@iabis.net>
1 parent 46ae1a3 commit e977bbf

File tree

10 files changed

+21893
-8
lines changed

10 files changed

+21893
-8
lines changed

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,25 @@ Bourne install script (`install.sh`) supports `http_proxy`, `https_proxy`, `ftp_
254254

255255
Powershell install script (`install.ps1`) supports `http_proxy` passed as a key to `install_command_options`.
256256

257+
258+
### Extending for other products
259+
260+
Create a ruby file in your application and use the product DSL like this (see [product.rb](lib/mixlib/install/product.rb) for available properties):
261+
262+
```
263+
product "cinc" do
264+
product_name "Cinc Infra Client"
265+
package_name "cinc-client"
266+
api_url "https://packages.cinc.sh"
267+
end
268+
```
269+
270+
Then set an environment variable to load them like this on linux:
271+
272+
`export EXTRA_PRODUCTS_FILE=/path/to/your/file.rb`
273+
274+
Calls to mixlib-install now allow to target your new product, assuming the api_url match pacakges api for `/<channel>/<product>/versions` and `/<channel>/<product>/<version>/artifacts` endpoints.
275+
257276
## Development
258277
VCR is a tool that helps cache and replay http responses. When these responses change or when you add more tests you might need to update cached responses. Check out [spec_helper.rb](https://github.com/chef/mixlib-install/blob/master/spec/spec_helper.rb) for instructions on how to do this.
259278

lib/mixlib/install/backend/package_router.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module Mixlib
3030
class Install
3131
class Backend
3232
class PackageRouter < Base
33-
ENDPOINT = Mixlib::Install::Dist::PRODUCT_ENDPOINT.freeze
3433

3534
COMPAT_DOWNLOAD_URL_ENDPOINT = "http://packages.chef.io".freeze
3635

@@ -269,7 +268,7 @@ def generate_chef_standard_path(channel, project, version, platform, platform_ve
269268
end
270269

271270
def endpoint
272-
@endpoint ||= ENV.fetch("PACKAGE_ROUTER_ENDPOINT", ENDPOINT)
271+
@endpoint ||= PRODUCT_MATRIX.lookup(options.product_name, options.product_version).api_url
273272
end
274273

275274
def omnibus_project

lib/mixlib/install/options.rb

+12-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Install
2626
class Options
2727
class InvalidOptions < ArgumentError; end
2828

29-
attr_reader :options, :errors, :original_platform_version
29+
attr_reader :options, :errors, :original_platform_version, :supported_product_names
3030

3131
SUPPORTED_ARCHITECTURES = %w{
3232
aarch64
@@ -46,8 +46,6 @@ class InvalidOptions < ArgumentError; end
4646
:unstable,
4747
]
4848

49-
SUPPORTED_PRODUCT_NAMES = PRODUCT_MATRIX.products
50-
5149
SUPPORTED_SHELL_TYPES = [
5250
:ps1,
5351
:sh,
@@ -77,6 +75,15 @@ def initialize(options)
7775
# Store original options in cases where we must remap
7876
@original_platform_version = options[:platform_version]
7977

78+
# Eval extra products definition
79+
extra_products = ENV.fetch("EXTRA_PRODUCTS_FILE", nil)
80+
unless extra_products.nil?
81+
PRODUCT_MATRIX.instance_eval(::File.read(extra_products), extra_products)
82+
end
83+
84+
# Store supported product names
85+
@supported_product_names = PRODUCT_MATRIX.products
86+
8087
resolve_platform_version_compatibility_mode!
8188

8289
map_windows_versions!
@@ -189,10 +196,10 @@ def validate_architecture
189196
end
190197

191198
def validate_product_names
192-
unless SUPPORTED_PRODUCT_NAMES.include? product_name
199+
unless @supported_product_names.include? product_name
193200
errors << <<-EOS
194201
Unknown product name #{product_name}.
195-
Must be one of: #{SUPPORTED_PRODUCT_NAMES.join(", ")}
202+
Must be one of: #{@supported_product_names.join(", ")}
196203
EOS
197204
end
198205
end

lib/mixlib/install/product.rb

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def initialize(key, &block)
3636
:omnibus_project,
3737
:github_repo,
3838
:downloads_product_page_url,
39+
:api_url,
3940
]
4041

4142
#
@@ -86,6 +87,8 @@ def default_value_for(prop)
8687
"#{Mixlib::Install::Dist::DOWNLOADS_PAGE}/#{product_key}"
8788
when :github_repo
8889
"#{Mixlib::Install::Dist::GITHUB_ORG}/#{product_key}"
90+
when :api_url
91+
ENV.fetch("PACKAGE_ROUTER_ENDPOINT", Mixlib::Install::Dist::PRODUCT_ENDPOINT)
8992
else
9093
nil
9194
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
product "cinc" do
2+
product_name "Cinc Infra Client"
3+
package_name "cinc-client"
4+
api_url "https://packages.cinc.sh"
5+
end

0 commit comments

Comments
 (0)