Skip to content

Commit af6b95f

Browse files
authored
Merge pull request #15 from kool-dev/patch-webp
Auto Serving webp if available/exists
2 parents 2a428ed + 9ba2567 commit af6b95f

35 files changed

+273
-316
lines changed

.github/workflows/ci-cd.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
version: [ '8.0', '8.1', '8.2', '8.3' ]
15+
version: [ '8.1', '8.2', '8.3', '8.4' ]
1616
type: [ '', '-prod' ]
1717

1818
steps:
@@ -37,6 +37,7 @@ jobs:
3737
docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} php -v
3838
docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} wp --allow-root --version
3939
docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} nginx -v
40+
docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} nginx -t
4041
docker run kooldev/wordpress:${{ matrix.version }}-nginx${{ matrix.type }} supervisord version
4142
4243
- name: Test docker images wordpress code

7.4-nginx/Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

7.4-nginx/entrypoint

Lines changed: 0 additions & 92 deletions
This file was deleted.

8.0-nginx/Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

8.0-nginx/entrypoint

Lines changed: 0 additions & 92 deletions
This file was deleted.

8.1-nginx-prod/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FROM wordpress:cli-php8.1 as wordpress-cli
2-
FROM wordpress:php8.1-fpm-alpine as wordpress
1+
FROM wordpress:cli-php8.1 AS wordpress-cli
2+
FROM wordpress:php8.1-fpm-alpine AS wordpress
33
FROM kooldev/php:8.1-nginx-prod
44

55
ENV NGINX_ROOT=/app
@@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp
88
COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress
99
COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content
1010
COPY entrypoint /kool/wordpress-entrypoint
11+
COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf
1112

1213
RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint
1314

8.1-nginx-prod/entrypoint

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22
set -eo pipefail
33

4-
# Nginx server config
5-
dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf
4+
# Add WebP support for WordPress by injecting include directive
5+
# Insert the include directive before the location / block
6+
sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl
67

78
# Run as current user
89
CURRENT_USER=${ASUSER:-${UID:-0}}

8.1-nginx-prod/wordpress-webp.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# WordPress WebP support: automatically serve WebP images when available and supported
2+
location ~* ^(.+)\.(jpe?g|png)$ {
3+
set $webp_suffix "";
4+
5+
# Check if WebP is supported by the client
6+
if ($http_accept ~* "image/webp") {
7+
set $webp_suffix ".webp";
8+
}
9+
10+
# Try to serve the WebP version first, then fallback to original
11+
try_files $uri$webp_suffix $uri /index.php?$query_string;
12+
13+
# Set appropriate cache headers for images
14+
expires 30d;
15+
add_header Cache-Control "public, immutable";
16+
add_header Vary "Accept";
17+
}

8.1-nginx/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FROM wordpress:cli-php8.1 as wordpress-cli
2-
FROM wordpress:php8.1-fpm-alpine as wordpress
1+
FROM wordpress:cli-php8.1 AS wordpress-cli
2+
FROM wordpress:php8.1-fpm-alpine AS wordpress
33
FROM kooldev/php:8.1-nginx
44

55
ENV NGINX_ROOT=/app
@@ -8,6 +8,7 @@ COPY --from=wordpress-cli /usr/local/bin/wp /usr/local/bin/wp
88
COPY --from=wordpress --chown=kool:kool /usr/src/wordpress /kool/wordpress
99
COPY --from=wordpress --chown=kool:kool /var/www/html/wp-content /app/wp-content
1010
COPY entrypoint /kool/wordpress-entrypoint
11+
COPY wordpress-webp.conf /etc/nginx/wordpress-webp.conf
1112

1213
RUN chmod -R 777 wp-content && chmod +x /kool/wordpress-entrypoint
1314

8.1-nginx/entrypoint

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/bash
22
set -eo pipefail
33

4-
# Nginx server config
5-
dockerize -template /kool/default.tmpl:/etc/nginx/conf.d/default.conf
4+
# Add WebP support for WordPress by injecting include directive
5+
# Insert the include directive before the location / block
6+
sed -i 's/\( location \/ {\)/ # Include WordPress WebP support\n include \/etc\/nginx\/wordpress-webp.conf;\n\n\1/' /kool/default.tmpl
67

78
# Run as current user
89
CURRENT_USER=${ASUSER:-${UID:-0}}

0 commit comments

Comments
 (0)