-
Notifications
You must be signed in to change notification settings - Fork 6
356 lines (350 loc) · 12.7 KB
/
ci.yml
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
name: CI
on:
push:
branches:
- 'release/**'
pull_request:
env:
GITHUB_REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
RELEASE_REF_FILTER: 'refs/heads/release/'
EXCLUDED_PLATFORM: "linux/amd64" # change to linux/amd64
# and thos blocks from:
# exclude:
# - platform: none
# to:
# exclude:
# - platform: linux/amd64
jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: hadolint/[email protected]
with:
dockerfile: "Dockerfile"
format: "tty"
no-color: "true"
output-file: "/dev/stdout"
build-base:
runs-on: ARM64
needs:
- lint
strategy:
fail-fast: false
matrix:
platform:
- linux/arm64
- linux/amd64
exclude:
- platform: linux/amd64
steps:
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
tags: temporary-build-image-${{ env.PLATFORM_PAIR }}
target: php-zts-base
cache-to: type=gha,mode=max,scope=${{ env.PLATFORM_PAIR }}-base
outputs: type=docker,dest=/tmp/${{ env.PLATFORM_PAIR }}-base.tar
- name: Load image
run: |
docker load --input /tmp/${{ env.PLATFORM_PAIR }}-base.tar
docker image ls -a
- name: Test
run: |
docker run --platform ${{ matrix.platform }} --rm temporary-build-image-${{ env.PLATFORM_PAIR }} sh -c 'uname -a && php -v'
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PLATFORM_PAIR }}-base.tar
path: /tmp/${{ env.PLATFORM_PAIR }}-base.tar
build-pecl-modules:
runs-on: ARM64
needs: build-base
strategy:
fail-fast: false
matrix:
platform:
- linux/arm64
- linux/amd64
exclude:
- platform: linux/amd64
module:
- pecl-builder-amqp
- pecl-builder-apcu
- pecl-builder-igbinary
- pecl-builder-imagick
- pecl-builder-msgpack
- pecl-builder-memcached
- pecl-builder-protobuf
- pecl-builder-redis
- pecl-builder-xdebug
- pecl-builder-grpc
- pecl-builder-pcov
- FRANKENPHPBUILDER
steps:
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
tags: temporary-build-image-${{ env.PLATFORM_PAIR }}
target: ${{ matrix.module }}
cache-from: type=gha,scope=${{ env.PLATFORM_PAIR }}-base
cache-to: type=gha,mode=max,scope=${{ env.PLATFORM_PAIR }}-${{ matrix.module }}
outputs: type=docker,dest=/tmp/${{ env.PLATFORM_PAIR }}-${{ matrix.module }}.tar
- name: Load image
run: |
docker load --input /tmp/${{ env.PLATFORM_PAIR }}-${{ matrix.module }}.tar
docker image ls -a
- name: Test
run: |
docker run --platform ${{ matrix.platform }} --rm temporary-build-image-${{ env.PLATFORM_PAIR }} sh -c 'uname -a && php -v'
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PLATFORM_PAIR }}-${{ matrix.module }}.tar
path: /tmp/${{ env.PLATFORM_PAIR }}-${{ matrix.module }}.tar
build-all:
runs-on: ubuntu-latest
needs: build-pecl-modules
strategy:
fail-fast: false
matrix:
platform:
- linux/arm64
- linux/amd64
exclude:
- platform: linux/amd64
steps:
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- if: contains(github.ref, env.RELEASE_REF_FILTER)
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- if: contains(github.ref, env.RELEASE_REF_FILTER)
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
tags: temporary-build-image-${{ env.PLATFORM_PAIR }}
cache-from: |
type=gha,scope=${{ env.PLATFORM_PAIR }}-base
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-amqp
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-apcu
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-igbinary
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-imagick
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-msgpack
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-memcached
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-protobuf
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-redis
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-xdebug
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-grpc
type=gha,scope=${{ env.PLATFORM_PAIR }}-pecl-builder-pcov
type=gha,scope=${{ env.PLATFORM_PAIR }}-FRANKENPHPBUILDER
cache-to: type=gha,mode=max,scope=${{ env.PLATFORM_PAIR }}
outputs: type=docker,dest=/tmp/${{ env.PLATFORM_PAIR }}.tar
- name: Load image
run: |
docker load --input /tmp/${{ env.PLATFORM_PAIR }}.tar
docker image ls -a
- name: Test
run: |
docker run --platform ${{ matrix.platform }} --rm temporary-build-image-${{ env.PLATFORM_PAIR }} sh -c 'uname -a && php -v'
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PLATFORM_PAIR }}.tar
path: /tmp/${{ env.PLATFORM_PAIR }}.tar
test:
runs-on: ubuntu-latest
needs: build-all
strategy:
fail-fast: false
matrix:
platform:
- linux/arm64
- linux/amd64
exclude:
- platform: linux/amd64
steps:
-
name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Download ${{ matrix.platform }} artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.PLATFORM_PAIR }}.tar
path: /tmp
- name: Load image
run: |
docker load --input /tmp/${{ env.PLATFORM_PAIR }}.tar
docker image ls -a
- name: Test
run: |
docker run --platform ${{ matrix.platform }} --rm temporary-build-image-${{ env.PLATFORM_PAIR }} sh -c 'uname -a && php -v'
use:
runs-on: ubuntu-latest
needs: build-all
strategy:
fail-fast: false
matrix:
suffix:
- unsuffixed
- fpm
- apache2
- unit
- frankenphp
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download amd64 artifact
uses: actions/download-artifact@v4
with:
name: linux-amd64.tar
path: /tmp
- name: Download arm64 artifact
if: env.EXCLUDED_PLATFORM != 'linux/arm64'
uses: actions/download-artifact@v4
with:
name: linux-arm64.tar
path: /tmp
- name: Load arm64 image
if: env.EXCLUDED_PLATFORM != 'linux/arm64'
run: |
docker load --input /tmp/linux-arm64.tar
docker image ls -a
- name: Load amd64 image
run: |
docker load --input /tmp/linux-amd64.tar
docker image ls -a
- name: Test amd64
run: |
docker run --platform linux/amd64 --rm temporary-build-image-linux-amd64 sh -c 'uname -a && php -v'
- name: Test arm64
if: env.EXCLUDED_PLATFORM != 'linux/arm64'
run: |
docker run --platform linux/arm64 --rm temporary-build-image-linux-arm64 sh -c 'uname -a && php -v'
- name: "PHP_VERSION Env"
run: echo "PHP_VERSION=`docker run --pull=never --rm -t temporary-build-image-linux-amd64 php --version | head -n 1 | cut -f 2 -d ' '``docker run --pull=never --rm -t temporary-build-image-linux-amd64 php --version | grep 'ZTS' >/dev/null && echo '-zts' || echo ''`" >> $GITHUB_ENV
- name: Log into registry ${{ env.GITHUB_REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Dockerfile metadata
id: metaUnsuffixed
uses: docker/[email protected]
with:
tags: |
type=raw,value=${{ env.PHP_VERSION }}
images: ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Set platforms
id: set-platforms
run: |
if [ "${{ env.EXCLUDED_PLATFORM }}" = "linux/arm64" ]; then
echo "PLATFORMS=linux/amd64" >> $GITHUB_ENV
else
echo "PLATFORMS=linux/amd64,linux/arm64" >> $GITHUB_ENV
fi
- if: contains(matrix.suffix, 'unsuffixed')
name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
platforms: ${{ env.PLATFORMS }}
provenance: false
cache-from: |
type=gha,scope=unsuffixed
type=gha,scope=linux-amd64
type=gha,scope=linux-arm64
cache-to: type=gha,mode=max,scope=unsuffixed
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.metaUnsuffixed.outputs.tags }}
labels: ${{ steps.metaUnsuffixed.outputs.labels }}
- if: ${{ !contains(matrix.suffix, 'unsuffixed') }}
name: Create Dockerfile-${{ matrix.suffix }}
run: |
cp Dockerfile Dockerfile-${{ matrix.suffix }}
cat files/${{ matrix.suffix }}/${{ matrix.suffix }}.Dockerfile.snippet.txt >> Dockerfile-${{ matrix.suffix }}
- if: ${{ !contains(matrix.suffix, 'unsuffixed') }}
name: Extract Dockerfile-${{ matrix.suffix }} metadata
id: meta
uses: docker/[email protected]
with:
tags: |
type=raw,value=${{ env.PHP_VERSION }}-${{ matrix.suffix }}
images: ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}
- if: ${{ !contains(matrix.suffix, 'unsuffixed') }}
name: Build and push Dockerfile-${{ matrix.suffix }}
uses: docker/[email protected]
with:
context: .
file: Dockerfile-${{ matrix.suffix }}
platforms: ${{ env.PLATFORMS }}
provenance: false
cache-from: |
type=gha,scope=unsuffixed
type=gha,scope=linux-amd64
type=gha,scope=linux-arm64
cache-to: type=gha,mode=max,scope=${{ matrix.suffix }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}