Repository navigation
Expand file tree
/
Copy pathtest_dockerhub_doc_config_update.py
More file actions
2074 lines (1845 loc) · 97 KB
/
Copy pathtest_dockerhub_doc_config_update.py
File metadata and controls
2074 lines (1845 loc) · 97 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
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 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
#
# https://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.
#
import io
import hashlib
import json
import os
import subprocess
import sys
import tempfile
import textwrap
import unittest
from contextlib import redirect_stderr, redirect_stdout
from pathlib import Path
from unittest.mock import MagicMock, patch
from urllib.error import URLError
from adoptium_api import get_latest_lts, get_supported_versions
from dockerhub_doc_config_update import (
find_manifest_block,
fetch_official_manifest,
fetch_open_publication_prs,
create_publication_pr,
format_ojdk_version,
get_block_gitcommit,
get_distro_name,
get_dockerfile_arches,
get_java_version,
get_manifest_entries,
get_pending_arches,
get_github_token,
generate_manifest,
java_version_key,
main,
merge_publication_manifest,
github_pages,
PublicationPlan,
PublicationPR,
prepare_publication_source,
run_publication_command,
)
MOCK_API_RESPONSE = {
"available_lts_releases": [8, 11, 17, 21, 25],
"available_releases": [8, 11, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],
"most_recent_feature_release": 26,
"most_recent_feature_version": 27,
"most_recent_lts": 25,
"tip_version": 27,
}
def mock_urlopen(req):
"""Mock urllib.request.urlopen to return fake API data."""
class MockResponse:
def read(self):
return json.dumps(MOCK_API_RESPONSE).encode("utf-8")
def __enter__(self):
return self
def __exit__(self, *args):
pass
return MockResponse()
class TestAdoptiumAPI(unittest.TestCase):
@patch("adoptium_api.urllib.request.urlopen", side_effect=mock_urlopen)
def test_get_supported_versions(self, _mock):
versions = get_supported_versions()
self.assertEqual(versions, [8, 11, 17, 21, 25, 26])
@patch("adoptium_api.urllib.request.urlopen", side_effect=mock_urlopen)
def test_get_supported_versions_lts_only(self, _mock):
"""When most_recent_feature_release equals most_recent_lts, only LTS versions are returned."""
with patch.dict(MOCK_API_RESPONSE, {"most_recent_feature_release": 25}):
versions = get_supported_versions()
self.assertEqual(versions, [8, 11, 17, 21, 25])
@patch("adoptium_api.urllib.request.urlopen", side_effect=mock_urlopen)
def test_get_supported_versions_excludes_eol_26(self, _mock):
with patch.dict(MOCK_API_RESPONSE, {"most_recent_feature_release": 27, "available_releases": [8, 11, 17, 21, 25, 26, 27]}):
self.assertEqual(get_supported_versions(), [8, 11, 17, 21, 25, 27])
@patch("adoptium_api.urllib.request.urlopen", side_effect=mock_urlopen)
def test_get_supported_versions_multiple_non_lts(self, _mock):
"""Only the latest non-LTS release is supported alongside LTS releases."""
with patch.dict(MOCK_API_RESPONSE, {"most_recent_feature_release": 28, "available_releases": [8, 11, 17, 21, 25, 26, 27, 28]}):
versions = get_supported_versions()
self.assertEqual(versions, [8, 11, 17, 21, 25, 28])
@patch("adoptium_api.urllib.request.urlopen", side_effect=mock_urlopen)
def test_get_latest_lts(self, _mock):
self.assertEqual(get_latest_lts(), 25)
class TestFormatOjdkVersion(unittest.TestCase):
def test_jdk8_version(self):
self.assertEqual(format_ojdk_version("jdk8u482-b08"), "8u482-b08")
def test_jdk11_version(self):
self.assertEqual(format_ojdk_version("jdk-11.0.30+7"), "11.0.30_7")
def test_jdk25_version(self):
self.assertEqual(format_ojdk_version("jdk-25.0.2+10"), "25.0.2_10")
def test_jdk26_ea_version(self):
self.assertEqual(format_ojdk_version("jdk-26+35"), "26_35")
class TestGetDistroName(unittest.TestCase):
def test_ubuntu(self):
self.assertEqual(get_distro_name("linux", "ubuntu/noble"), "noble")
def test_alpine(self):
self.assertEqual(get_distro_name("alpine-linux", "alpine/3.23"), "alpine-3.23")
def test_ubi(self):
self.assertEqual(get_distro_name("linux", "ubi/ubi10-minimal"), "ubi10-minimal")
def test_windows(self):
self.assertEqual(
get_distro_name("windows", "windows/windowsservercore-ltsc2022"),
"windowsservercore-ltsc2022",
)
class TestGetJavaVersion(unittest.TestCase):
def test_extracts_version(self):
with tempfile.NamedTemporaryFile(mode="w", suffix=".Dockerfile", delete=False) as f:
f.write("FROM ubuntu:24.04\n")
f.write("ENV JAVA_VERSION=jdk-25.0.2+10\n")
f.write("RUN echo hello\n")
f.flush()
self.assertEqual(get_java_version(f.name), "jdk-25.0.2+10")
os.unlink(f.name)
def test_returns_none_when_missing(self):
with tempfile.NamedTemporaryFile(mode="w", suffix=".Dockerfile", delete=False) as f:
f.write("FROM ubuntu:24.04\n")
f.write("RUN echo hello\n")
f.flush()
self.assertIsNone(get_java_version(f.name))
os.unlink(f.name)
class TestGetDockerfileArches(unittest.TestCase):
def test_parses_ubuntu_arches(self):
dockerfile = textwrap.dedent("""\
FROM ubuntu:24.04
RUN set -eux; \\
ARCH="$(dpkg --print-architecture)"; \\
case "${ARCH}" in \\
amd64) \\
ESUM='abc123'; \\
;; \\
arm64) \\
ESUM='def456'; \\
;; \\
ppc64el) \\
ESUM='ghi789'; \\
;; \\
s390x) \\
ESUM='jkl012'; \\
;; \\
*) \\
echo "Unsupported arch: ${ARCH}"; \\
exit 1; \\
;; \\
esac;
""")
with tempfile.NamedTemporaryFile(mode="w", suffix=".Dockerfile", delete=False) as f:
f.write(dockerfile)
f.flush()
arches = get_dockerfile_arches(f.name)
self.assertEqual(arches, ["amd64", "arm64v8", "ppc64le", "s390x"])
os.unlink(f.name)
def test_parses_alpine_arches(self):
dockerfile = textwrap.dedent("""\
FROM alpine:3.23
RUN set -eux; \\
ARCH="$(apk --print-arch)"; \\
case "${ARCH}" in \\
x86_64) \\
ESUM='abc123'; \\
;; \\
aarch64) \\
ESUM='def456'; \\
;; \\
*) \\
echo "Unsupported arch: ${ARCH}"; \\
exit 1; \\
;; \\
esac;
""")
with tempfile.NamedTemporaryFile(mode="w", suffix=".Dockerfile", delete=False) as f:
f.write(dockerfile)
f.flush()
arches = get_dockerfile_arches(f.name)
self.assertEqual(arches, ["amd64", "arm64v8"])
os.unlink(f.name)
def test_parses_armhf(self):
dockerfile = textwrap.dedent("""\
FROM ubuntu:22.04
RUN set -eux; \\
case "${ARCH}" in \\
amd64) \\
;; \\
armhf) \\
;; \\
*) \\
;; \\
esac;
""")
with tempfile.NamedTemporaryFile(mode="w", suffix=".Dockerfile", delete=False) as f:
f.write(dockerfile)
f.flush()
arches = get_dockerfile_arches(f.name)
self.assertEqual(arches, ["amd64", "arm32v7"])
os.unlink(f.name)
def test_staggered_release_fewer_arches(self):
"""A Dockerfile with only amd64 and arm64 (e.g. early access release)."""
dockerfile = textwrap.dedent("""\
FROM ubuntu:24.04
RUN set -eux; \\
case "${ARCH}" in \\
amd64) \\
;; \\
arm64) \\
;; \\
*) \\
;; \\
esac;
""")
with tempfile.NamedTemporaryFile(mode="w", suffix=".Dockerfile", delete=False) as f:
f.write(dockerfile)
f.flush()
arches = get_dockerfile_arches(f.name)
self.assertEqual(arches, ["amd64", "arm64v8"])
os.unlink(f.name)
def test_pending_arches_only_include_marked_branches(self):
dockerfile = textwrap.dedent("""\
# TODO: This configured architecture is pending upstream binary availability
RUN case "${ARCH}" in
amd64)
ESUM='abc';
;;
armhf)
# TODO: This configured architecture is pending upstream binary availability for jdk8u504-b01.
exit 1;
;;
arm64)
ESUM='def';
;;
*)
# TODO: This configured architecture is pending upstream binary availability
exit 1;
;;
esac;
""")
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / "Dockerfile"
path.write_text(dockerfile)
self.assertEqual(get_pending_arches(path), ["arm32v7"])
self.assertEqual(get_dockerfile_arches(path), ["amd64", "arm32v7", "arm64v8"])
class TestJavaVersionKey(unittest.TestCase):
def test_feature_build_is_older_than_patch_release(self):
self.assertLess(java_version_key("jdk-27+35"), java_version_key("jdk-27.0.1.0"))
def test_build_numbers_are_numeric(self):
self.assertLess(java_version_key("jdk-25.0.2+9"), java_version_key("jdk-25.0.2+10"))
def test_jdk8_update_and_build_numbers(self):
self.assertLess(java_version_key("jdk8u492-b10"), java_version_key("jdk8u502-b01"))
self.assertLess(java_version_key("jdk8u502-b09"), java_version_key("jdk8u502-b10"))
def test_manifest_tag_and_java_version_compare_equal(self):
self.assertEqual(java_version_key("25.0.2_10"), java_version_key("jdk-25.0.2+10"))
self.assertEqual(java_version_key("8u502-b10"), java_version_key("jdk8u502-b10"))
class TestFetchOfficialManifest(unittest.TestCase):
@patch("dockerhub_doc_config_update.urllib.request.urlopen", side_effect=URLError("unavailable"))
def test_fetch_failure_is_reported_as_unavailable_not_an_empty_manifest(self, _urlopen):
output = io.StringIO()
with redirect_stderr(output):
self.assertIsNone(fetch_official_manifest())
self.assertIn("cannot compare with the official manifest", output.getvalue())
class TestFindManifestBlock(unittest.TestCase):
SAMPLE_MANIFEST = (
"Tags: 25.0.2_10-jdk-noble, 25-jdk-noble\n"
"Architectures: amd64, arm64v8\n"
"GitCommit: abc123\n"
"Directory: 25/jdk/ubuntu/noble\n"
"\n"
"Tags: 26_35-jdk-noble, 26-jdk-noble\n"
"Architectures: amd64\n"
"GitCommit: def456\n"
"Directory: 26/jdk/ubuntu/noble"
)
def test_finds_matching_block(self):
block = find_manifest_block(self.SAMPLE_MANIFEST, "25.0.2_10-jdk-noble, 25-jdk-noble")
self.assertIn("GitCommit: abc123", block)
def test_returns_none_for_no_match(self):
block = find_manifest_block(self.SAMPLE_MANIFEST, "99-jdk-noble")
self.assertIsNone(block)
def test_returns_none_for_empty_manifest(self):
self.assertIsNone(find_manifest_block("", "25-jdk-noble"))
self.assertIsNone(find_manifest_block(None, "25-jdk-noble"))
class TestGetBlockGitcommit(unittest.TestCase):
def test_extracts_commit(self):
block = "Tags: 25-jdk-noble\nGitCommit: abc123def\nDirectory: 25/jdk"
self.assertEqual(get_block_gitcommit(block), "abc123def")
def test_returns_none_for_no_commit(self):
block = "Tags: 25-jdk-noble\nDirectory: 25/jdk"
self.assertIsNone(get_block_gitcommit(block))
def test_returns_none_for_none(self):
self.assertIsNone(get_block_gitcommit(None))
class TestGenerateManifest(unittest.TestCase):
"""Integration test using a minimal config and temp Dockerfiles."""
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
# Create a minimal Dockerfile
jdk_dir = os.path.join(self.tmpdir, "25", "jdk", "ubuntu", "noble")
os.makedirs(jdk_dir)
with open(os.path.join(jdk_dir, "Dockerfile"), "w") as f:
f.write(textwrap.dedent("""\
FROM ubuntu:24.04
ENV JAVA_VERSION=jdk-25.0.2+10
RUN set -eux; \\
ARCH="$(dpkg --print-architecture)"; \\
case "${ARCH}" in \\
amd64) \\
ESUM='abc'; \\
;; \\
arm64) \\
ESUM='def'; \\
;; \\
*) \\
echo "Unsupported"; \\
exit 1; \\
;; \\
esac;
"""))
self.config = {
"maintainers": [
"Publisher One <one@example.com> (@one)",
"Publisher Two <two@example.com> (@two)",
],
"configurations": {
"linux": [{
"directory": "ubuntu/noble",
"image": "ubuntu:24.04",
"architectures": ["aarch64", "x64"],
"os": "ubuntu",
}],
"alpine-linux": [{
"directory": "alpine/3.23",
"image": "alpine:3.23",
"architectures": ["aarch64", "x64"],
"os": "alpine-linux",
}],
},
}
self.output_file = os.path.join(self.tmpdir, "eclipse-temurin")
self.orig_dir = os.getcwd()
os.chdir(self.tmpdir)
def tearDown(self):
os.chdir(self.orig_dir)
import shutil
shutil.rmtree(self.tmpdir)
@patch("dockerhub_doc_config_update.get_supported_versions", return_value=[25])
@patch("dockerhub_doc_config_update.get_latest_lts", return_value=25)
@patch("dockerhub_doc_config_update.get_git_commit", return_value="abc123")
@patch("dockerhub_doc_config_update.fetch_official_manifest", return_value="")
def test_generates_valid_manifest(self, _fetch, _git, _lts, _versions):
generate_manifest(self.config, self.output_file)
with open(self.output_file) as f:
content = f.read()
# Check header
self.assertIn("# Eclipse Temurin OpenJDK images provided by the Eclipse Foundation.", content)
self.assertIn(
"Maintainers: Publisher One <one@example.com> (@one),\n"
" Publisher Two <two@example.com> (@two)\n"
"GitRepo: ",
content,
)
self.assertIn("GitRepo: https://github.com/adoptium/containers.git", content)
self.assertIn("Builder: buildkit", content)
# Check tags for v25 JDK noble
self.assertIn("Tags: 25.0.2_10-jdk-noble, 25-jdk-noble, 25-noble", content)
self.assertIn("SharedTags: 25.0.2_10-jdk, 25-jdk, 25, latest", content)
# Architectures come from the Dockerfile, not config
self.assertIn("Architectures: amd64, arm64v8", content)
# GitCommit
self.assertIn("GitCommit: abc123", content)
self.assertIn("Directory: 25/jdk/ubuntu/noble", content)
@patch("dockerhub_doc_config_update.get_supported_versions", return_value=[25])
@patch("dockerhub_doc_config_update.get_latest_lts", return_value=25)
@patch("dockerhub_doc_config_update.get_git_commit", return_value="abc123")
@patch("dockerhub_doc_config_update.fetch_official_manifest", return_value="")
def test_maintainer_header_handles_one_or_more_entries(self, _fetch, _git, _lts, _versions):
cases = [
(["First"], "Maintainers: First\nGitRepo: "),
(
["First", "Second", "Third"],
"Maintainers: First,\n Second,\n Third\nGitRepo: ",
),
]
for maintainers, expected in cases:
with self.subTest(maintainers=maintainers), redirect_stderr(io.StringIO()):
self.config["maintainers"] = maintainers
plan = generate_manifest(self.config, self.output_file, dry_run=True)
self.assertIn(expected, plan.manifest)
@patch("dockerhub_doc_config_update.get_supported_versions", return_value=[25])
@patch("dockerhub_doc_config_update.get_latest_lts", return_value=25)
@patch("dockerhub_doc_config_update.get_git_commit", return_value="abc123")
@patch("dockerhub_doc_config_update.fetch_official_manifest", return_value="")
def test_invalid_maintainers_are_rejected(self, _fetch, _git, _lts, _versions):
for maintainers in (None, [], "First", [None], [""], ["First\nSecond"]):
with self.subTest(maintainers=maintainers):
self.config["maintainers"] = maintainers
with redirect_stderr(io.StringIO()), self.assertRaisesRegex(ValueError, "maintainers"):
generate_manifest(self.config, self.output_file, dry_run=True)
del self.config["maintainers"]
with redirect_stderr(io.StringIO()), self.assertRaisesRegex(ValueError, "maintainers"):
generate_manifest(self.config, self.output_file, dry_run=True)
@patch("dockerhub_doc_config_update.get_supported_versions", return_value=[25])
@patch("dockerhub_doc_config_update.get_latest_lts", return_value=25)
@patch("dockerhub_doc_config_update.get_git_commit", return_value="abc123")
@patch("dockerhub_doc_config_update.fetch_official_manifest", return_value="")
def test_no_trailing_blank_lines(self, _fetch, _git, _lts, _versions):
generate_manifest(self.config, self.output_file)
with open(self.output_file) as f:
content = f.read()
# File should end with exactly one newline
self.assertTrue(content.endswith("\n"))
self.assertFalse(content.endswith("\n\n"))
@patch("dockerhub_doc_config_update.get_supported_versions", return_value=[25])
@patch("dockerhub_doc_config_update.get_latest_lts", return_value=25)
@patch("dockerhub_doc_config_update.get_git_commit", return_value="abc123")
@patch("dockerhub_doc_config_update.fetch_official_manifest", return_value="")
def test_skips_missing_dockerfiles(self, _fetch, _git, _lts, _versions):
"""Entries for os families with no Dockerfiles on disk should be skipped."""
generate_manifest(self.config, self.output_file)
with open(self.output_file) as f:
content = f.read()
# alpine-linux config exists but no Dockerfile was created for it
self.assertNotIn("alpine-3.23", content)
@patch("dockerhub_doc_config_update.get_supported_versions", return_value=[8])
@patch("dockerhub_doc_config_update.get_latest_lts", return_value=8)
@patch("dockerhub_doc_config_update.get_git_commit", return_value="abc123")
@patch("dockerhub_doc_config_update.fetch_official_manifest", return_value="")
def test_jdk8_arm32_uses_standard_tags(
self, _fetch, _git, _lts, _versions
):
jdk_dir = os.path.join(self.tmpdir, "8", "jdk", "ubuntu", "noble")
os.makedirs(jdk_dir)
with open(os.path.join(jdk_dir, "Dockerfile"), "w") as f:
f.write(textwrap.dedent("""\
FROM ubuntu:24.04
ENV JAVA_VERSION=jdk8u504-b01
RUN case "${ARCH}" in
amd64)
;;
armhf)
# TODO: This configured architecture is pending upstream binary availability for jdk8u504-b01.
echo "Temurin binary for armhf is not available yet"
exit 1
;;
esac;
"""))
generate_manifest(self.config, self.output_file)
with open(self.output_file) as f:
content = f.read()
blocks = content.split("\n\n")
matching_blocks = [
block
for block in blocks
if "Tags: 8u504-b01-jdk-noble, 8-jdk-noble, 8-noble" in block
]
self.assertEqual(len(matching_blocks), 1)
main_block = matching_blocks[0]
self.assertIn(
"SharedTags: 8u504-b01-jdk, 8-jdk, 8, latest",
main_block,
)
self.assertIn("Architectures: amd64, arm32v7", main_block)
self.assertIn("Directory: 8/jdk/ubuntu/noble", main_block)
self.assertNotIn("Tags: 8u504-b01-jdk-noble-arm32v7", content)
class TestPublishReadiness(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.TemporaryDirectory()
self.addCleanup(self.tmpdir.cleanup)
original_dir = os.getcwd()
os.chdir(self.tmpdir.name)
self.addCleanup(os.chdir, original_dir)
self.read_published_file = self.enterContext(patch(
"dockerhub_doc_config_update.read_git_file", return_value="",
))
self.config = {
"maintainers": ["Publisher One <one@example.com> (@one)"],
"configurations": {
"linux": [{
"directory": "ubuntu/noble",
"architectures": ["x64", "aarch64"],
}],
"alpine-linux": [{
"directory": "alpine/3.24",
"architectures": ["x64", "aarch64"],
}],
},
}
for package in ("jdk", "jre"):
for directory in ("ubuntu/noble", "alpine/3.24"):
self.write_dockerfile(package, directory)
def write_dockerfile(
self, package, directory, release="jdk-25.0.2+10",
arches=("amd64", "arm64"), pending=(), version=25,
):
path = Path(str(version)) / package / directory / "Dockerfile"
path.parent.mkdir(parents=True, exist_ok=True)
lines = [f"ENV JAVA_VERSION={release}", 'RUN case "${ARCH}" in']
for arch in arches:
lines.append(f" {arch})")
if arch in pending:
lines.append(" # TODO: This configured architecture is pending upstream binary availability")
lines.append(" exit 1;")
lines.append(" ;;")
lines.append("esac;")
path.write_text("\n".join(lines))
return path
def generate(self, official_manifest="", versions=None, open_prs=(), dry_run=False):
output = io.StringIO()
stdout = io.StringIO()
with (
patch("dockerhub_doc_config_update.get_supported_versions", return_value=versions or [25]),
patch("dockerhub_doc_config_update.get_latest_lts", return_value=25),
patch("dockerhub_doc_config_update.get_git_commit", return_value="abc123"),
patch("dockerhub_doc_config_update.fetch_official_manifest", return_value=official_manifest),
patch("dockerhub_doc_config_update.fetch_open_publication_prs", return_value=open_prs),
redirect_stderr(output),
redirect_stdout(stdout),
):
self.plan = generate_manifest(self.config, "manifest", dry_run=dry_run)
self.assertEqual(stdout.getvalue(), "")
return output.getvalue(), self.plan.manifest if dry_run else Path("manifest").read_text()
def assert_readiness(self, summary, status, complete):
rows = [
[cell.strip() for cell in line.strip("|").split("|")]
for line in summary.splitlines() if line.startswith("|")
]
self.assertIn(["25", "25.0.2_10", status, complete], [row[:4] for row in rows])
def test_complete_release_is_ready_and_summary_is_not_in_manifest(self):
summary, manifest = self.generate()
self.assert_readiness(summary, "READY", "4/4")
self.assertIn("Ready for upstream publish: Java 25.", summary)
self.assertNotIn("readiness", manifest)
self.assertNotIn("Publication blockers:", summary)
self.assertIn("python3 dockerhub_doc_config_update.py --create-pr", summary)
self.assertIn("python3 dockerhub_doc_config_update.py --dry-run", summary)
self.assertEqual(self.plan.ready_releases, {25: "25.0.2_10"})
def test_pending_architecture_blocks_publish_without_removing_manifest_arch(self):
self.write_dockerfile("jre", "ubuntu/noble", pending=("arm64",))
summary, manifest = self.generate()
self.assert_readiness(summary, "BLOCKED", "3/4")
self.assertIn("pending binaries: arm64v8", summary)
self.assertIn("JRE ubuntu/noble", summary)
self.assertIn("No updated Java versions are ready for upstream publish.", summary)
self.assertIn("Architectures: amd64, arm64v8", manifest)
self.assertIn("Directory: 25/jre/ubuntu/noble", manifest)
def configure_jdk8(self, pending=("armhf",)):
self.config["configurations"]["linux"][0]["architectures"] = ["x64", "arm"]
self.config["configurations"]["alpine-linux"][0]["architectures"] = ["x64"]
for package in ("jdk", "jre"):
self.write_dockerfile(
package, "ubuntu/noble", release="jdk8u512-b09",
arches=("amd64", "armhf"), pending=pending, version=8,
)
self.write_dockerfile(
package, "alpine/3.24", release="jdk8u512-b09",
arches=("amd64",), version=8,
)
def test_jdk8_pending_arm32v7_is_ready_and_retained_for_follow_up(self):
self.configure_jdk8()
summary, manifest = self.generate(versions=[8])
self.assertEqual(self.plan.ready_releases, {8: "8u512-b09"})
self.assertIn("Deferred binaries", summary)
self.assertIn("arm32v7", summary)
self.assertIn("JDK+JRE ubuntu/noble", summary)
self.assertNotIn("Publication blockers:", summary)
self.assertIn("Architectures: amd64, arm32v7", manifest)
self.assertIn("Directory: 8/jdk/ubuntu/noble", manifest)
self.assertIn("Directory: 8/jre/ubuntu/noble", manifest)
self.assertNotIn("noble-arm32v7", manifest)
def test_jdk8_pending_arm32v7_in_only_jre_is_ready(self):
self.configure_jdk8()
self.write_dockerfile(
"jdk", "ubuntu/noble", release="jdk8u512-b09",
arches=("amd64", "armhf"), version=8,
)
summary, _ = self.generate(versions=[8])
self.assertEqual(self.plan.ready_releases, {8: "8u512-b09"})
self.assertIn("JRE ubuntu/noble", summary)
self.assertNotIn("JDK+JRE ubuntu/noble", summary)
def test_jdk8_other_pending_architectures_still_block(self):
self.configure_jdk8()
self.config["configurations"]["linux"][0]["architectures"].append("aarch64")
for package in ("jdk", "jre"):
self.write_dockerfile(
package, "ubuntu/noble", release="jdk8u512-b09",
arches=("amd64", "armhf", "arm64"),
pending=("armhf", "arm64"), version=8,
)
summary, _ = self.generate(versions=[8])
self.assertEqual(self.plan.ready_releases, {})
self.assertIn("pending binaries: arm64v8", summary)
self.assertNotIn("pending binaries: arm32v7", summary)
self.assertIn("Deferred binaries", summary)
def test_jdk8_missing_arm32v7_branch_still_blocks(self):
self.configure_jdk8()
self.write_dockerfile(
"jdk", "ubuntu/noble", release="jdk8u512-b09",
arches=("amd64",), version=8,
)
summary, _ = self.generate(versions=[8])
self.assertEqual(self.plan.ready_releases, {})
self.assertIn("missing architectures: arm32v7", summary)
def test_jdk8_deferral_does_not_allow_missing_or_stale_jre(self):
for stale in (False, True):
with self.subTest(stale=stale):
self.configure_jdk8()
if stale:
self.write_dockerfile(
"jre", "ubuntu/noble", release="jdk8u504-b01",
arches=("amd64", "armhf"), pending=("armhf",), version=8,
)
else:
Path("8/jre/ubuntu/noble/Dockerfile").unlink()
summary, _ = self.generate(versions=[8])
self.assertEqual(self.plan.ready_releases, {})
self.assertIn("stale release" if stale else "missing Dockerfile", summary)
def test_jdk8_deferred_arm32v7_can_be_selected_for_publication_pr(self):
self.configure_jdk8()
_, manifest = self.generate(versions=[8, 25])
upstream = manifest.replace("8u512-b09", "8u504-b01")
self.generate(official_manifest=upstream, versions=[8, 25])
self.assertEqual(self.plan.ready_releases, {8: "8u512-b09"})
output = io.StringIO()
with (
patch(
"dockerhub_doc_config_update.prepare_publication_source",
return_value=("published-main", self.plan.manifest),
),
patch("dockerhub_doc_config_update.run_publication_command") as commands,
redirect_stderr(output),
):
create_publication_pr(self.plan, dry_run=True)
commands.assert_not_called()
self.assertIn("8 to 8u512-b09", output.getvalue())
self.assertNotIn("25 to", output.getvalue())
self.assertNotIn("Java", output.getvalue().split("--- a/library/eclipse-temurin")[0])
self.assertIn("arm32v7 binaries are not released yet", output.getvalue())
self.assertIn("a follow-up PR will publish them", output.getvalue())
merged = merge_publication_manifest(upstream, self.plan.manifest, [8])
self.assertIn("Architectures: amd64, arm32v7", merged)
for directory, entry in get_manifest_entries(upstream).items():
if directory.startswith("25/"):
self.assertEqual(get_manifest_entries(merged)[directory], entry)
def test_jdk8_arm32v7_resolved_after_publication_is_ready(self):
self.configure_jdk8()
published_pending = Path("8/jdk/ubuntu/noble/Dockerfile").read_text()
_, upstream = self.generate(versions=[8])
upstream = upstream.replace("GitCommit: abc123", "GitCommit: first-publication")
self.configure_jdk8(pending=())
with patch(
"dockerhub_doc_config_update.read_git_file",
side_effect=lambda commit, path: published_pending if "ubuntu" in path else "",
) as read_git_file:
summary, _ = self.generate(official_manifest=upstream, versions=[8])
read_git_file.assert_any_call("first-publication", "8/jdk/ubuntu/noble/Dockerfile")
self.assertEqual(self.plan.ready_releases, {8: "8u512-b09"})
self.assertEqual(self.plan.added_architectures, {8: ["arm32v7"]})
self.assertEqual(self.plan.follow_up_directories, {
8: {"8/jdk/ubuntu/noble", "8/jre/ubuntu/noble"},
})
self.assertNotIn("Deferred binaries", summary)
output = self.dry_run_publication_pr()
self.assertIn("'eclipse-temurin: 8 8u512-b09 add arm32v7'", output)
self.assertIn("branch eclipse-temurin-8u512-b09-arm32v7", output)
self.assertIn("now includes arm32v7 binaries", output)
self.assertIn("not available when this release was first published", output)
self.assertNotIn("Publish READY releases", output)
self.assertNotIn("Java", output.split("--- a/library/eclipse-temurin")[0])
def dry_run_publication_pr(self):
output = io.StringIO()
with (
patch(
"dockerhub_doc_config_update.prepare_publication_source",
return_value=("published-main", self.plan.manifest),
),
patch("dockerhub_doc_config_update.run_publication_command") as commands,
redirect_stderr(output),
):
create_publication_pr(self.plan, dry_run=True)
commands.assert_not_called()
return output.getvalue()
def test_jdk8_commit_only_follow_up_pr_is_not_suggested_again(self):
self.configure_jdk8()
published_pending = Path("8/jdk/ubuntu/noble/Dockerfile").read_text()
_, upstream = self.generate(versions=[8])
self.configure_jdk8(pending=())
url = "https://github.com/docker-library/official-images/pull/456"
with patch(
"dockerhub_doc_config_update.read_git_file",
side_effect=lambda commit, path: published_pending if "ubuntu" in path else "",
):
summary, _ = self.generate(
official_manifest=upstream,
versions=[8],
open_prs=[PublicationPR(url, set(), updated_directories={"8/jdk/ubuntu/noble"})],
)
self.assertIn("PR OPEN", summary)
self.assertIn(url, summary)
self.assertEqual(self.plan.ready_releases, {})
def test_jdk8_follow_up_selects_only_the_image_with_a_resolved_binary(self):
self.configure_jdk8()
published_pending = Path("8/jdk/ubuntu/noble/Dockerfile").read_text()
_, upstream = self.generate(versions=[8])
self.configure_jdk8(pending=())
with patch(
"dockerhub_doc_config_update.read_git_file",
side_effect=lambda commit, path: published_pending if path == "8/jdk/ubuntu/noble/Dockerfile" else "",
):
self.generate(official_manifest=upstream, versions=[8])
self.assertEqual(self.plan.follow_up_directories, {8: {"8/jdk/ubuntu/noble"}})
def test_jdk8_removed_architecture_is_not_mistaken_for_a_resolved_binary(self):
self.configure_jdk8()
published_pending = Path("8/jdk/ubuntu/noble/Dockerfile").read_text()
_, upstream = self.generate(versions=[8])
self.config["configurations"]["linux"][0]["architectures"] = ["x64"]
for package in ("jdk", "jre"):
self.write_dockerfile(
package, "ubuntu/noble", release="jdk8u512-b09",
arches=("amd64",), version=8,
)
with patch(
"dockerhub_doc_config_update.read_git_file",
side_effect=lambda commit, path: published_pending if "ubuntu" in path else "",
):
self.generate(official_manifest=upstream, versions=[8])
self.assertEqual(self.plan.ready_releases, {})
self.assertEqual(self.plan.follow_up_directories, {})
def test_missing_published_history_blocks_only_the_unverifiable_version(self):
self.configure_jdk8(pending=())
for package in ("jdk", "jre"):
self.write_dockerfile(package, "ubuntu/noble", arches=("amd64", "armhf"))
_, upstream = self.generate(versions=[8, 25])
upstream = upstream.replace("25.0.2_10", "25.0.1_8")
self.read_published_file.side_effect = (
lambda commit, path: None if path.startswith("8/") else ""
)
summary, _ = self.generate(official_manifest=upstream, versions=[8, 25])
self.assertIn("cannot read published Dockerfile", summary)
self.assertEqual(self.plan.ready_releases, {25: "25.0.2_10"})
def test_jdk8_arm32v7_still_deferred_after_publication_is_up_to_date(self):
self.configure_jdk8()
published_pending = Path("8/jdk/ubuntu/noble/Dockerfile").read_text()
_, upstream = self.generate(versions=[8])
with patch(
"dockerhub_doc_config_update.read_git_file",
side_effect=lambda commit, path: published_pending if "ubuntu" in path else "",
):
summary, _ = self.generate(official_manifest=upstream, versions=[8])
self.assertEqual(self.plan.ready_releases, {})
self.assertIn("UP TO DATE", summary)
def test_pending_arm32v7_still_blocks_other_java_versions(self):
self.config["configurations"]["linux"][0]["architectures"] = ["x64", "arm"]
for version in (11, 17, 25):
with self.subTest(version=version):
for package in ("jdk", "jre"):
self.write_dockerfile(
package, "ubuntu/noble", release=f"jdk-{version}.0.2+10",
arches=("amd64", "armhf"), pending=("armhf",), version=version,
)
self.write_dockerfile(
package, "alpine/3.24", release=f"jdk-{version}.0.2+10",
version=version,
)
summary, _ = self.generate(versions=[version])
self.assertEqual(self.plan.ready_releases, {})
self.assertIn("pending binaries: arm32v7", summary)
self.assertNotIn("Deferred binaries", summary)
def test_missing_architecture_blocks_publish(self):
self.write_dockerfile("jdk", "ubuntu/noble", arches=("amd64",))
summary, _ = self.generate()
self.assertIn("missing architectures: arm64v8", summary)
self.assertIn("JDK ubuntu/noble", summary)
self.assertIn("No updated Java versions are ready for upstream publish.", summary)
def test_missing_jre_blocks_publish(self):
Path("25/jre/ubuntu/noble/Dockerfile").unlink()
summary, _ = self.generate()
self.assertIn("missing Dockerfile", summary)
self.assertIn("JRE ubuntu/noble", summary)
self.assert_readiness(summary, "BLOCKED", "3/4")
def test_missing_java_version_blocks_publish(self):
Path("25/jre/ubuntu/noble/Dockerfile").write_text("FROM ubuntu:24.04\n")
summary, _ = self.generate()
self.assertIn("missing JAVA_VERSION", summary)
self.assertIn("JRE ubuntu/noble", summary)
def test_stale_jre_blocks_publish(self):
self.write_dockerfile("jre", "ubuntu/noble", release="jdk-25.0.2+9")
summary, _ = self.generate()
self.assertIn("stale release jdk-25.0.2+9;", summary)
self.assertIn("jdk-25.0.2+10", summary)
self.assertIn("JRE ubuntu/noble", summary)
self.assert_readiness(summary, "BLOCKED", "3/4")
def test_stale_windows_release_blocks_publish(self):
self.config["configurations"]["windows"] = [{
"directory": "windows/windowsservercore-ltsc2022",
"architectures": ["x64"],
}]
for package in ("jdk", "jre"):
self.write_dockerfile(
package, "windows/windowsservercore-ltsc2022",
release="jdk-25+36", arches=(),
)
summary, _ = self.generate()
self.assert_readiness(summary, "BLOCKED", "4/6")
self.assertIn("stale release jdk-25+36;", summary)
self.assertIn("jdk-25.0.2+10", summary)
self.assertEqual(summary.count("stale release"), 1)
self.assertIn("JDK+JRE windows/windowsservercore-ltsc2022", summary)
def test_current_windows_release_is_ready(self):
self.config["configurations"]["windows"] = [{
"directory": "windows/windowsservercore-ltsc2022",
"architectures": ["x64"],
}]
for package in ("jdk", "jre"):
self.write_dockerfile(package, "windows/windowsservercore-ltsc2022", arches=())
summary, manifest = self.generate()
self.assert_readiness(summary, "READY", "6/6")
self.assertIn("Architectures: windows-amd64", manifest)
def test_global_and_local_architecture_overrides(self):
self.config["architecture_overrides"] = [{"versions": ">=25", "exclude": ["aarch64"]}]
self.config["configurations"]["linux"][0]["architecture_overrides"] = [
{"versions": "==25", "include": ["s390x"]},
]
summary, _ = self.generate()
self.assertIn("missing architectures: s390x", summary)
for package in ("jdk", "jre"):
self.write_dockerfile(package, "ubuntu/noble", arches=("amd64", "s390x"))
self.write_dockerfile(package, "alpine/3.24", arches=("amd64",))
summary, _ = self.generate()
self.assert_readiness(summary, "READY", "4/4")
def test_deprecated_and_version_excluded_configs_are_not_blockers(self):
self.config["configurations"]["alpine-linux"][0]["deprecated"] = 25
self.config["configurations"]["linux"].append({
"directory": "ubuntu/jammy",
"architectures": ["x64"],
"versions": [21],
})
summary, _ = self.generate()
self.assert_readiness(summary, "READY", "2/2")
self.assertNotIn("missing Dockerfile", summary)
def test_removed_distro_still_upstream_is_reported_without_changing_readiness(self):
_, upstream = self.generate()
upstream += "\n" + "\n\n".join(
f"Tags: 25.0.2_10-{package}-alpine-3.21\nDirectory: 25/{package}/alpine/3.21"
for package in ("jdk", "jre")
) + "\n"
summary, manifest = self.generate(official_manifest=upstream)
self.assertIn("Deprecated or removed images still in the upstream official manifest:", summary)
self.assertEqual(summary.count("JDK+JRE alpine/3.21"), 1)
self.assert_readiness(summary, "UP TO DATE", "4/4")
self.assertEqual(self.plan.ready_releases, {})
self.assertNotIn("alpine/3.21", manifest)
self.assertEqual(self.plan.cleanup_directories, {
"25/jdk/alpine/3.21", "25/jre/alpine/3.21",
})
self.assertIn("Upstream cleanup ready: 2 retired image entries", summary)
self.assertIn("--create-pr", summary)
def test_deprecated_and_excluded_upstream_configs_are_reported(self):
_, upstream = self.generate()
for field, value in (("deprecated", 25), ("versions", [21])):
with self.subTest(field=field):
configuration = self.config["configurations"]["alpine-linux"][0]
configuration[field] = value
summary, _ = self.generate(official_manifest=upstream)
self.assertIn("Deprecated or removed images still in the upstream official manifest:", summary)
self.assertIn("JDK+JRE alpine/3.24", summary)
self.assert_readiness(summary, "UP TO DATE", "2/2")
del configuration[field]
def test_distro_below_deprecation_threshold_is_not_reported(self):
self.config["configurations"]["alpine-linux"][0]["deprecated"] = 26
_, upstream = self.generate()
summary, _ = self.generate(official_manifest=upstream)
self.assertNotIn("Deprecated or removed images", summary)
self.assert_readiness(summary, "UP TO DATE", "4/4")
def test_missing_local_dockerfile_is_not_reported_as_deprecated_upstream(self):
_, upstream = self.generate()
Path("25/jre/ubuntu/noble/Dockerfile").unlink()
summary, _ = self.generate(official_manifest=upstream)
self.assertNotIn("Deprecated or removed images", summary)
self.assertIn("missing Dockerfile", summary)
self.assert_readiness(summary, "BLOCKED", "3/4")