-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.rb
More file actions
162 lines (145 loc) · 4.56 KB
/
config.rb
File metadata and controls
162 lines (145 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
require 'erb'
require 'open-uri'
require 'json'
DOIT = !(ENV['DRY_RUN'] == '1')
NUM_RETRIES = ENV['DOCKERHUB'] ? 15 : 3
RETRY_JITTER = ENV['DOCKERHUB'] ? (30*1000) : 2000
RETRY_MAX_INTERVAL = ENV['DOCKERHUB'] ? (120.0+rand(60)) : 60.0
def cmd(*args, exception: true, num_retries: NUM_RETRIES)
puts "#{DOIT ? '' : '(dry-run) '}$ #{args.join(" ")}"
tries = 0
begin
system(*args, exception: exception) if DOIT
rescue RuntimeError => e
tries += 1
wait = [(2**tries) + (rand(RETRY_JITTER)/1000.0), RETRY_MAX_INTERVAL].min
if tries > num_retries
raise
else
$stderr.puts e.full_message
$stderr.puts "Retry in #{wait}s (#{tries}/#{num_retries})"
sleep wait
retry
end
end
end
@apt_repo_packages = {}
def apt_packages(repo_url)
# source->package->versions
@apt_repo_packages[repo_url] ||= URI.open(repo_url, 'r', &:read)
.each_line
.slice_after{ |_| _.chomp.empty? }
.map { |chunk|
chunk
.map(&:chomp)
.reject(&:empty?)
.slice_before { |_| _[0] != ' ' }
.map { |_|
key, val = _.first.split(': ', 2)
[key.sub(/: ?\z/,''), [val.nil? || val.empty? ? nil : val, *_[1..-1].map{ |x| x.sub(/^ /,'') }].compact]
}.to_h
}
.group_by{ |_| (_['Source'] || _['Package'])[0] }
.map{ |source, versions| [source, versions.group_by{ |_| _['Package'][0] }] }
.to_h
end
Release = Struct.new(:version, :arm, :default_distro, keyword_init: true)
Distro = Struct.new(:family, :name, :apt_url, :arm, keyword_init: true)
BuiltImage = Struct.new(:series, :version, :distro, :dev, :arch, keyword_init: true) do
def repo
'sorah-ruby'
end
def series_tag
"#{series }#{dev ? '-dev' : nil}"
end
def series_distro_tag
"#{series }#{dev ? '-dev' : nil}-#{distro}"
end
def version_tag
"#{version}#{dev ? '-dev' : nil}"
end
def version_distro_tag
"#{version}#{dev ? '-dev' : nil}-#{distro}"
end
def canonical_tag
"#{version}#{dev ? '-dev' : nil}-#{distro}-#{arch}"
end
def platform
"linux/#{arch}"
end
end
DISTROS = [
Distro.new(
family: 'ubuntu',
name: 'bionic',
apt_url: 'https://cache.ruby-lang.org/lab/sorah/deb/dists/bionic/main/binary-amd64/Packages',
arm: true,
),
Distro.new(
family: 'ubuntu',
name: 'focal',
apt_url: 'https://cache.ruby-lang.org/lab/sorah/deb/dists/focal/main/binary-amd64/Packages',
arm: true,
),
Distro.new(
family: 'ubuntu',
name: 'jammy',
apt_url: 'https://cache.ruby-lang.org/lab/sorah/deb/dists/jammy/main/binary-amd64/Packages',
arm: true,
),
Distro.new(
family: 'ubuntu',
name: 'noble',
apt_url: 'https://cache.ruby-lang.org/lab/sorah/deb/dists/noble/main/binary-amd64/Packages',
arm: true,
),
Distro.new(
family: 'ubuntu',
name: 'resolute',
apt_url: 'https://cache.ruby-lang.org/lab/sorah/deb/dists/resolute/main/binary-amd64/Packages',
arm: true,
),
Distro.new(
family: 'debian',
name: 'bullseye',
apt_url: 'https://cache.ruby-lang.org/lab/sorah/deb/dists/bullseye/main/binary-amd64/Packages',
arm: true,
),
Distro.new(
family: 'debian',
name: 'buster',
apt_url: 'https://cache.ruby-lang.org/lab/sorah/deb/dists/buster/main/binary-amd64/Packages',
arm: true,
),
Distro.new(
family: 'debian',
name: 'bookworm',
apt_url: 'https://cache.ruby-lang.org/lab/sorah/deb/dists/bookworm/main/binary-amd64/Packages',
arm: true,
),
Distro.new(
family: 'debian',
name: 'trixie',
apt_url: 'https://cache.ruby-lang.org/lab/sorah/deb/dists/trixie/main/binary-amd64/Packages',
arm: true,
),
]
# NOTE: Make sure build.jsonnet is updated as well
ARCHS = %w(arm64 amd64)
SERIES = [
Release.new(version: '2.6', default_distro: 'focal'),
Release.new(version: '2.7', default_distro: 'focal', arm: true),
Release.new(version: '3.0', default_distro: 'focal', arm: true),
Release.new(version: '3.1', default_distro: 'jammy', arm: true),
Release.new(version: '3.2', default_distro: 'jammy', arm: true),
Release.new(version: '3.3', default_distro: 'jammy', arm: true),
Release.new(version: '3.4', default_distro: 'noble', arm: true),
Release.new(version: '4.0', default_distro: 'noble', arm: true),
]
def find_series(version)
SERIES.find { _1.version == version } or raise "series not found for #{version.inspect}"
end
PUSH_REPOS = ENV['DOCKERHUB'] ? %W(sorah/ruby) : %W(public.ecr.aws/sorah/ruby ghcr.io/sorah-rbpkg/ruby)
DISTRO_FILTER = ENV['DIST_FILTER']&.split(/,\s*/)
ARCH_FILTER = ENV['ARCH_FILTER']&.split(/,\s*/)
SERIES_FILTER = ENV['SERIES_FILTER']&.split(/,\s*/)