omnibus 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +26 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +6 -0
- data/.travis.yml +7 -1
- data/CHANGELOG.md +24 -0
- data/MAINTAINERS.md +5 -5
- data/README.md +2 -2
- data/appveyor.yml +2 -0
- data/features/commands/build.feature +40 -6
- data/features/commands/clean.feature +2 -2
- data/features/commands/manifest.feature +131 -0
- data/features/step_definitions/generator_steps.rb +23 -7
- data/lib/omnibus.rb +3 -0
- data/lib/omnibus/cli.rb +20 -0
- data/lib/omnibus/download_helpers.rb +137 -0
- data/lib/omnibus/fetchers/git_fetcher.rb +8 -1
- data/lib/omnibus/fetchers/net_fetcher.rb +8 -81
- data/lib/omnibus/health_check.rb +54 -1
- data/lib/omnibus/licensing.rb +172 -4
- data/lib/omnibus/packager.rb +1 -0
- data/lib/omnibus/packagers/bff.rb +8 -2
- data/lib/omnibus/packagers/deb.rb +2 -24
- data/lib/omnibus/packagers/rpm.rb +1 -1
- data/lib/omnibus/project.rb +7 -0
- data/lib/omnibus/software.rb +72 -21
- data/lib/omnibus/version.rb +1 -1
- data/omnibus.gemspec +2 -1
- data/spec/functional/licensing_spec.rb +109 -13
- data/spec/unit/health_check_spec.rb +4 -2
- data/spec/unit/packagers/deb_spec.rb +26 -85
- data/spec/unit/packagers/rpm_spec.rb +12 -2
- data/spec/unit/software_spec.rb +154 -15
- metadata +24 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a17a0e151fcd48e38827a9504daafcbdeb58abe5
|
4
|
+
data.tar.gz: 599d4ab2fb191028721c42fb912d836a05ef6e69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 829c377378e984fabdbc83f3e23e7f092a25c8dda2823391fa7c4198a873529c8f8750367abeca0b908ad9c3b6073633a4308aa90814cb0e114fe6a2d6a0b39f
|
7
|
+
data.tar.gz: 6262ddf08f75fc3d49735e2f223a63c0eced1bf6050ab912f9a79113589c4dfd69ccc30abcc97f4c5caca60609435dabd861d09f0a6b88dd4ae61b586de77c32
|
@@ -0,0 +1,26 @@
|
|
1
|
+
### Description
|
2
|
+
|
3
|
+
Briefly describe the issue
|
4
|
+
|
5
|
+
### Omnibus Version
|
6
|
+
|
7
|
+
Tell us which version of Omnibus you are using
|
8
|
+
|
9
|
+
### Platform Version
|
10
|
+
|
11
|
+
Tell us which Operating System distribution, version and architecture the Omnibus build is being executed on.
|
12
|
+
|
13
|
+
### Replication Case
|
14
|
+
|
15
|
+
Tell us what steps to take to replicate your problem. See [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)
|
16
|
+
for information on how to create a good replication case.
|
17
|
+
|
18
|
+
### Build Output
|
19
|
+
|
20
|
+
The relevant output of the Omnibus build or a link to a gist of the entire build, if there is one.
|
21
|
+
|
22
|
+
The verbose build output (`omnibus build <PROJECT> -l internal`) may be useful, but please link to a gist, or truncate it.
|
23
|
+
|
24
|
+
--------------------------------------------------
|
25
|
+
/cc @chef/omnibus-maintainers <- This ensures the Omnibus Maintainers team are notified to review this PR.
|
26
|
+
|
data/.travis.yml
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
sudo: false
|
1
2
|
rvm:
|
2
3
|
- 2.0.0
|
3
4
|
- 2.1
|
@@ -8,7 +9,12 @@ branches:
|
|
8
9
|
- 2.0-stable
|
9
10
|
- 3.0-stable
|
10
11
|
- master
|
11
|
-
before_install:
|
12
|
+
before_install:
|
13
|
+
- gem update --system
|
14
|
+
- gem install bundler
|
15
|
+
before_script:
|
16
|
+
- git config --global user.email "clouseau@chef.io"
|
17
|
+
- git config --global user.name "Pink Panther"
|
12
18
|
script: bundle exec rake travis:ci
|
13
19
|
notifications:
|
14
20
|
slack:
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
Omnibus CHANGELOG
|
2
2
|
=================
|
3
3
|
|
4
|
+
v5.3.0 (March 25, 2016)
|
5
|
+
-----------------------
|
6
|
+
### New Features
|
7
|
+
|
8
|
+
- Get correct architecture name for Debian environments from `dpkg` (#646)
|
9
|
+
- Update fauxhai to latest (#652)
|
10
|
+
- Use project.license in deb and rpm packagers if available (#653)
|
11
|
+
- Whitelist additional Solaris11 libraries (#650)
|
12
|
+
- Use gcc 4.9 on freebsd (#649)
|
13
|
+
- Per-Platform manifest generation (#645)
|
14
|
+
- Support omnibus manifest arguments: `omnibus manifest --os=OS --platform-family=FAMILY --platform=PLATFORM --platform-version=VERSION`
|
15
|
+
- Can be used to generate manifests for other platforms than the one you are on, allowing a multi-platform build to be quickly set up.
|
16
|
+
- Affects chef-sugar's `windows?`, `solaris?` and similar functions, which are used by software in `omnibus-software`
|
17
|
+
- Performance: Ignore non-libraries in health checks (#642)
|
18
|
+
- Add `github` source (#643)
|
19
|
+
- Add `suse` support (#647)
|
20
|
+
- Exclude files with whitespace names from AIX packages (#641)
|
21
|
+
- Fix compilation problems on Windows (#640)
|
22
|
+
- Disable `sse` to avoid compilation segfaults
|
23
|
+
- Don't change newlines when `git pull`ing
|
24
|
+
- Warn when software licenses are missing for software components (#638)
|
25
|
+
- Add Chef MLSA to the list of recognized licenses (#639)
|
26
|
+
- Download remote license files into the LICENSES directory (#637)
|
27
|
+
|
4
28
|
v5.2.0 (March 15, 2016)
|
5
29
|
-----------------------
|
6
30
|
### New Features
|
data/MAINTAINERS.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Maintainers
|
2
2
|
|
3
|
-
This file lists how the
|
4
|
-
|
5
|
-
|
3
|
+
This file lists how the `omnibus` project is maintained.
|
4
|
+
|
5
|
+
When making changes to the system, you need two maintainers to provide a :+1: on
|
6
6
|
your pull request. Additionally, you need to not receive a veto from a
|
7
7
|
Lieutenant or the Project Lead.
|
8
8
|
|
@@ -19,10 +19,10 @@ project lead.
|
|
19
19
|
|
20
20
|
* [Daniel DeLeo](https://github.com/danielsdeleo)
|
21
21
|
* [Jay Mundrawala](https://github.com/jaym)
|
22
|
+
* [Kartik Null Cating-Subramanian](https://github.com/ksubrama)
|
22
23
|
* [Lamont Granquist](https://github.com/lamont-granquist)
|
23
24
|
* [Scott Hain](https://github.com/scotthain)
|
24
25
|
* [Seth Vargo](http://github.com/sethvargo)
|
25
26
|
* [Steven Danna](https://github.com/stevendanna)
|
26
|
-
* [Yvonne Lam](http://github.com/yzl)
|
27
27
|
* [Thom May](https://github.com/thommay)
|
28
|
-
* [
|
28
|
+
* [Yvonne Lam](http://github.com/yzl)
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[][travis]
|
5
5
|
|
6
6
|
[gem]: https://rubygems.org/gems/omnibus
|
7
|
-
[travis]:
|
7
|
+
[travis]: https://travis-ci.org/chef/omnibus
|
8
8
|
|
9
9
|
Easily create full-stack installers for your project across a variety of platforms.
|
10
10
|
|
@@ -341,7 +341,7 @@ use_git_caching false
|
|
341
341
|
License
|
342
342
|
-------
|
343
343
|
```text
|
344
|
-
Copyright 2012-
|
344
|
+
Copyright 2012-2016 Chef Software, Inc.
|
345
345
|
|
346
346
|
Licensed under the Apache License, Version 2.0 (the "License");
|
347
347
|
you may not use this file except in compliance with the License.
|
data/appveyor.yml
CHANGED
@@ -25,6 +25,8 @@ install:
|
|
25
25
|
- cp C:\Ruby21%ruby_version:~3%\Devkit\mingw\bin\bsdtar.exe C:\Ruby21%ruby_version:~3%\Devkit\mingw\bin\tar.exe
|
26
26
|
- appveyor DownloadFile http://curl.haxx.se/ca/cacert.pem -FileName C:\cacert.pem
|
27
27
|
- set SSL_CERT_FILE=C:\cacert.pem
|
28
|
+
- git config --global user.email "clouseau@chef.io"
|
29
|
+
- git config --global user.name "Pink Panther"
|
28
30
|
|
29
31
|
build_script:
|
30
32
|
- bundle install
|
@@ -1,8 +1,42 @@
|
|
1
1
|
Feature: omnibus build
|
2
|
+
Background:
|
3
|
+
Given I have an omnibus project named "hamlet"
|
4
|
+
|
2
5
|
Scenario: When the project does not exist
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
When I run `omnibus build bacon`
|
7
|
+
|
8
|
+
Then the output should contain:
|
9
|
+
"""
|
10
|
+
I could not find a project named `bacon' in any of the project locations:
|
11
|
+
"""
|
12
|
+
And the exit status should not be 0
|
13
|
+
|
14
|
+
# These scenarios don't work on appveyor due to no heat.exe/candle.exe/light.exe
|
15
|
+
# Scenario: When the project has no software definitions
|
16
|
+
# When I run `omnibus build hamlet`
|
17
|
+
#
|
18
|
+
# Then it should pass with "[Project: hamlet] I | Building version manifest"
|
19
|
+
# And the file "output/version-manifest.json" should exist
|
20
|
+
# And the file "output/version-manifest.txt" should exist
|
21
|
+
# And the file "output/LICENSE" should exist
|
22
|
+
# And the directory "output/LICENSES" should exist
|
23
|
+
#
|
24
|
+
# Scenario: When the project has a software definition
|
25
|
+
# Given a file "config/software/ophelia.rb" with:
|
26
|
+
# """
|
27
|
+
# name "ophelia"
|
28
|
+
# default_version "1.0.0"
|
29
|
+
# build do
|
30
|
+
# command "echo true > #{install_dir}/blah.txt"
|
31
|
+
# end
|
32
|
+
# """
|
33
|
+
# And I append to "config/projects/hamlet.rb" with "dependency 'ophelia'"
|
34
|
+
#
|
35
|
+
# When I run `omnibus build hamlet`
|
36
|
+
#
|
37
|
+
# Then it should pass with "[Builder: ophelia] I | $ echo true"
|
38
|
+
# And the file "output/blah.txt" should contain "true"
|
39
|
+
# And the file "output/version-manifest.json" should exist
|
40
|
+
# And the file "output/version-manifest.txt" should exist
|
41
|
+
# And the file "output/LICENSE" should exist
|
42
|
+
# And the directory "output/LICENSES" should exist
|
@@ -10,12 +10,12 @@ Feature: omnibus clean
|
|
10
10
|
Scenario: When the --purge option is given
|
11
11
|
* I have an omnibus project named "hamlet"
|
12
12
|
* I successfully run `omnibus clean hamlet --purge`
|
13
|
-
* the output should contain "remove
|
13
|
+
* the output should contain "remove output"
|
14
14
|
|
15
15
|
Scenario: When no options are given
|
16
16
|
* I have an omnibus project named "hamlet"
|
17
17
|
* I successfully run `omnibus clean hamlet`
|
18
18
|
* the output should not contain:
|
19
19
|
"""
|
20
|
-
remove
|
20
|
+
remove output
|
21
21
|
"""
|
@@ -0,0 +1,131 @@
|
|
1
|
+
Feature: omnibus manifest
|
2
|
+
Background:
|
3
|
+
Given I have an omnibus project named "hamlet"
|
4
|
+
|
5
|
+
Scenario: When the project does not exist
|
6
|
+
When I run `omnibus manifest bacon`
|
7
|
+
|
8
|
+
Then the output should contain:
|
9
|
+
"""
|
10
|
+
I could not find a project named `bacon' in any of the project locations:
|
11
|
+
"""
|
12
|
+
And the exit status should not be 0
|
13
|
+
|
14
|
+
Scenario: When the project has no software definitions
|
15
|
+
When I run `omnibus manifest hamlet`
|
16
|
+
|
17
|
+
Then it should pass with "[Project: hamlet] I | Building version manifest"
|
18
|
+
And the output should contain:
|
19
|
+
"""
|
20
|
+
"software": {
|
21
|
+
},
|
22
|
+
"""
|
23
|
+
|
24
|
+
Scenario: When the project has a software definition
|
25
|
+
Given a file "config/software/ophelia.rb" with:
|
26
|
+
"""
|
27
|
+
name "ophelia"
|
28
|
+
default_version "1.0.0"
|
29
|
+
build do
|
30
|
+
command "echo true > #{install_dir}/blah.txt"
|
31
|
+
end
|
32
|
+
"""
|
33
|
+
And I append to "config/projects/hamlet.rb" with "dependency 'ophelia'"
|
34
|
+
|
35
|
+
When I run `omnibus manifest hamlet`
|
36
|
+
|
37
|
+
Then it should pass with "[Project: hamlet] I | Building version manifest"
|
38
|
+
And the output should contain:
|
39
|
+
"""
|
40
|
+
"software": {
|
41
|
+
"ophelia": {
|
42
|
+
"locked_version": "1.0.0",
|
43
|
+
"locked_source": null,
|
44
|
+
"source_type": "project_local",
|
45
|
+
"described_version": "1.0.0",
|
46
|
+
"license": "Unspecified"
|
47
|
+
}
|
48
|
+
},
|
49
|
+
"""
|
50
|
+
|
51
|
+
Scenario: When the project has a software definition
|
52
|
+
Given a file "config/software/ophelia.rb" with:
|
53
|
+
"""
|
54
|
+
name "ophelia"
|
55
|
+
default_version "1.0.0"
|
56
|
+
build do
|
57
|
+
command "echo true > #{install_dir}/blah.txt"
|
58
|
+
end
|
59
|
+
"""
|
60
|
+
And I append to "config/projects/hamlet.rb" with "dependency 'ophelia'"
|
61
|
+
|
62
|
+
When I run `omnibus manifest hamlet`
|
63
|
+
|
64
|
+
Then it should pass with "[Project: hamlet] I | Building version manifest"
|
65
|
+
And the output should contain:
|
66
|
+
"""
|
67
|
+
"software": {
|
68
|
+
"ophelia": {
|
69
|
+
"locked_version": "1.0.0",
|
70
|
+
"locked_source": null,
|
71
|
+
"source_type": "project_local",
|
72
|
+
"described_version": "1.0.0",
|
73
|
+
"license": "Unspecified"
|
74
|
+
}
|
75
|
+
},
|
76
|
+
"""
|
77
|
+
And the exit status should be 0
|
78
|
+
|
79
|
+
Scenario: When the project has a software definition whose version depends on the OS
|
80
|
+
Given a file "config/software/ophelia.rb" with:
|
81
|
+
"""
|
82
|
+
name "ophelia"
|
83
|
+
default_version (windows? ? "2.0.0" : "1.0.0")
|
84
|
+
build do
|
85
|
+
command "echo true > #{install_dir}/blah.txt"
|
86
|
+
end
|
87
|
+
"""
|
88
|
+
And I append to "config/projects/hamlet.rb" with "dependency 'ophelia'"
|
89
|
+
|
90
|
+
When I run `omnibus manifest hamlet --os=linux --platform_family=debian --platform=ubuntu --platform_version=14.04`
|
91
|
+
|
92
|
+
Then it should pass with "[Project: hamlet] I | Building version manifest"
|
93
|
+
And the output should contain:
|
94
|
+
"""
|
95
|
+
"software": {
|
96
|
+
"ophelia": {
|
97
|
+
"locked_version": "1.0.0",
|
98
|
+
"locked_source": null,
|
99
|
+
"source_type": "project_local",
|
100
|
+
"described_version": "1.0.0",
|
101
|
+
"license": "Unspecified"
|
102
|
+
}
|
103
|
+
},
|
104
|
+
"""
|
105
|
+
|
106
|
+
Scenario: When the project has a software definition whose version depends on the OS
|
107
|
+
Given a file "config/software/ophelia.rb" with:
|
108
|
+
"""
|
109
|
+
name "ophelia"
|
110
|
+
default_version (windows? ? "2.0.0" : "1.0.0")
|
111
|
+
build do
|
112
|
+
command "echo true > #{install_dir}/blah.txt"
|
113
|
+
end
|
114
|
+
"""
|
115
|
+
And I append to "config/projects/hamlet.rb" with "dependency 'ophelia'"
|
116
|
+
|
117
|
+
When I run `omnibus manifest hamlet --os=windows --platform_family=windows --platform=windows --platform_version=2012r2`
|
118
|
+
|
119
|
+
Then it should pass with "[Project: hamlet] I | Building version manifest"
|
120
|
+
And the output should contain:
|
121
|
+
"""
|
122
|
+
"software": {
|
123
|
+
"ophelia": {
|
124
|
+
"locked_version": "2.0.0",
|
125
|
+
"locked_source": null,
|
126
|
+
"source_type": "project_local",
|
127
|
+
"described_version": "2.0.0",
|
128
|
+
"license": "Unspecified"
|
129
|
+
}
|
130
|
+
},
|
131
|
+
"""
|
@@ -4,30 +4,46 @@ Given(/^I have an omnibus project named "(.+)"$/) do |name|
|
|
4
4
|
create_directory(name)
|
5
5
|
cd(name)
|
6
6
|
|
7
|
+
# Build target dir must be created
|
8
|
+
abs_path = expand_path(".")
|
9
|
+
|
10
|
+
# Single top level output dir
|
11
|
+
create_directory("output")
|
12
|
+
|
7
13
|
write_file("config/projects/#{name}.rb", <<-EOH.gsub(/^ {4}/, ''))
|
8
14
|
name '#{name}'
|
9
15
|
maintainer 'Mrs. Maintainer'
|
10
16
|
homepage 'https://example.com'
|
11
|
-
install_dir
|
17
|
+
install_dir "#{abs_path}/output"
|
12
18
|
|
13
19
|
build_version '1.0.0'
|
14
20
|
|
15
21
|
exclude '\.git*'
|
16
22
|
exclude 'bundler\/git'
|
23
|
+
|
24
|
+
# This is necessary for Windows to pass.
|
25
|
+
package :msi do
|
26
|
+
upgrade_code "102FDF98-B9BF-4CE1-A716-2AB9CBCDA403"
|
27
|
+
end
|
17
28
|
EOH
|
18
29
|
|
19
30
|
write_file('omnibus.rb', <<-EOH.gsub(/^ {4}/, ''))
|
20
31
|
# Build configuration
|
21
32
|
append_timestamp false
|
22
|
-
cache_dir '
|
23
|
-
git_cache_dir '
|
24
|
-
source_dir '
|
25
|
-
build_dir '
|
26
|
-
package_dir '
|
27
|
-
package_tmp '
|
33
|
+
cache_dir '#{abs_path}/local/omnibus/cache'
|
34
|
+
git_cache_dir '#{abs_path}/local/omnibus/cache/git_cache'
|
35
|
+
source_dir '#{abs_path}/local/omnibus/src'
|
36
|
+
build_dir '#{abs_path}/local/omnibus/build'
|
37
|
+
package_dir '#{abs_path}/local/omnibus/pkg'
|
38
|
+
package_tmp '#{abs_path}/local/omnibus/pkg-tmp'
|
28
39
|
EOH
|
29
40
|
end
|
30
41
|
|
42
|
+
Given(/^I debug$/) do
|
43
|
+
require 'pry'
|
44
|
+
binding.pry
|
45
|
+
end
|
46
|
+
|
31
47
|
Given(/^I have a platform mappings file named "(.+)"$/) do |name|
|
32
48
|
write_file(name, <<-EOH.gsub(/^ {4}/, ''))
|
33
49
|
{
|
data/lib/omnibus.rb
CHANGED
data/lib/omnibus/cli.rb
CHANGED
@@ -99,8 +99,28 @@ module Omnibus
|
|
99
99
|
#
|
100
100
|
# $ omnibus manifest PROJECT
|
101
101
|
#
|
102
|
+
method_option :os,
|
103
|
+
desc: "An os name in Ohai form. Defaults to the current os.",
|
104
|
+
type: :string
|
105
|
+
method_option :platform_family,
|
106
|
+
desc: "A platform family string in Ohai form. Defaults to the current platform_family.",
|
107
|
+
type: :string
|
108
|
+
method_option :platform,
|
109
|
+
desc: "A platform string in Ohai form. Defaults to the current platform.",
|
110
|
+
type: :string
|
111
|
+
method_option :platform_version,
|
112
|
+
desc: "A platform version string in Ohai form. Defaults to the current platform.",
|
113
|
+
type: :string
|
114
|
+
method_option :architecture,
|
115
|
+
desc: "The target architecture: x86, x64, powerpc. Defaults to the current architecture."
|
102
116
|
desc 'manifest PROJECT', 'Print a manifest for the given Omnibus project'
|
103
117
|
def manifest(name)
|
118
|
+
# Override ohai information
|
119
|
+
Ohai['os'] = @options[:os] if @options[:os]
|
120
|
+
Ohai['platform_family'] = @options[:platform_family] if @options[:platform_family]
|
121
|
+
Ohai['platform'] = @options[:platform] if @options[:platform]
|
122
|
+
Ohai['platform_version'] = @options[:platform_version] if @options[:platform_version]
|
123
|
+
Ohai['kernel']['machine'] = @options[:architecture] if @options[:architecture]
|
104
124
|
puts JSON.pretty_generate(Project.load(name).built_manifest.to_hash)
|
105
125
|
end
|
106
126
|
|
@@ -0,0 +1,137 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2015 Chef Software, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'open-uri'
|
18
|
+
require 'ruby-progressbar'
|
19
|
+
|
20
|
+
module Omnibus
|
21
|
+
module DownloadHelpers
|
22
|
+
def self.included(base)
|
23
|
+
base.send(:include, InstanceMethods)
|
24
|
+
end
|
25
|
+
|
26
|
+
module InstanceMethods
|
27
|
+
private
|
28
|
+
#
|
29
|
+
# Downloads a from a given url to a given path using Ruby's
|
30
|
+
# +OpenURI+ implementation.
|
31
|
+
#
|
32
|
+
# @param [String] from_url
|
33
|
+
# @param [String] to_path
|
34
|
+
# @param [Hash] options
|
35
|
+
# +options+ compatible with Ruby's +OpenURI+ implementation.
|
36
|
+
# You can also use special option +enable_progress_bar+ which will
|
37
|
+
# display a progress bar during download.
|
38
|
+
#
|
39
|
+
# @raise [SocketError]
|
40
|
+
# @raise [Errno::ECONNREFUSED]
|
41
|
+
# @raise [Errno::ECONNRESET]
|
42
|
+
# @raise [Errno::ENETUNREACH]
|
43
|
+
# @raise [Timeout::Error]
|
44
|
+
# @raise [OpenURI::HTTPError]
|
45
|
+
#
|
46
|
+
# @return [void]
|
47
|
+
#
|
48
|
+
def download_file!(from_url, to_path, download_options = {})
|
49
|
+
options = download_options.dup
|
50
|
+
|
51
|
+
# :enable_progress_bar is a special option we handle.
|
52
|
+
# by default we enable the progress bar.
|
53
|
+
enable_progress_bar = options.delete(:enable_progress_bar)
|
54
|
+
enable_progress_bar = true if enable_progress_bar.nil?
|
55
|
+
|
56
|
+
options.merge!(download_headers)
|
57
|
+
options[:read_timeout] = Omnibus::Config.fetcher_read_timeout
|
58
|
+
|
59
|
+
fetcher_retries ||= Omnibus::Config.fetcher_retries
|
60
|
+
|
61
|
+
reported_total = 0
|
62
|
+
if enable_progress_bar
|
63
|
+
progress_bar = ProgressBar.create(
|
64
|
+
output: $stdout,
|
65
|
+
format: '%e %B %p%% (%r KB/sec)',
|
66
|
+
rate_scale: ->(rate) { rate / 1024 },
|
67
|
+
)
|
68
|
+
|
69
|
+
options[:content_length_proc] = ->(total) {
|
70
|
+
reported_total = total
|
71
|
+
progress_bar.total = total
|
72
|
+
}
|
73
|
+
options[:progress_proc] = ->(step) {
|
74
|
+
downloaded_amount = [step, reported_total].min
|
75
|
+
progress_bar.progress = downloaded_amount
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
file = open(from_url, options)
|
80
|
+
# This is a temporary file. Close and flush it before attempting to copy
|
81
|
+
# it over.
|
82
|
+
file.close
|
83
|
+
FileUtils.cp(file.path, to_path)
|
84
|
+
file.unlink
|
85
|
+
rescue SocketError,
|
86
|
+
Errno::ECONNREFUSED,
|
87
|
+
Errno::ECONNRESET,
|
88
|
+
Errno::ENETUNREACH,
|
89
|
+
Timeout::Error,
|
90
|
+
OpenURI::HTTPError => e
|
91
|
+
if fetcher_retries != 0
|
92
|
+
log.info(log_key) { "Retrying failed download due to #{e} (#{fetcher_retries} retries left)..." }
|
93
|
+
fetcher_retries -= 1
|
94
|
+
retry
|
95
|
+
else
|
96
|
+
log.error(log_key) { "Download failed - #{e.class}!" }
|
97
|
+
raise
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# The list of headers to pass to the download.
|
103
|
+
#
|
104
|
+
# @return [Hash]
|
105
|
+
#
|
106
|
+
def download_headers
|
107
|
+
{}.tap do |h|
|
108
|
+
# Alright kids, sit down while grandpa tells you a story. Back when the
|
109
|
+
# Internet was just a series of tubes, and you had to "dial in" using
|
110
|
+
# this thing called a "modem", ancient astronaunt theorists (computer
|
111
|
+
# scientists) invented gzip to compress requests sent over said tubes
|
112
|
+
# and make the Internet faster.
|
113
|
+
#
|
114
|
+
# Fast forward to the year of broadband - ungzipping these files was
|
115
|
+
# tedious and hard, so Ruby and other client libraries decided to do it
|
116
|
+
# for you:
|
117
|
+
#
|
118
|
+
# https://github.com/ruby/ruby/blob/c49ae7/lib/net/http.rb#L1031-L1033
|
119
|
+
#
|
120
|
+
# Meanwhile, software manufacturers began automatically compressing
|
121
|
+
# their software for distribution as a +.tar.gz+, publishing the
|
122
|
+
# appropriate checksums accordingly.
|
123
|
+
#
|
124
|
+
# But consider... If a software manufacturer is publishing the checksum
|
125
|
+
# for a gzipped tarball, and the client is automatically ungzipping its
|
126
|
+
# responses, then checksums can (read: should) never match! Herein lies
|
127
|
+
# the bug that took many hours away from the lives of a once-happy
|
128
|
+
# developer.
|
129
|
+
#
|
130
|
+
# TL;DR - Do not let Ruby ungzip our file
|
131
|
+
#
|
132
|
+
h['Accept-Encoding'] = 'identity'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|