Commit e8611aec authored by Tobias Schmidt's avatar Tobias Schmidt

Render tarball sha256 checksum if available for release

parent 5f38896b
...@@ -233,8 +233,9 @@ footer { ...@@ -233,8 +233,9 @@ footer {
} }
.downloads .checksum { .downloads .checksum {
color: #aaa; font-family: monospace;
font-style: italic; font-size: .6em;
vertical-align: bottom;
} }
/* Docs-related styles. */ /* Docs-related styles. */
......
...@@ -29,11 +29,6 @@ title: Download ...@@ -29,11 +29,6 @@ title: Download
the <a href="/docs/introduction/getting_started/">installation instructions</a>. the <a href="/docs/introduction/getting_started/">installation instructions</a>.
</p> </p>
<div class="alert alert-info" role="alert">
<strong>Work in progress!</strong>
We will provide more precompiled binary versions as well as checksums soon.
</div>
<div class="panel panel-default download-selection"> <div class="panel panel-default download-selection">
<div class="panel-body"> <div class="panel-body">
Operating system <%= dropdown(:os, Downloads.operating_systems, :popular, popular: %w(darwin linux windows)) %> Operating system <%= dropdown(:os, Downloads.operating_systems, :popular, popular: %w(darwin linux windows)) %>
...@@ -64,13 +59,13 @@ title: Download ...@@ -64,13 +59,13 @@ title: Download
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% release.assets.each do |asset| %> <% release.binaries.each do |binary| %>
<tr data-os="<%= asset.os %>" data-arch="<%= asset.arch %>"> <tr data-os="<%= binary.os %>" data-arch="<%= binary.arch %>">
<td class="filename"><a class="download" href="<%= asset.url %>"><%= asset.name %></a></td> <td class="filename"><a class="download" href="<%= binary.url %>"><%= binary.name %></a></td>
<td><%= asset.os %></td> <td><%= binary.os %></td>
<td><%= asset.arch %></td> <td><%= binary.arch %></td>
<td><%= format_bytes asset.size %></td> <td><%= format_bytes binary.size %></td>
<td class="checksum">not available yet</td> <td class="checksum"><%= Downloads.checksum(release, binary.name) %></td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
......
require 'fileutils'
require 'json' require 'json'
require 'open-uri'
module Downloads module Downloads
# repositories returns a list of all repositories with releases. # repositories returns a list of all repositories with releases.
def self.repositories def self.repositories
@repositories ||= begin @_repositories ||= begin
repos = Dir.glob('downloads/*').map { |dir| Repository.new(dir) } repos = Dir.glob('downloads/*').map { |dir| Repository.new(dir) }
repos.sort_by { |r| r.name == 'prometheus' ? '0' : r.name } repos.sort_by { |r| r.name == 'prometheus' ? '0' : r.name }
end end
...@@ -13,7 +15,7 @@ module Downloads ...@@ -13,7 +15,7 @@ module Downloads
# provided for. # provided for.
def self.operating_systems def self.operating_systems
repositories.inject([]) do |list, repo| repositories.inject([]) do |list, repo|
list += repo.releases.map { |r| r.assets.map(&:os) }.flatten list += repo.releases.map { |r| r.binaries.map(&:os) }.flatten
end.uniq.sort end.uniq.sort
end end
...@@ -21,10 +23,38 @@ module Downloads ...@@ -21,10 +23,38 @@ module Downloads
# provided for. # provided for.
def self.architectures def self.architectures
repositories.inject([]) do |list, repo| repositories.inject([]) do |list, repo|
list += repo.releases.map { |r| r.assets.map(&:arch) }.flatten list += repo.releases.map { |r| r.binaries.map(&:arch) }.flatten
end.uniq.sort end.uniq.sort
end end
# checksum returns the checksum for a given filename of a given release. It
# might try to download the sha256sums.txt from the given release if available
# and not already cached.
def self.checksum(release, name)
@_checksums ||= {}
@_checksums[release.id] ||= begin
asset = release.assets.find { |a| a['name'] == 'sha256sums.txt' }
if asset
cache = ['downloads', '.cache', release.id, 'sha256sums.txt'].join('/')
unless File.exists?(cache)
FileUtils.mkdir_p(File.dirname(cache))
File.open(cache, 'wb') do |file|
file.write(URI.parse(asset['browser_download_url']).read)
end
end
File.readlines(cache).each_with_object({}) do |line, memo|
checksum, filename = line.split(/\s+/)
memo[filename] = checksum
end
else
{}
end
end
@_checksums[release.id][name]
end
class Repository class Repository
def initialize(dir) def initialize(dir)
@repo = JSON.parse(File.read(File.join(dir, 'repo.json'))) @repo = JSON.parse(File.read(File.join(dir, 'repo.json')))
...@@ -66,6 +96,10 @@ module Downloads ...@@ -66,6 +96,10 @@ module Downloads
@data = data @data = data
end end
def id
@data['id']
end
def name def name
@data['name'] @data['name']
end end
...@@ -79,11 +113,17 @@ module Downloads ...@@ -79,11 +113,17 @@ module Downloads
end end
def assets def assets
@data['assets'].map { |d| Asset.new(d) } @data['assets']
end
def binaries
assets.
select { |d| d['name'] && %w[.tar.gz .zip].any? { |ext| d['name'].end_with?(ext) } }.
map { |d| Binary.new(d) }
end end
end end
class Asset class Binary
def initialize(data) def initialize(data)
@data = data @data = data
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment