Skip to content

Commit d8e6f6c

Browse files
committed
replace web scraping with docker subprocess
1 parent ca46c3b commit d8e6f6c

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

internal/lib/distro_info.rb

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,8 @@ def extract_nginx_version(os, distro, sanitize)
102102
if UBUNTU_DISTRIBUTIONS.key?(distro)
103103
version = fetch_latest_nginx_version_from_launchpad_api(distro)
104104
elsif DEBIAN_DISTRIBUTIONS.key?(distro)
105-
url = "https://packages.debian.org/search?suite=#{distro}&exact=1&searchon=names&keywords=nginx"
106-
retries = 0
107-
doc = begin
108-
if RUBY_VERSION >= '2.5'
109-
URI.open(url) do |io|
110-
Nokogiri.XML(io)
111-
end
112-
else
113-
open(url) do |io|
114-
Nokogiri.XML(io)
115-
end
116-
end
117-
rescue
118-
if (retries += 1) <= 3
119-
sleep(retries)
120-
retry
121-
else
122-
raise
123-
end
124-
end
125-
126-
version = doc.at_css('#psearchres ul li').text.lines.select{|s|s.include? ": all" or s.include? ": amd64 arm64"}.first.strip.split.first.chomp(':')
105+
output=`docker run debian:#{distro} bash -c 'apt-get update >/dev/null && apt-cache policy nginx'`
106+
version = output.lines.filter_map{|l| $' if l =~ /Candidate:/}.first.strip
127107
end
128108
File.write(cache_file,version)
129109
else

0 commit comments

Comments
 (0)