Skip to content

Commit 65a41c6

Browse files
author
wslaghekke
committed
Build patch-version specific tags and use those in cache-from so rebuilds with the same patch-version use cache and can be skipped
Move nodejs install to end so multiple nodejs versions of the image can reuse all the php layers (and save time building the php extensions)
1 parent 9069fdc commit 65a41c6

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

.github/workflows/build.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
strategy:
1515
matrix:
1616
php:
17-
- '^(7\.4)-apache$'
18-
- '^(8\.0)-apache$'
19-
- '^(8\.1)-apache$'
20-
- '^(7\.4)-fpm$'
21-
- '^(8\.0)-fpm$'
22-
- '^(8\.1)-fpm$'
17+
- '^(7\.4)(\.\d+)?-apache$'
18+
- '^(8\.0)(\.\d+)?-apache$'
19+
- '^(8\.1)(\.\d+)?-apache$'
20+
- '^(7\.4)(\.\d+)?-fpm$'
21+
- '^(8\.0)(\.\d+)?-fpm$'
22+
- '^(8\.1)(\.\d+)?-fpm$'
2323
steps:
2424
- name: Setup multi-architecture support
2525
run: 'docker run --rm --privileged multiarch/qemu-user-static --reset -p yes'

apache/Dockerfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ RUN pecl install apcu \
2323
&& pecl clear-cache \
2424
&& echo "extension=apcu.so" > /usr/local/etc/php/conf.d/apcu.ini
2525

26-
2726
# Upload settings
2827
RUN echo "file_uploads = On\n" \
2928
"memory_limit = 256M\n" \
@@ -45,14 +44,6 @@ RUN curl -sS https://getcomposer.org/installer | php \
4544
&& mv composer.phar /usr/local/bin/composer \
4645
&& mkdir /var/www/html/public
4746

48-
ARG NODE_VERSION
49-
ARG TARGETARCH
50-
RUN (curl -SL --fail -o node.tar.xz "https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-linux-$TARGETARCH.tar.xz" || curl -SL --fail -o node.tar.xz "https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-linux-x64.tar.xz") \
51-
&& tar -xJf "node.tar.xz" -C /usr/local --strip-components=1 \
52-
&& rm "node.tar.xz" \
53-
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs \
54-
&& npm install --global yarn
55-
5647
ARG ENABLE_IMAGE_SUPPORT=false
5748
RUN $ENABLE_IMAGE_SUPPORT \
5849
&& apt-get update \
@@ -75,3 +66,11 @@ RUN $ENABLE_DEBUG \
7566
&& sed -i.bak "s/display_errors = 0/display_errors = 1/g" /usr/local/etc/php/conf.d/general.ini \
7667
&& sed -i.bak "s/display_startup_errors = 0/display_startup_errors = 1/g" /usr/local/etc/php/conf.d/general.ini \
7768
|| true
69+
70+
ARG NODE_VERSION
71+
ARG TARGETARCH
72+
RUN (curl -SL --fail -o node.tar.xz "https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-linux-$TARGETARCH.tar.xz" || curl -SL --fail -o node.tar.xz "https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-linux-x64.tar.xz") \
73+
&& tar -xJf "node.tar.xz" -C /usr/local --strip-components=1 \
74+
&& rm "node.tar.xz" \
75+
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs \
76+
&& npm install --global yarn

src/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ import {createClientV2} from 'docker-registry-client';
1717
return {
1818
tag: it,
1919
version: match && match[1],
20+
exactVersion: match && (match[1] + (match[2] || '')),
2021
webServer: it.includes('-fpm') ? WebServerType.NGINX : WebServerType.APACHE,
2122
} as PhpVersion;
2223
}).filter(it => it.version);
24+
const highestPhpVersion = phpVersions.reduce((a, b) => {
25+
return compareVersions(a.exactVersion, b.exactVersion) === -1 ? b : a;
26+
});
2327

2428
const nodeVersions = await getNodeLtsVersions();
2529

2630
const docker = new Docker();
2731

28-
for (let phpVersion of phpVersions) {
29-
const imageTags = await buildImages(docker, phpVersion, nodeVersions)
30-
await createOrUpdateRelease(phpVersion, imageTags)
31-
}
32+
const imageTags = await buildImages(docker, highestPhpVersion, nodeVersions)
33+
await createOrUpdateRelease(highestPhpVersion, imageTags)
3234
} catch (e) {
3335
console.error('Build failed: ', e);
3436
process.exit(typeof e == 'number' ? e : 1);
@@ -95,17 +97,21 @@ async function buildImages(docker: Docker, phpVersion: PhpVersion, nodeVersions:
9597

9698
async function buildAndPushImage(docker: Docker, phpVersion: PhpVersion, nodeVersion: NodeVersion, imageSupport: boolean, debug: boolean) {
9799
const imageName = 'recognizebv/symfony-docker';
98-
const tagName = `php${phpVersion.version}${phpVersion.webServer === WebServerType.NGINX ? '-nginx' : ''}-node${nodeVersion.major}` + (imageSupport ? '-image' : '') + (debug ? '-dev' : '');
100+
const tagSuffix = `${phpVersion.webServer === WebServerType.NGINX ? '-nginx' : ''}-node${nodeVersion.major}` + (imageSupport ? '-image' : '') + (debug ? '-dev' : '');
101+
const exactTagName = `php${phpVersion.exactVersion}${tagSuffix}`
102+
const tagName = `php${phpVersion.version}${tagSuffix}`
99103
const tag = imageName + ':' + tagName;
100104
const architecture = process.argv[3] ?? 'linux/amd64';
101105

102-
console.log('Building image ' + tag);
106+
console.log(`Building image ${tag} with base image version ${phpVersion.exactVersion}`);
103107
const childProcess = spawn('docker', [
104108
'buildx',
105109
'build',
106110
'--platform', architecture,
107111
'--push',
108112
'-f', phpVersion.webServer === WebServerType.NGINX ? 'nginx/Dockerfile' : 'apache/Dockerfile',
113+
'--cache-from', `${imageName}:${tagName}`,
114+
'--tag', `${imageName}:${exactTagName}`,
109115
'--tag', `${imageName}:${tagName}`,
110116
'--build-arg', `BASE_IMAGE=php:${phpVersion.tag}`,
111117
'--build-arg', `NODE_VERSION=${nodeVersion.version}`,

src/model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface NodeVersion {
1111

1212
export interface PhpVersion {
1313
version: string;
14+
exactVersion: string;
1415
tag: string;
1516
webServer: string;
1617
}

0 commit comments

Comments
 (0)