Skip to content

Commit 7da13d7

Browse files
authored
Merge pull request #6 from milejko/feature/opcache-revalidate-options
Feature/opcache revalidate options
2 parents 63ef7de + 139860f commit 7da13d7

File tree

9 files changed

+164
-36
lines changed

9 files changed

+164
-36
lines changed

.github/workflows/cd-ne.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: "PHP Docker NE images delivery"
2+
3+
on:
4+
schedule:
5+
# once per week
6+
- cron: "0 4 1,14 * *"
7+
push:
8+
tags:
9+
- "v*.*.*"
10+
11+
jobs:
12+
Deploy:
13+
name: "Image deployment"
14+
strategy:
15+
matrix:
16+
base-image: ['debian', 'alpine']
17+
php-version: ['8.3', '8.0', '8.1', '8.2']
18+
target: ['cli', 'fpm']
19+
exclude:
20+
- base-image: alpine
21+
php-version: '8.3'
22+
- base-image: alpine
23+
php-version: '8.0'
24+
fail-fast: false
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
- name: Build testing Docker Image
30+
uses: docker/build-push-action@v5
31+
with:
32+
push: false
33+
file: ./${{ matrix.base-image }}/Dockerfile
34+
context: ./${{ matrix.base-image }}/
35+
target: ${{ matrix.target }}
36+
tags: testing
37+
build-args: PHP_VERSION=${{ matrix.php-version }}
38+
- name: Dump installed PHP version
39+
run: echo "PHP_REAL_VERSION=$(docker run testing -v | grep -Eo -m 1 '[0-9]+\.[0-9]+\.[0-9]+')" >> $GITHUB_ENV
40+
- name: Check PHP version
41+
run: echo "${{ env.PHP_REAL_VERSION }}" | grep "${{ matrix.php-version }}"
42+
- name: Perform image tests
43+
run: IMAGE_TAG=testing ./.github/workflows/test-image.sh
44+
- name: "Check FPM"
45+
if: ${{ 'fpm' == matrix.target }}
46+
run: |
47+
docker run testing find /usr/bin/php-fpm
48+
docker run testing /usr/bin/php-fpm --daemonize
49+
- name: "Check CLI"
50+
if: ${{ 'cli' == matrix.target }}
51+
run: docker run testing | grep "Interactive"
52+
- name: Set up QEMU (multiplatform)
53+
uses: docker/setup-qemu-action@v3
54+
- name: Set up Docker Buildx (multiplatform)
55+
uses: docker/setup-buildx-action@v3
56+
- name: Login to Docker Hub
57+
uses: docker/login-action@v3
58+
with:
59+
username: ${{ secrets.NE_DOCKERHUB_USERNAME }}
60+
password: ${{ secrets.NE_DOCKERHUB_TOKEN }}
61+
- name: Prepare image metadata
62+
id: meta
63+
uses: docker/metadata-action@v4
64+
with:
65+
images: ${{ secrets.NE_DOCKERHUB_USERNAME }}/php
66+
# sample tag output: 8.2-cli, 8.2.11, latest, cli, 8.2.11-cli, 8.2.11-cli-20230712, 8.2.11
67+
tags: |
68+
type=raw,value=${{ matrix.php-version }}-${{ matrix.target }},enable=${{ 'debian' == matrix.base-image }}
69+
type=raw,value=${{ matrix.php-version }},enable=${{ 'cli' == matrix.target && 'debian' == matrix.base-image }}
70+
type=raw,value=latest,enable=${{ '8.2' == matrix.php-version && 'cli' == matrix.target && 'debian' == matrix.base-image }}
71+
type=raw,value=${{ matrix.target }},enable=${{ '8.2' == matrix.php-version && 'debian' == matrix.base-image }}
72+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.target }},enable=${{ 'debian' == matrix.base-image }}
73+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.target }}-{{ date 'YYYYMMDD' }},enable=${{ 'debian' == matrix.base-image }}
74+
type=raw,value=${{ env.PHP_REAL_VERSION }},enable=${{ 'cli' == matrix.target && 'debian' == matrix.base-image }}
75+
76+
type=raw,value=${{ matrix.php-version }}-${{ matrix.target }}-${{ matrix.base-image }}
77+
type=raw,value=${{ matrix.php-version }}-${{ matrix.base-image }},enable=${{ 'cli' == matrix.target }}
78+
type=raw,value=${{ matrix.target }}-${{ matrix.base-image }},enable=${{ '8.2' == matrix.php-version }}
79+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.target }}-${{ matrix.base-image }}
80+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.target }}-{{date 'YYYYMMDD'}}-${{ matrix.base-image }}
81+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.base-image }},enable=${{ 'cli' == matrix.target }}
82+
- name: Build & push to Docker Hub
83+
uses: docker/build-push-action@v5
84+
with:
85+
push: true
86+
file: ./${{ matrix.base-image }}/Dockerfile
87+
context: ./${{ matrix.base-image }}/
88+
platforms: linux/amd64,linux/arm64
89+
target: ${{ matrix.target }}
90+
tags: ${{ steps.meta.outputs.tags }},
91+
labels: ${{ steps.meta.outputs.labels }},
92+
build-args: PHP_VERSION=${{ matrix.php-version }}

.github/workflows/cd.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ on:
99
- "v*.*.*"
1010

1111
jobs:
12-
Test:
13-
uses: ./.github/workflows/ci.yml
14-
1512
Deploy:
1613
name: "Image deployment"
17-
needs: Test
1814
strategy:
1915
matrix:
2016
base-image: ['debian', 'alpine']
@@ -32,6 +28,29 @@ jobs:
3228
steps:
3329
- name: Checkout code
3430
uses: actions/checkout@v4
31+
- name: Build testing Docker Image
32+
uses: docker/build-push-action@v5
33+
with:
34+
push: false
35+
file: ./${{ matrix.base-image }}/Dockerfile
36+
context: ./${{ matrix.base-image }}/
37+
target: ${{ matrix.target }}
38+
tags: testing
39+
build-args: PHP_VERSION=${{ matrix.php-version }}
40+
- name: Dump installed PHP version
41+
run: echo "PHP_REAL_VERSION=$(docker run testing -v | grep -Eo -m 1 '[0-9]+\.[0-9]+\.[0-9]+')" >> $GITHUB_ENV
42+
- name: Check PHP version
43+
run: echo "${{ env.PHP_REAL_VERSION }}" | grep "${{ matrix.php-version }}"
44+
- name: Perform image tests
45+
run: IMAGE_TAG=testing ./.github/workflows/test-image.sh
46+
- name: "Check FPM"
47+
if: ${{ 'fpm' == matrix.target }}
48+
run: |
49+
docker run testing find /usr/bin/php-fpm
50+
docker run testing /usr/bin/php-fpm --daemonize
51+
- name: "Check CLI"
52+
if: ${{ 'cli' == matrix.target }}
53+
run: docker run testing | grep "Interactive"
3554
- name: Set up QEMU (multiplatform)
3655
uses: docker/setup-qemu-action@v3
3756
- name: Set up Docker Buildx (multiplatform)
@@ -41,10 +60,6 @@ jobs:
4160
with:
4261
username: ${{ secrets.DOCKERHUB_USERNAME }}
4362
password: ${{ secrets.DOCKERHUB_TOKEN }}
44-
- name: Export PHP version to ENV
45-
run: |
46-
docker build -t version --target=${{ matrix.target }} -f ./${{ matrix.base-image }}/Dockerfile --build-arg PHP_VERSION=${{ matrix.php-version }} ./${{ matrix.base-image }}
47-
echo "PHP_PACKAGE_VERSION=$(docker run version -v | grep -Eo -m 1 '[0-9]+\.[0-9]+\.[0-9]+')" >> $GITHUB_ENV
4863
- name: Prepare image metadata
4964
id: meta
5065
uses: docker/metadata-action@v4
@@ -56,16 +71,16 @@ jobs:
5671
type=raw,value=${{ matrix.php-version }},enable=${{ 'cli' == matrix.target && 'debian' == matrix.base-image }}
5772
type=raw,value=latest,enable=${{ '8.2' == matrix.php-version && 'cli' == matrix.target && 'debian' == matrix.base-image }}
5873
type=raw,value=${{ matrix.target }},enable=${{ '8.2' == matrix.php-version && 'debian' == matrix.base-image }}
59-
type=raw,value=${{ env.PHP_PACKAGE_VERSION }}-${{ matrix.target }},enable=${{ 'debian' == matrix.base-image }}
60-
type=raw,value=${{ env.PHP_PACKAGE_VERSION }}-${{ matrix.target }}-{{ date 'YYYYMMDD' }},enable=${{ 'debian' == matrix.base-image }}
61-
type=raw,value=${{ env.PHP_PACKAGE_VERSION }},enable=${{ 'cli' == matrix.target && 'debian' == matrix.base-image }}
74+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.target }},enable=${{ 'debian' == matrix.base-image }}
75+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.target }}-{{ date 'YYYYMMDD' }},enable=${{ 'debian' == matrix.base-image }}
76+
type=raw,value=${{ env.PHP_REAL_VERSION }},enable=${{ 'cli' == matrix.target && 'debian' == matrix.base-image }}
6277
6378
type=raw,value=${{ matrix.php-version }}-${{ matrix.target }}-${{ matrix.base-image }}
6479
type=raw,value=${{ matrix.php-version }}-${{ matrix.base-image }},enable=${{ 'cli' == matrix.target }}
6580
type=raw,value=${{ matrix.target }}-${{ matrix.base-image }},enable=${{ '8.2' == matrix.php-version }}
66-
type=raw,value=${{ env.PHP_PACKAGE_VERSION }}-${{ matrix.target }}-${{ matrix.base-image }}
67-
type=raw,value=${{ env.PHP_PACKAGE_VERSION }}-${{ matrix.target }}-{{date 'YYYYMMDD'}}-${{ matrix.base-image }}
68-
type=raw,value=${{ env.PHP_PACKAGE_VERSION }}-${{ matrix.base-image }},enable=${{ 'cli' == matrix.target }}
81+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.target }}-${{ matrix.base-image }}
82+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.target }}-{{date 'YYYYMMDD'}}-${{ matrix.base-image }}
83+
type=raw,value=${{ env.PHP_REAL_VERSION }}-${{ matrix.base-image }},enable=${{ 'cli' == matrix.target }}
6984
- name: Build & push to Docker Hub
7085
uses: docker/build-push-action@v5
7186
with:

.github/workflows/ci.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ on:
44
schedule:
55
# once per week (external changes can break this images)
66
- cron: "30 3 * * 0"
7+
push:
78
pull_request:
8-
#needed as workflow is reusable
9+
# workflow can be called directly
910
workflow_call:
10-
workflow_dispatch:
1111

1212
jobs:
1313
Test:
@@ -38,13 +38,17 @@ jobs:
3838
target: ${{ matrix.target }}
3939
tags: testing
4040
build-args: PHP_VERSION=${{ matrix.php-version }}
41-
- name: Check image version
42-
run: docker run testing -v | grep "${{ matrix.php-version }}"
43-
- name: "Check FPM binary"
41+
- name: Dump installed PHP version
42+
run: echo "PHP_REAL_VERSION=$(docker run testing -v | grep -Eo -m 1 '[0-9]+\.[0-9]+\.[0-9]+')" >> $GITHUB_ENV
43+
- name: Check PHP version
44+
run: echo "${{ env.PHP_REAL_VERSION }}" | grep "${{ matrix.php-version }}"
45+
- name: Perform image tests
46+
run: IMAGE_TAG=testing ./.github/workflows/test-image.sh
47+
- name: "Check FPM"
4448
if: ${{ 'fpm' == matrix.target }}
45-
run: docker run testing find /usr/bin/php-fpm
46-
- name: "Check CLI shell"
49+
run: |
50+
docker run testing find /usr/bin/php-fpm
51+
docker run testing /usr/bin/php-fpm --daemonize
52+
- name: "Check CLI"
4753
if: ${{ 'cli' == matrix.target }}
4854
run: docker run testing | grep "Interactive"
49-
- name: Perform image tests
50-
run: IMAGE_TAG=testing ./.github/workflows/test-image.sh

.github/workflows/test-image.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
set -eu;
4+
35
PHP_INFO=$(docker run \
46
\
57
-e ALLOW_URL_FOPEN=0 \
@@ -19,8 +21,9 @@ PHP_INFO=$(docker run \
1921
-e OPCACHE_ENABLE_CLI=1 \
2022
-e OPCACHE_MEMORY_CONSUMPTION=200M \
2123
-e OPCACHE_INTERNED_STRINGS_BUFFER=22 \
22-
-e OPCACHE_JIT=1 \
23-
-e OPCACHE_JIT_BUFFER_SIZE=16M \
24+
-e OPCACHE_VALIDATE_TIMESTAMPS=0 \
25+
-e OPCACHE_REVALIDATE_FREQ=15 \
26+
-e OPCACHE_PRELOAD="test.php" \
2427
${IMAGE_TAG} -r 'phpinfo();')
2528

2629
echo "${PHP_INFO}" | grep "allow_url_fopen => Off"
@@ -39,16 +42,15 @@ echo "${PHP_INFO}" | grep "upload_max_filesize => 200M"
3942
echo "${PHP_INFO}" | grep "opcache.enable => Off"
4043
echo "${PHP_INFO}" | grep "opcache.enable_cli => On"
4144
echo "${PHP_INFO}" | grep "opcache.memory_consumption => 200M"
42-
echo "${PHP_INFO}" | grep "opcache.interned_strings_buffer => 22"
43-
echo "${PHP_INFO}" | grep "opcache.jit => 1"
44-
echo "${PHP_INFO}" | grep "opcache.jit_buffer_size => 16M"
45+
echo "${PHP_INFO}" | grep "opcache.validate_timestamps => Off"
46+
echo "${PHP_INFO}" | grep "opcache.revalidate_freq => 15"
47+
echo "${PHP_INFO}" | grep "opcache.max_accelerated_files => 65000"
48+
echo "${PHP_INFO}" | grep "opcache.preload => test.php"
4549

4650
docker run ${IMAGE_TAG} -a | grep "Interactive"
4751

4852
docker run ${IMAGE_TAG} composer -V | grep "Composer version"
49-
docker run ${IMAGE_TAG} pwd | grep "/app"
50-
51-
docker run ${IMAGE_TAG} /usr/bin/php-fpm --daemonize | grep "fpm is running, pid"
53+
docker run ${IMAGE_TAG} pwd | grep "/var/www/html"
5254

5355
INSTALLED_MODULES=$(docker run ${IMAGE_TAG} -m)
5456

README.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,11 @@ <h2>Available environmental values</h2>
184184
OPCACHE_CLI_ENABLE=0
185185
OPCACHE_MEMORY_CONSUMPTION=128M
186186
OPCACHE_INTERNED_STRINGS_BUFFER=16
187+
OPCACHE_VALIDATE_TIMESTAMPS=1
188+
OPCACHE_REVALIDATE_FREQ=2
189+
OPCACHE_PRELOAD=
187190
OPCACHE_JIT=off
188-
OPCACHE_JIT_BUFFER_SIZE=32M
191+
OPCACHE_JIT_BUFFER_SIZE=0
189192
</pre>
190193
<br>
191194
By <a href="https://github.com/milejko">Mariusz Miłejko</a>, enjoy!

alpine/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ ENV WORKDIR=/var/www/html \
2626
OPCACHE_ENABLE_CLI=0 \
2727
OPCACHE_MEMORY_CONSUMPTION=128M \
2828
OPCACHE_INTERNED_STRINGS_BUFFER=16 \
29-
OPCACHE_JIT=off \
30-
OPCACHE_JIT_BUFFER_SIZE=32M
29+
OPCACHE_VALIDATE_TIMESTAMPS=1 \
30+
OPCACHE_REVALIDATE_FREQ=2 \
31+
OPCACHE_PRELOAD= \
32+
OPCACHE_JIT=tracing \
33+
OPCACHE_JIT_BUFFER_SIZE=0
3134

3235
RUN export PHP_PACKAGE_VERSION=${PHP_VERSION/./} && \
3336
apk add --no-cache \

alpine/etc/php/conf.d/00_opcache.ini.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ opcache.enable = ${OPCACHE_ENABLE}
44
opcache.enable_cli = ${OPCACHE_ENABLE_CLI}
55
opcache.memory_consumption = ${OPCACHE_MEMORY_CONSUMPTION}
66
opcache.interned_strings_buffer = ${OPCACHE_INTERNED_STRINGS_BUFFER}
7+
opcache.validate_timestamps = ${OPCACHE_VALIDATE_TIMESTAMPS}
8+
opcache.revalidate_freq = ${OPCACHE_REVALIDATE_FREQ}
9+
opcache.preload = ${OPCACHE_PRELOAD}
710

811
opcache.jit = ${OPCACHE_JIT}
912
opcache.jit_buffer_size = ${OPCACHE_JIT_BUFFER_SIZE}

debian/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ ENV WORKDIR=/var/www/html \
2727
OPCACHE_ENABLE_CLI=0 \
2828
OPCACHE_MEMORY_CONSUMPTION=128M \
2929
OPCACHE_INTERNED_STRINGS_BUFFER=16 \
30-
OPCACHE_JIT=off \
31-
OPCACHE_JIT_BUFFER_SIZE=32M
30+
OPCACHE_VALIDATE_TIMESTAMPS=1 \
31+
OPCACHE_REVALIDATE_FREQ=2 \
32+
OPCACHE_PRELOAD= \
33+
OPCACHE_JIT=tracing \
34+
OPCACHE_JIT_BUFFER_SIZE=0
3235

3336
RUN apt-get update && \
3437
apt-get install -yq --no-install-recommends \

debian/etc/php/mods-available/opcache.ini.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ opcache.enable = ${OPCACHE_ENABLE}
44
opcache.enable_cli = ${OPCACHE_ENABLE_CLI}
55
opcache.memory_consumption = ${OPCACHE_MEMORY_CONSUMPTION}
66
opcache.interned_strings_buffer = ${OPCACHE_INTERNED_STRINGS_BUFFER}
7+
opcache.validate_timestamps = ${OPCACHE_VALIDATE_TIMESTAMPS}
8+
opcache.revalidate_freq = ${OPCACHE_REVALIDATE_FREQ}
9+
opcache.preload = ${OPCACHE_PRELOAD}
710

811
opcache.jit = ${OPCACHE_JIT}
912
opcache.jit_buffer_size = ${OPCACHE_JIT_BUFFER_SIZE}

0 commit comments

Comments
 (0)