forked from shopware/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.php
197 lines (148 loc) · 6.5 KB
/
generate.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
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
<?php
require __DIR__ . '/functions.php';
$supportedVersions = ['8.1', '8.2', '8.3'];
$rcVersions = [];
$index = [];
$tpl = file_get_contents('Dockerfile.template');
$versionRegex ='/^(?<version>\d\.\d\.\d{1,}(RC\d)?)/m';
$supervisord = get_digest_of_image('shyim/supervisord', 'latest');
$workflow = <<<YML
name: Build
on:
workflow_dispatch:
push:
branches:
- main
paths:
- "Dockerfile.template"
- ".github/workflows/build.yml"
- "rootfs/**"
env:
DOCKER_BUILDKIT: 1
COSIGN_EXPERIMENTAL: 1
permissions:
contents: write
id-token: write
packages: write
jobs:
YML;
$stages = [];
$dockerMerges = [];
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;
}
preg_match($versionRegex, $entry['name'], $patchVersion);
}
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');
$folder = $supportedVersion . '/';
if (!file_exists($folder)) {
mkdir($folder, 0777, true);
}
$phpShort = str_replace('.', '', $supportedVersion);
$replaces = [
'${PHP_VERSION_SHORT}' => $phpShort,
'${PHP_VERSION}' => $supportedVersion,
'${PHP_PATCH_VERSION}' => $patchVersion['version'],
'${PHP_DIGEST}' => $phpDigest,
'${SUPERVISORD_DIGEST}' => $supervisord,
];
file_put_contents($folder . 'Dockerfile', str_replace(array_keys($replaces), array_values($replaces), $tpl));
$index[$supportedVersion] = $patchVersion['version'];
$workflowTpl = <<<'TPL'
php${PHP_VERSION_SHORT}-arm64:
name: ${PHP_VERSION} on ARM64
runs-on: hcloud-arm64-small
steps:
- uses: actions/checkout@v3
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Login into Docker Hub
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
- name: Login into Github Docker Registery
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- uses: docker/build-push-action@v4
with:
tags: ghcr.io/shopware/docker-base:${PHP_PATCH_VERSION}-arm64
context: .
file: ${PHP_VERSION}/Dockerfile
cache-from: type=registry,ref=ghcr.io/shopware/docker-cache:${PHP_VERSION}-arm64
cache-to: type=registry,ref=ghcr.io/shopware/docker-cache:${PHP_VERSION}-arm64,mode=max
platforms: linux/arm64
push: true
provenance: false
php${PHP_VERSION_SHORT}-amd64:
name: ${PHP_VERSION} on AMD64
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Login into Github Docker Registery
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- uses: docker/build-push-action@v4
with:
tags: ghcr.io/shopware/docker-base:${PHP_PATCH_VERSION}-amd64
context: .
file: ${PHP_VERSION}/Dockerfile
cache-from: type=registry,ref=ghcr.io/shopware/docker-cache:${PHP_VERSION}-amd64
cache-to: type=registry,ref=ghcr.io/shopware/docker-cache:${PHP_VERSION}-amd64,mode=max
platforms: linux/amd64
push: true
provenance: false
TPL;
$workflow .= str_replace(array_keys($replaces), array_values($replaces), $workflowTpl);
$dockerMerges[] = 'docker manifest create ghcr.io/shopware/docker-base:' . $supportedVersion . ' --amend ghcr.io/shopware/docker-base:' . $patchVersion['version'] . '-amd64 --amend ghcr.io/shopware/docker-base:' . $patchVersion['version'] . '-arm64';
$dockerMerges[] = 'docker manifest create ghcr.io/shopware/docker-base:' . $patchVersion['version'] . ' --amend ghcr.io/shopware/docker-base:' . $patchVersion['version'] . '-amd64 --amend ghcr.io/shopware/docker-base:' . $patchVersion['version'] . '-arm64';
$dockerMerges[] = 'docker manifest push ghcr.io/shopware/docker-base:' . $supportedVersion;
$dockerMerges[] = 'docker manifest push ghcr.io/shopware/docker-base:' . $patchVersion['version'];
$dockerMerges[] = 'cosign sign --yes ghcr.io/shopware/docker-base:' . $supportedVersion;
$dockerMerges[] = 'cosign sign --yes ghcr.io/shopware/docker-base:' . $patchVersion['version'];
$dockerMerges[] = './regctl-linux-amd64 image copy ghcr.io/shopware/docker-base:' . $supportedVersion . ' shopware/docker-base:' . $supportedVersion;
$dockerMerges[] = './regctl-linux-amd64 image copy ghcr.io/shopware/docker-base:' . $patchVersion['version'] . ' shopware/docker-base:' . $patchVersion['version'];
$stages[] = 'php' . $phpShort . '-arm64';
$stages[] = 'php' . $phpShort . '-amd64';
}
$workflow .= '
merge-manifest:
name: Merge Manifest
runs-on: ubuntu-latest
needs:
';
foreach ($stages as $stage) {
$workflow .= ' - ' . $stage . "\n";
}
$workflow .= '
steps:
- name: Login into Docker Hub
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
- name: Login into Github Docker Registery
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Install Regclient
run: |
wget https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64
chmod +x regctl-linux-amd64
';
foreach ($dockerMerges as $merge) {
$workflow .= " - run: " . $merge . "\n\n";
}
file_put_contents('.github/workflows/build.yml', $workflow);