-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux.Modusfile
234 lines (218 loc) · 9.69 KB
/
linux.Modusfile
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
# Could have a prefix predicate?
is_alpine(VARIANT, ALPINE_VERSION) :- VARIANT = f"alpine${ALPINE_VERSION}".
is_oracle(VARIANT, ORACLE_VERSION) :- VARIANT = f"oraclelinux${ORACLE_VERSION}".
is_debian(VARIANT) :- debian_variant(VARIANT). # HACK: to determine if (non-slim) debian base image, should replace.
is_debian_slim(VARIANT, DEBIAN_SUITE) :- VARIANT = f"slim-${DEBIAN_SUITE}".
oracle_installer_cleaner_version("yum install -y", "rm -rf /var/cache/yum", "7").
oracle_installer_cleaner_version("microdnf install", "microdnf clean all", oracle_version) :-
number_gt(oracle_version, "7").
debian_suffix_type("-scm", "jdk").
debian_suffix_type("-curl", "jre").
debian_image(VARIANT, JAVA_TYPE) :-
(
is_debian_slim(VARIANT, DEBIAN_SUITE),
from(f"debian:${DEBIAN_SUITE}-slim")
;
is_debian(VARIANT),
debian_suffix_type(SUFFIX, JAVA_TYPE),
from(f"buildpack-deps:${VARIANT}${SUFFIX}")
).
debian_packages("ca-certificates p11-kit", variant, major_version) :-
is_debian_slim(variant, _).
debian_packages("bzip2 unzip xz-utils binutils fontconfig libfreetype6 \
ca-certificates p11-kit",
variant,
major_version) :-
is_debian(variant), number_geq(major_version, "13").
debian_packages("bzip2 unzip xz-utils fontconfig libfreetype6 \
ca-certificates p11-kit",
variant,
major_version) :-
is_debian(variant), number_gt("13", major_version).
backwards_compatibility(MAJOR_VERSION, JAVA_HOME) :-
# backwards compatibility for debian versions < 16
(
number_gt("16", MAJOR_VERSION),
run(f"{ echo '#/bin/sh'; echo 'echo \"${JAVA_HOME}\"'; } > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home \
&& [ \"${JAVA_HOME}\" = \"\$(docker-java-home)\" ]")
;
number_geq(MAJOR_VERSION, "16"),
run("")
).
locale(variant, "en_US.UTF-8") :- is_oracle(variant, "7").
locale(variant, "C.UTF-8") :- !is_oracle(variant, "7").
# Selects base image and runs relevant initial commands to prepare it.
base_image(MAJOR_VERSION, VARIANT, JAVA_HOME, JAVA_TYPE, BASE_SETUP_COMMAND) :-
(
is_alpine(VARIANT, ALPINE_VERSION),
from(f"alpine:${ALPINE_VERSION}"),
BASE_SETUP_COMMAND = "apk add --no-cache java-cacerts",
JAVA_HOME = f"/opt/openjdk-${MAJOR_VERSION}"
;
is_oracle(VARIANT, ORACLE_VERSION),
oracle_installer_cleaner_version(INSTALLER, CLEANER, ORACLE_VERSION),
from(f"oraclelinux:${ORACLE_VERSION}-slim"),
BASE_SETUP_COMMAND = f"set -eux; \
${INSTALLER} gzip tar binutils freetype fontconfig; \
${CLEANER}",
JAVA_HOME = f"/usr/java/openjdk-${MAJOR_VERSION}"
;
!(is_alpine(VARIANT, _) ; is_oracle(VARIANT, _)),
debian_image(VARIANT, JAVA_TYPE),
debian_packages(PACKAGES, VARIANT, MAJOR_VERSION),
BASE_SETUP_COMMAND = f"set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends ${PACKAGES}; \
rm -rf /var/lib/apt/lists/*",
JAVA_HOME = f"/usr/local/openjdk-${MAJOR_VERSION}",
backwards_compatibility(MAJOR_VERSION, JAVA_HOME)
).
gpg_check_source(getter, "adopt") :-
run(f"${getter} openjdk.tgz.asc \"`cat /tmp/downloadUrl`.sign\""),
run("set -eux; \
export GNUPGHOME=\"$(mktemp -d)\"; \
echo \"$GNUPGHOME\" > /tmp/GNUPGHOME; \
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys EAC843EBD3EFDB98CC772FADA5CD6035332FA671; \
gpg --batch --keyserver keyserver.ubuntu.com --keyserver-options no-self-sigs-only --recv-keys CA5F11C6CE22644D42C6AC4492EF8D39DC13168F; \
gpg --batch --list-sigs --keyid-format 0xLONG CA5F11C6CE22644D42C6AC4492EF8D39DC13168F \
| tee /dev/stderr \
| grep '0xA5CD6035332FA671' \
| grep 'Andrew Haley'; \
gpg --batch --verify openjdk.tgz.asc openjdk.tgz;"),
run("gpgconf --kill all;"),
run("rm -rf \"`cat /tmp/GNUPGHOME`\"").
gpg_check_source(getter, source) :- source != "adopt", run("").
extract_bin(JAVA_HOME) :-
run(f"mkdir -p ${JAVA_HOME}; \
tar --extract \
--file openjdk.tgz \
--directory \"${JAVA_HOME}\" \
--strip-components 1 \
--no-same-owner \
; \
rm openjdk.tgz*;").
install_bin(AMD64_URL, ARM64_URL, JAVA_HOME, SOURCE) :-
ARCH_PRINTER = "apk --print-arch",
AMD64_MATCH = "x86_64",
ARM64_MATCH = "aarch64",
GETTER = "wget -O",
# It shouldn't really matter that the binary we're downloading/extracting here may not work
# on alpine, since we will just copy the extracted files into the correct base image later.
# So this is fine as long as we don't try to execute it here.
from("alpine:latest"),
run("apk add gnupg"),
run(f"set -eux; \
arch=\"\$(${ARCH_PRINTER})\"; \
case \"\$arch\" in \
'${AMD64_MATCH}') \
downloadUrl='${AMD64_URL}'; \
;; \
'${ARM64_MATCH}') \
downloadUrl='${ARM64_URL}'; \
;; \
*) echo >&2 \"error: unsupported architecture: '\$arch'\"; exit 1 ;; \
esac; \
echo \"$downloadUrl\" > /tmp/downloadUrl; \
${GETTER} openjdk.tgz \"\$downloadUrl\";"),
gpg_check_source(GETTER, SOURCE),
extract_bin(JAVA_HOME),
run("rm -rf /tmp/downloadUrl").
ca_certs(MAJOR_VERSION, JAVA_TYPE, VARIANT, JAVA_HOME) :-
(
MAJOR_VERSION = "8", JAVA_TYPE = "jdk",
CACERTS_FILE = f"${JAVA_HOME}/jre/lib/security/cacerts"
;
(number_gt(MAJOR_VERSION, "8") ; JAVA_TYPE = "jre"),
CACERTS_FILE = f"${JAVA_HOME}/lib/security/cacerts"
),
(
is_alpine(VARIANT, ALPINE_VERSION),
run(f"rm -rf \"${CACERTS_FILE}\"; \
ln -sT /etc/ssl/certs/java/cacerts \"${CACERTS_FILE}\";")
;
is_oracle(VARIANT, ORACLE_VERSION),
run(f"rm -rf \"${CACERTS_FILE}\"; \
ln -sT /etc/pki/ca-trust/extracted/java/cacerts \"${CACERTS_FILE}\"; \
\
ln -sfT \"${JAVA_HOME}\" /usr/java/default; \
ln -sfT \"${JAVA_HOME}\" /usr/java/latest; \
for bin in \"${JAVA_HOME}/bin/\"*; do \
base=\"\$(basename \"\$bin\")\"; \
[ ! -e \"/usr/bin/\$base\" ]; \
alternatives --install \"/usr/bin/\$base\" \"\$base\" \"\$bin\" 20000; \
done;")
;
(is_debian(VARIANT) ; is_debian_slim(VARIANT, DEBIAN_SUITE)),
run(f"{ \
echo '#!/usr/bin/env bash'; \
echo 'set -Eeuo pipefail'; \
echo 'trust extract --overwrite --format=java-cacerts --filter=ca-anchors --purpose=server-auth \"${CACERTS_FILE}\"'; \
} > /etc/ca-certificates/update.d/docker-openjdk; \
chmod +x /etc/ca-certificates/update.d/docker-openjdk; \
/etc/ca-certificates/update.d/docker-openjdk; \
\
find \"${JAVA_HOME}/lib\" -name '*.so' -exec dirname '{}' ';' | sort -u > /etc/ld.so.conf.d/docker-openjdk.conf; \
ldconfig;")
).
smoke_tests_version_type("8", "jdk") :- run("javac -version; java -version").
smoke_tests_version_type("8", "jre") :- run("java -version").
smoke_tests_version_type(major_version, java_type) :-
number_gt(major_version, "8"),
(
java_type = "jdk",
command = "java -Xshare:dump; \
fileEncoding=\"$(echo 'System.out.println(System.getProperty(\"file.encoding\"))' | jshell -s -)\"; [ \"$fileEncoding\" = 'UTF-8' ]; rm -rf ~/.java; \
javac --version; \
java --version"
;
java_type = "jre",
command = "java -Xshare:dump; java --version"
),
run(command).
entry_sh_command(MAJOR_VERSION, JAVA_TYPE, VARIANT, COMMAND) :-
(
is_alpine(VARIANT, _), SHELL = "ash"
;
!is_alpine(VARIANT, _), SHELL = "bash"
),
(
(
MAJOR_VERSION = "8"
;
number_gt(MAJOR_VERSION, "8"), JAVA_TYPE = "jre"
),
COMMAND = SHELL
;
number_gt(MAJOR_VERSION, "8"), JAVA_TYPE = "jdk",
COMMAND = "jshell" # jshell only launched if jdk
).
openjdk_setup(MAJOR_VERSION, VERSION, JAVA_TYPE, VARIANT, AMD64_URL, ARM64_URL, SOURCE) :-
openjdk_config(MAJOR_VERSION, VERSION,
JAVA_TYPE,
VARIANT,
AMD64_URL, ARM64_URL,
SOURCE),
base_image(MAJOR_VERSION, VARIANT, JAVA_HOME, JAVA_TYPE, BASE_SETUP_COMMAND)
::append_path(f"${JAVA_HOME}/bin")
::set_env("JAVA_HOME", JAVA_HOME)
::set_env("LANG", LANG)
::set_env("JAVA_VERSION", VERSION),
(
run(BASE_SETUP_COMMAND),
locale(VARIANT, LANG),
install_bin(AMD64_URL, ARM64_URL, JAVA_HOME, SOURCE)::copy(JAVA_HOME, JAVA_HOME),
ca_certs(MAJOR_VERSION, JAVA_TYPE, VARIANT, JAVA_HOME),
smoke_tests_version_type(MAJOR_VERSION, JAVA_TYPE)
)::merge.
openjdk(major_version, java_type, variant) :-
entry_sh_command(major_version, java_type, variant, command),
(
string_concat("windows", windows_image, variant),
"0" = "1", # NOTE: no windows support atm. So this will intentionally always fail.
openjdk_setup(major_version, version, java_type, variant, amd64_url, arm64_url, source)
;
openjdk_setup(major_version, version, java_type, variant, amd64_url, arm64_url, source)
)::set_entrypoint(command).
debian_variant("bullseye").
debian_variant("buster").