forked from gocd/gocd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Distro.groovy
297 lines (257 loc) · 10.9 KB
/
Distro.groovy
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
* Copyright 2023 Thoughtworks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.thoughtworks.go.build.docker
import com.thoughtworks.go.build.Architecture
import com.thoughtworks.go.build.OperatingSystem
import org.gradle.api.Project
enum Distro implements DistroBehavior {
alpine{
@Override
List<DistroVersion> getSupportedVersions() {
return [ // See https://endoflife.date/alpine
new DistroVersion(version: '3.15', releaseName: '3.15', eolDate: parseDate('2023-11-01')),
new DistroVersion(version: '3.16', releaseName: '3.16', eolDate: parseDate('2024-05-23')),
new DistroVersion(version: '3.17', releaseName: '3.17', eolDate: parseDate('2024-11-22')),
new DistroVersion(version: '3.18', releaseName: '3.18', eolDate: parseDate('2025-05-09')),
]
}
@Override
List<String> getBaseImageUpdateCommands(DistroVersion v) {
return ['apk --no-cache upgrade']
}
@Override
List<String> getCreateUserAndGroupCommands() {
return [
'adduser -D -u ${UID} -s /bin/bash -G root go'
]
}
@Override
List<String> getInstallPrerequisitesCommands(DistroVersion v) {
return [
// procps is needed for tanuki wrapper shell script
'apk add --no-cache nss git mercurial subversion openssh-client bash curl procps'
]
}
@Override
List<String> getInstallJavaCommands(Project project) {
// Originally copied verbatim from https://github.com/AdoptOpenJDK/openjdk-docker/blob/436253bad9e494ea0043da22fca197e6055a538a/15/jdk/alpine/Dockerfile.hotspot.releases.slim#L24-L55
// Subsequent to this, Adoptium have moved to use of native Alpine/musl libc builds for JDK 16/17 onwards.
// More detail at https://github.com/adoptium/temurin-build/issues/2688 and https://github.com/adoptium/containers/issues/1
// Unfortunately, these do not work for GoCD due to the Tanuki Wrapper which does not currently work with musl libc,
// nor alternate compatibility layers such as libc6-compat or gcompat.
//
// zlib/libz.so.1 is required by the JRE, and we need a glibc-linked version. Can probably be latest available version.
return [
'# install glibc/zlib for the Tanuki Wrapper, and use by glibc-linked Adoptium JREs',
' apk add --no-cache tzdata --virtual .build-deps curl binutils zstd',
' GLIBC_VER="2.34-r0"',
' ALPINE_GLIBC_REPO="https://github.com/sgerrand/alpine-pkg-glibc/releases/download"',
' ZLIB_URL="https://archive.archlinux.org/packages/z/zlib/zlib-1%3A1.2.13-2-x86_64.pkg.tar.zst"',
' ZLIB_SHA256=c4f394724b20b84d7304b23bbb58442b6ef53e5cbac89eb51e39d7f0a46abafd',
' curl -LfsS https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub',
' SGERRAND_RSA_SHA256="823b54589c93b02497f1ba4dc622eaef9c813e6b0f0ebbb2f771e32adf9f4ef2"',
' echo "${SGERRAND_RSA_SHA256} */etc/apk/keys/sgerrand.rsa.pub" | sha256sum -c -',
' curl -LfsS ${ALPINE_GLIBC_REPO}/${GLIBC_VER}/glibc-${GLIBC_VER}.apk > /tmp/glibc-${GLIBC_VER}.apk',
' apk add --no-cache --force-overwrite /tmp/glibc-${GLIBC_VER}.apk',
' curl -LfsS ${ALPINE_GLIBC_REPO}/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk > /tmp/glibc-bin-${GLIBC_VER}.apk',
' apk add --no-cache /tmp/glibc-bin-${GLIBC_VER}.apk',
' curl -Ls ${ALPINE_GLIBC_REPO}/${GLIBC_VER}/glibc-i18n-${GLIBC_VER}.apk > /tmp/glibc-i18n-${GLIBC_VER}.apk',
' apk add --no-cache /tmp/glibc-i18n-${GLIBC_VER}.apk',
' /usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "$LANG" || true',
' echo "export LANG=$LANG" > /etc/profile.d/locale.sh',
' curl -LfsS ${ZLIB_URL} -o /tmp/libz.tar.zst',
' echo "${ZLIB_SHA256} */tmp/libz.tar.zst" | sha256sum -c -',
' mkdir /tmp/libz',
' zstd -d /tmp/libz.tar.zst --output-dir-flat /tmp',
' tar -xf /tmp/libz.tar -C /tmp/libz',
' mv /tmp/libz/usr/lib/libz.so* /usr/glibc-compat/lib',
' apk del --purge .build-deps glibc-i18n',
' rm -rf /tmp/*.apk /tmp/libz /tmp/libz.tar* /var/cache/apk/*',
'# end installing glibc/zlib',
] + super.getInstallJavaCommands(project)
}
},
centos{
@Override
Set<Architecture> getSupportedArchitectures() {
[Architecture.x64, Architecture.aarch64]
}
@Override
String getBaseImageRegistry(DistroVersion v) {
v.lessThan(8) ? super.baseImageRegistry : "quay.io/centos"
}
@Override
List<String> getBaseImageUpdateCommands(DistroVersion v) {
def commands = [
"echo 'fastestmirror=1' >> /etc/${pkgFor(v) == 'yum' ? 'yum' : 'dnf/dnf'}.conf",
"echo 'install_weak_deps=False' >> /etc/${pkgFor(v) == 'yum' ? 'yum' : 'dnf/dnf'}.conf",
]
if (v.lessThan(8)) {
commands += [
"${pkgFor(v)} install -y centos-release-scl-rh grubby",
"${pkgFor(v)} autoremove -y",
"${pkgFor(v)} remove -y grubby",
]
}
commands += [
"${pkgFor(v)} upgrade -y",
"${pkgFor(v)} install -y shadow-utils",
]
commands
}
@Override
List<String> getInstallPrerequisitesCommands(DistroVersion v) {
def commands = [
"${pkgFor(v)} install -y mercurial subversion openssh-clients bash unzip procps" +
(v.lessThan(8) ? ' rh-git227-git-core sysvinit-tools coreutils' : ' git-core procps-ng coreutils-single') +
(v.lessThan(9) ? ' curl' : ' curl-minimal')
]
if (v.lessThan(8)) {
commands += 'cp /opt/rh/rh-git227/enable /etc/profile.d/rh-git227.sh'
}
commands += [
"${pkgFor(v)} clean all",
"rm -rf /var/cache/${pkgFor(v)}",
]
commands
}
private String pkgFor(DistroVersion v) {
switch (v.version) {
case '7': return 'yum'
case '8': return 'dnf'
case '9': return 'microdnf'
default: throw IllegalArgumentException("Unknown version $v")
}
}
@Override
Map<String, String> getEnvironmentVariables(DistroVersion v) {
def vars = super.getEnvironmentVariables(v)
if (v.lessThan(8)) {
return vars + [
BASH_ENV: "/opt/rh/rh-git227/enable",
ENV : "/opt/rh/rh-git227/enable"
] as Map<String, String>
} else {
return vars
}
}
@Override
List<DistroVersion> getSupportedVersions() {
return [ // See https://endoflife.date/centos
new DistroVersion(version: '7', releaseName: '7', eolDate: parseDate('2024-06-30')),
new DistroVersion(version: '8', releaseName: 'stream8', eolDate: parseDate('2024-05-31'), installPrerequisitesCommands: ['dnf install -y glibc-langpack-en']),
new DistroVersion(version: '9', releaseName: 'stream9-minimal', eolDate: parseDate('2027-05-31'), installPrerequisitesCommands: ['microdnf install -y glibc-langpack-en tar tzdata epel-release epel-next-release']),
]
}
},
debian{
@Override
Set<Architecture> getSupportedArchitectures() {
[Architecture.x64, Architecture.aarch64]
}
@Override
List<String> getBaseImageUpdateCommands(DistroVersion v) {
return [
'DEBIAN_FRONTEND=noninteractive apt-get update',
'DEBIAN_FRONTEND=noninteractive apt-get upgrade -y',
]
}
@Override
List<String> getInstallPrerequisitesCommands(DistroVersion v) {
return [
'DEBIAN_FRONTEND=noninteractive apt-get install -y git-core subversion mercurial openssh-client bash unzip curl ca-certificates locales procps sysvinit-utils coreutils',
'DEBIAN_FRONTEND=noninteractive apt-get clean all',
'rm -rf /var/lib/apt/lists/*',
'echo \'en_US.UTF-8 UTF-8\' > /etc/locale.gen && /usr/sbin/locale-gen'
]
}
@Override
List<DistroVersion> getSupportedVersions() {
return [ // See https://endoflife.date/debian
new DistroVersion(version: '10', releaseName: 'buster-slim', eolDate: parseDate('2024-06-01')),
new DistroVersion(version: '11', releaseName: 'bullseye-slim', eolDate: parseDate('2026-06-30')),
new DistroVersion(version: '12', releaseName: 'bookworm-slim', eolDate: parseDate('2028-06-10')),
]
}
},
ubuntu{
@Override
Set<Architecture> getSupportedArchitectures() {
debian.supportedArchitectures
}
@Override
List<String> getBaseImageUpdateCommands(DistroVersion v) {
return debian.getBaseImageUpdateCommands(v)
}
@Override
List<String> getInstallPrerequisitesCommands(DistroVersion v) {
return debian.getInstallPrerequisitesCommands(v)
}
@Override
List<DistroVersion> getSupportedVersions() {
return [ // See https://endoflife.date/ubuntu "Maintenance & Security Support"
new DistroVersion(version: '20.04', releaseName: 'focal', eolDate: parseDate('2025-04-02')),
new DistroVersion(version: '22.04', releaseName: 'jammy', eolDate: parseDate('2027-04-01')),
]
}
},
docker{
@Override
OperatingSystem getOperatingSystem() {
return alpine.getOperatingSystem()
}
@Override
boolean isPrivilegedModeSupport() {
return true
}
@Override
List<String> getBaseImageUpdateCommands(DistroVersion v) {
return alpine.getBaseImageUpdateCommands(v)
}
@Override
List<String> getCreateUserAndGroupCommands() {
return alpine.getCreateUserAndGroupCommands()
}
@Override
List<String> getInstallPrerequisitesCommands(DistroVersion v) {
return alpine.getInstallPrerequisitesCommands(v) +
[
'apk add --no-cache sudo',
'rm -rf /lib/libudev.so*', // btrfs is installed by Docker, but requires eudev-libs, which causes issues with OSHI JNA libary on Alpine with glibc and JVM crashes. Dont think we need udev as it's only needed by btrfs for multipath support.
]
}
@Override
List<String> getInstallJavaCommands(Project project) {
return alpine.getInstallJavaCommands(project)
}
@Override
Map<String, String> getEnvironmentVariables(DistroVersion v) {
return alpine.getEnvironmentVariables(v)
}
@Override
List<DistroVersion> getSupportedVersions() {
return [
new DistroVersion(version: 'dind', releaseName: 'dind', eolDate: parseDate('2099-01-01'))
]
}
}
static Date parseDate(String date) {
return Date.parse("yyyy-MM-dd", date)
}
GString projectName(DistroVersion v) {
return "${name()}-${v.version}"
}
}