-
Notifications
You must be signed in to change notification settings - Fork 8
/
matrix.php
98 lines (76 loc) · 3.88 KB
/
matrix.php
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
<?php
$_SERVER['GITHUB_REF'] ??= 'refs/heads/main';
$_SERVER['GITHUB_RUN_ID'] ??= '1';
function get_digest_of_image(string $imageName, string $tag): string {
$response = json_decode(file_get_contents('https://hub.docker.com/v2/repositories/' . $imageName . '/tags/?page_size=50&page=1&name=' . urlencode($tag)), true);
$digest = null;
foreach ($response['results'] as $image) {
if ($image['name'] === $tag) {
$digest = $image['digest'];
break;
}
}
if (empty($digest)) {
throw new \Exception('Cannot find digest of ' . $imageName . ':' . $tag);
}
return $digest;
}
$supportedVersions = ['8.1', '8.2', '8.3'];
$rcVersions = [];
$data = [];
$versionRegex ='/^(?<version>\d\.\d\.\d{1,}(RC\d)?)/m';
$supervisord = get_digest_of_image('shyim/supervisord', 'latest');
foreach ($supportedVersions as $supportedVersion)
{
$apiResponse = json_decode(file_get_contents('https://hub.docker.com/v2/repositories/library/php/tags/?page_size=50&page=1&name=' . $supportedVersion. '.'), true);
if (!is_array($apiResponse)) {
throw new \RuntimeException("invalid api response");
}
$curVersion = null;
$patchVersion = null;
$rcVersion = null;
foreach ($apiResponse['results'] as $entry) {
preg_match($versionRegex, $entry['name'], $rcVersion);
if (strpos($entry['name'], 'RC') !== false && !in_array($rcVersion['version'], $rcVersions)) {
continue;
}
if (preg_match($versionRegex, $entry['name'], $patchVersion)) {
break;
}
}
if ($patchVersion === null) {
throw new \RuntimeException('There is no version found for PHP ' . $supportedVersion);
}
$phpDigest = get_digest_of_image('library/php', $patchVersion['version'] . '-fpm-alpine');
$imageTagPrefix = $_SERVER['GITHUB_REF'] !== 'refs/heads/main' ? ($_SERVER['GITHUB_RUN_ID'] . '-') : '';
$imageSuffix = $_SERVER['GITHUB_REF'] !== 'refs/heads/main' ? '-ci-test' : '';
$caddyImages = [
'ghcr.io/shopware/docker-base' . $imageSuffix . ':' . $imageTagPrefix . $supportedVersion,
'ghcr.io/shopware/docker-base' . $imageSuffix . ':' . $imageTagPrefix . $supportedVersion . '-caddy',
'ghcr.io/shopware/docker-base' . $imageSuffix . ':' . $imageTagPrefix . $patchVersion['version'],
'ghcr.io/shopware/docker-base' . $imageSuffix . ':' . $imageTagPrefix . $patchVersion['version'] . '-caddy',
];
if ($_SERVER['GITHUB_REF'] === 'refs/heads/main') {
$caddyImages = array_merge($caddyImages, [
'shopware/docker-base:' . $imageTagPrefix . $supportedVersion,
'shopware/docker-base:' . $imageTagPrefix . $supportedVersion . '-caddy',
'shopware/docker-base:' . $imageTagPrefix . $patchVersion['version'],
'shopware/docker-base:' . $imageTagPrefix . $patchVersion['version'] . '-caddy',
]);
}
$data[] = [
'php' => $supportedVersion,
'phpPatch' => $patchVersion['version'],
'phpPatchDigest' => $phpDigest,
'supervisordDigest' => $supervisord,
'base-image' => 'ghcr.io/shopware/docker-base' . $imageSuffix . ':' . $imageTagPrefix . $supportedVersion,
'fpm-image' => 'ghcr.io/shopware/docker-base' . $imageSuffix . ':' . $imageTagPrefix . $supportedVersion . '-fpm',
'fpm-patch-image' => 'ghcr.io/shopware/docker-base' . $imageSuffix . ':' . $imageTagPrefix . $patchVersion['version'] . '-fpm',
'fpm-hub-image' => 'shopware/docker-base:' . $imageTagPrefix . $supportedVersion . '-fpm',
'fpm-patch-hub-image' => 'shopware/docker-base:' . $imageTagPrefix . $patchVersion['version'] . '-fpm',
'caddy-tags' => implode("\n", $caddyImages),
'scan-tag' => $caddyImages[0],
'scan-to' => 'ghcr.io/shopware/docker-base:'.$supportedVersion,
];
}
echo json_encode(['matrix' => ['include' => $data]], JSON_THROW_ON_ERROR);